{"id":592,"date":"2023-03-23T21:28:47","date_gmt":"2023-03-23T13:28:47","guid":{"rendered":""},"modified":"2023-03-23T21:28:47","modified_gmt":"2023-03-23T13:28:47","slug":"SpringBoot Thymeleaf","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/592.html","title":{"rendered":"SpringBoot Thymeleaf"},"content":{"rendered":"
\n
XML <\/span> XHTML 1.0\u8fc7\u6e21\u7248<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n \u5b83\u65e2\u53ef\u4ee5\u5728\u7f51\u7edc\u73af\u5883\u4e2d\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u5728\u975e\u7f51\u7edc\u73af\u5883\u4e2d\u4f7f\u7528\u3002<\/span> <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/code>\n <\/div>\n <\/p>\n <\/body>
\n \u6709\u6548\u7684XML <\/span>
\n XHTML <\/span>
\n \u6709\u6548\u7684XHTML <\/span>
\n HTML5 <\/span>
\n \u65e7\u7248HTML5 <\/span> <\/p>\n
\n \u5b9a\u4e49\u660e\u786e\u7684XML <\/strong>\u6587\u4ef6\u3002\u5b83\u4f7f\u6211\u4eec\u80fd\u591f\u5904\u7406\u5177\u6709\u72ec\u7acb\u6807\u7b7e\uff0c\u6ca1\u6709\u503c\u7684\u6807\u7b7e\u5c5e\u6027\u6216\u672a\u5728\u5f15\u53f7\u4e4b\u95f4\u5199\u5165\u7b49\u529f\u80fd\u7684HTML5\u6587\u4ef6\u3002\n <\/div>\n
\n \u683c\u5f0f\u826f\u597d\u7684XML <\/strong>\u6587\u4ef6(\u6709\u6548\u7684HTML5\u6587\u4ef6)\u3002\n <\/div>\n\u6807\u51c6\u65b9\u8a00<\/h2>\n
\n \u5904\u7406\u5668<\/strong>\u3002\u4e00\u7ec4\u5904\u7406\u5668\u4ee5\u53ca\u4e00\u4e9b\u989d\u5916\u7684\u5de5\u4ef6\u79f0\u4e3a
\n \u65b9\u8a00<\/strong>\u3002\u5305\u542bThymeleaf\u6838\u5fc3\u5e93\u7684\u65b9\u8a00\u79f0\u4e3a
\n \u6807\u51c6\u65b9\u8a00\u3002<\/strong>\n <\/div>\n
\n SpringStandard Dialect <\/strong>\u7684\u65b9\u8a00\u3002\u6807\u51c6\u65b9\u8a00\u548cSpringStandard\u51e0\u4e4e\u76f8\u540c\u3002\u4f46\u662f\u6807\u51c6\u65b9\u8a00\u6709\u4e00\u4e9b\u5c0f\u7684\u53d8\u5316\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5229\u7528Spring\u6846\u67b6\u4e2d\u7684\u67d0\u4e9b\u529f\u80fd\u3002\n <\/div>\n
\n \u4e25\u683c\u7684XHTML 1.0 <\/span>
\n XHTML 1.0\u6846\u67b6\u96c6<\/span>
\n XHTML 1.1\u3002<\/span> <\/p>\n\r\n<form:inputText name=\"student.Name\"<\/span> value=\"${student.name}\"<\/span> \/>\r\n<\/pre>\n
\r\n<input type=\"text\"<\/span> name=\" student Name\"<\/span> value=\"Thomas\"<\/span> th:value=\"${student.name}\"<\/span> \/>\r\n<\/pre>\n
\n value <\/strong>\u5c5e\u6027(
\n Thomas <\/strong>)\u3002\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00\u539f\u578b\u65f6\uff0c\u5c06\u663e\u793a\u8be5\u503c\u3002\u5728\u6a21\u677f\u7684Thymeleaf\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u8be5\u5c5e\u6027\u5c06\u7531\u5bf9
\n $ {student.name} <\/strong>\u7684\u6c42\u503c\u5f97\u51fa\u7684\u503c\u4ee3\u66ff\u3002\n <\/div>\n
\n \u81ea\u7136\u6a21\u677f<\/strong>\u3002 <\/p>\nThymeleaf\u7279\u5f81<\/h2>\n
\n \u7528\u4e8eHTML5\/XML\/XHTML\u7684Java\u6a21\u677f\u5f15\u64ce\u3002<\/span>
\n \u5176\u9ad8\u6027\u80fd\u7684\u89e3\u6790\u6a21\u677f\u7f13\u5b58\u5c06I\/O\u964d\u81f3\u6700\u4f4e\u3002<\/span>
\n \u5982\u679c\u9700\u8981\uff0c\u5b83\u53ef\u4ee5\u7528\u4f5c\u6a21\u677f\u5f15\u64ce\u6846\u67b6\u3002<\/span>
\n \u5b83\u652f\u6301\u51e0\u79cd\u6a21\u677f\u6a21\u5f0f: XML\uff0cXHTML\u548cHTML5\u3002<\/span>
\n \u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u6269\u5c55\u548c\u521b\u5efa\u81ea\u5b9a\u4e49\u65b9\u8a00\u3002<\/span>
\n \u5b83\u57fa\u4e8e\u79f0\u4e3a\u65b9\u8a00\u7684\u6a21\u5757\u5316\u529f\u80fd\u96c6\u3002<\/span>
\n \u5b83\u652f\u6301\u56fd\u9645\u5316\u3002<\/span> <\/p>\n Thymeleaf\u5b9e\u73b0<\/h2>\n
\n spring-boot-starter-thymeleaf <\/strong>\u4f9d\u8d56\u9879\u6765\u5b9e\u73b0Thymeleaf\u6a21\u677f\u5f15\u64ce\u6587\u4ef6\u3002 Spring Boot\u5c06\u6a21\u677f\u5f15\u64ce\u914d\u7f6e\u4e3a\u4ece
\n \/resource\/templates\u4e2d\u8bfb\u53d6\u6a21\u677f\u6587\u4ef6\u3002<\/strong>\n <\/div>\n\r\n<dependency>\r\n<groupId>org.springframework.boot<\/groupId>\r\n<artifactId>spring-boot-starter-thymeleaf<\/artifactId>\r\n<\/dependency>\r\n<\/pre>\n
Spring Boot Thymeleaf\u793a\u4f8b<\/h2>\n
\n 2.3.0.M1\u3002<\/strong>\n <\/div>\n
\n \u7ec4<\/strong>\u540d\u79f0\u3002\u6211\u4eec\u63d0\u4f9b\u4e86
\n com.lidihuo <\/strong>\u3002\n <\/div>\n
\n \u5de5\u4ef6<\/strong> ID\u3002\u6211\u4eec\u63d0\u4f9b\u4e86
\n spring-boot-thymeleaf-view-example\u3002<\/strong>\n <\/div>\n
\n Spring Web <\/strong>\u548c
\n Thymeleaf<\/strong>\u3002\n <\/div>\n
\n Generate <\/strong>(\u751f\u6210)\u6309\u94ae\u3002\u5f53\u6211\u4eec\u5355\u51fb\"\u751f\u6210\"\u6309\u94ae\u65f6\uff0c\u5b83\u5c06\u89c4\u683c\u5305\u88c5\u5728
\n Jar <\/strong>\u6587\u4ef6\u4e2d\uff0c\u5e76\u5c06\u5176\u4e0b\u8f7d\u5230\u672c\u5730\u7cfb\u7edf\u3002\n <\/div>\n <\/p>\n
\n com.lidihuo <\/strong>\u4e2d\u521b\u5efa\u7c7b\u3002\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a
\n User\u7684\u7c7b\u3002<\/strong>\n <\/div>\n
\n name <\/strong>\u548c
\n email <\/strong>\u5e76\u751f\u6210
\n Getter\u548cSetters\u3002<\/strong>\n <\/div>\n\r\npackage <\/span>com.lidihuo; \r\npublic <\/span>class <\/span>User \r\n{ \r\nString name; \r\nString email; \r\npublic <\/span>String getName() \r\n{ \r\nreturn <\/span>name; \r\n} \r\npublic void <\/span>setName(String name) \r\n{ \r\nthis<\/span>.name = name; \r\n} \r\npublic <\/span>String getEmail() \r\n{ \r\nreturn <\/span>email; \r\n} \r\npublic void <\/span>setEmail(String email) \r\n{ \r\nthis<\/span>.email = email; \r\n} \r\n} \r\n<\/pre>\n
\n DemoController <\/strong>\u7684\u63a7\u5236\u5668\u7c7b\u3002\n <\/div>\n\r\npackage <\/span>com.lidihuo; \r\nimport org.springframework.web.bind.annotation.ModelAttribute; \r\nimport org.springframework.web.bind.annotation.RequestMapping; \r\nimport org.springframework.web.bind.annotation.RequestMethod; \r\nimport org.springframework.web.servlet.ModelAndView; \r\nimport org.springframework.stereotype.Controller; \r\n@Controller \r\npublic <\/span>class <\/span>DemoController \r\n{ \r\n@RequestMapping(\"\/\"<\/span>) \r\npublic <\/span>String index()\r\n{ \r\nreturn\"index\"<\/span>; \r\n} \r\n@RequestMapping(value=\"\/save\"<\/span>, method=RequestMethod.POST) \r\npublic <\/span>ModelAndView save(@ModelAttribute User user)\r\n{ \r\nModelAndView modelAndView = new <\/span>ModelAndView(); \r\nmodelAndView.setViewName<\/span>(\"user-data\"<\/span>); \r\nmodelAndView.addObject<\/span>(\"user\"<\/span>, user); \r\nreturn <\/span>modelAndView; \r\n} \r\n}\r\n<\/pre>\n
\n \u6a21\u677f\u5185\u90e8<\/strong>(src\/main\/resources\/\u6a21\u677f)\u6587\u4ef6\u5939\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u79f0\u4e3a
\n user-data <\/strong>\u7684Thymeleaf\u6a21\u677f\u3002\n <\/div>\n\r\n<html lang=\"en\"<\/span> xmlns:th=\"http:\/\/www.thymeleaf.org\"<\/span>>\r\n<\/pre>\n
\r\n<html xmlns:th=\"https:\/\/thymeleaf.org\"<\/span>> \r\n<table> \r\n<tr> \r\n<td><h4>User Name: <\/h4><\/td> \r\n<td><h4 th:text=\"${user.name}\"<\/span>><\/h4><\/td> \r\n<\/tr> \r\n<tr> \r\n<td><h4>Email ID: <\/h4><\/td> \r\n<td><h4 th:text=\"${user.email}\"<\/span>><\/h4><\/td> \r\n<\/tr> \r\n<\/table> \r\n<\/html>\r\n<\/pre>\n
\n HTML <\/strong>\u6587\u4ef6\u3002\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a
\n index <\/strong>\u7684HTML\u6587\u4ef6\u3002\n <\/div>\n\r\n<html lang=\"en\"<\/span>> \r\n<head> \r\n<title>Index Page<\/title> \r\n<\/head> \r\n<body> \r\n<form action=\"save\"<\/span> method=\"post\"<\/span>> \r\n<table> \r\n<tr> \r\n<td><label for=\"user-name\"<\/span>>User Name<\/label><\/td> \r\n<td><input type=\"text\"<\/span><\/span> name=\"name\"<\/span>><\/input><\/td> \r\n <\/tr> \r\n<tr> \r\n<td><label for=\"email\"<\/span><\/span>>Email<\/label><\/td> \r\n<td><input type=\"text\" name=\"email\"><\/input><\/td> \r\n<\/tr> \r\n<tr> \r\n<td><\/td> \r\n<td><input type=\"submit\"<\/span> value=\"Submit\"<\/span>><\/input><\/td> \r\n<\/tr> \r\n<\/table> \r\n<\/form> \r\n<\/body> \r\n<\/html>\r\n<\/pre>\n
\n application.properties <\/strong>\u6587\u4ef6\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5c5e\u6027\u3002\n <\/div>\n\r\nspring.thymeleaf.cache=false\r\nspring.thymeleaf.suffix: .html\r\n<\/pre>\n
<\/p>\n
\n SpringBootThymeleafViewExampleApplication.java <\/strong>\u6587\u4ef6\u5e76\u4ee5Java\u5e94\u7528\u7a0b\u5e8f\u3002\n <\/div>\n\r\npackage <\/span>com.lidihuo;\r\nimport org.springframework.boot.SpringApplication;\r\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\r\n@SpringBootApplication\r\npublic <\/span>class <\/span>SpringBootThymeleafViewExampleApplication \r\n{\r\npublic <\/span>static void <\/span>main(String[] args) \r\n{\r\nSpringApplication.run<\/span>(SpringBootThymeleafViewExampleApplication.class, args);\r\n}\r\n}\r\n<\/pre>\n
<\/p>\n
\n \u7528\u6237\u540d<\/strong>\u548c
\n \u7535\u5b50\u90ae\u4ef6<\/strong>\uff0c\u7136\u540e\u5355\u51fb
\n \u63d0\u4ea4<\/strong>\u6309\u94ae\u3002\n <\/div>\n <\/p>\n
\n \u63d0\u4ea4<\/strong>\u6309\u94ae\uff0cURL\u66f4\u6539\u4e3ahttp:\/\/localhost: 8080\/save\u5e76\u663e\u793a\u663e\u793a\u7528\u6237\u6570\u636e\uff0c\u5982\u4e0b\u6240\u793a\u3002\n <\/div>\n <\/p>\n
\n CSS <\/strong>\u548c
\n JS <\/strong>\u6587\u4ef6\u3002\u8fd9\u4e9b\u6587\u4ef6\u5fc5\u987b\u4f4d\u4e8e
\n src\/main\/resources\/static <\/strong>\u6587\u4ef6\u5939\u4e0b\u3002\n <\/div>\n
<\/div>\n
\n Python \u53d8\u91cf >> \n <\/div>\n
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"SpringBoot Thymeleafzh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[104],"tags":[],"class_list":["post-592","post","type-post","status-publish","format-standard","hentry","category-bc_springboot_jc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/592"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=592"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/592\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}