JavaEE框架整合开发创新·协作·分享第七章SpringBoot的Web开发本章目标1.掌握Thymeleaf视图模板引擎技术2.掌握SpringBoot的JSON数据交互技术3.掌握SpringBoot的文件上传与下载4.掌握SpringBoot的异常统一处理5.了解SpringBoot对JSP的支持2本章内容37.1SpringBoot的Web开发支持7.2Thymeleaf模板引擎7.3SpringBoot处理JSON数据7.4SpringBoot文件上传与下载7.5SpringBoot的异常统一处理7.6SpringBoot对JSP的支持7.1SpringBoot的Web开发支持4
org.springframework.bootspring-boot-starter-webSpringBoot将自动关联Web开发的相关依赖,如tomcat、spring-webmvc等,进而对Web开发的支持,并将相关技术的配置实现自动配置。另外,开发者也可以使用SpringToolSuite集成开发工具快速创建SpringStarterProject,在“NewSpringStarterProjectDependencies”窗口中添加SpringBoot的Web依赖。是不是似曾相识的感觉?本章内容57.1SpringBoot的Web开发支持7.2Thymeleaf模板引擎7.3SpringBoot处理JSON数据7.4SpringBoot文件上传与下载7.5SpringBoot的异常统一处理7.6SpringBoot对JSP的支持7.2Thymeleaf模板引擎7.2.1SpringBoot的Thymeleaf支持7.2.2Thymeleaf基础语法7.2.3Thymeleaf的常用属性7.2.4SpringBoot与Thymeleaf实现页面信息国际化7.2.5SpringBoot与Thymeleaf的表单验证7.2.6基于Thymeleaf与BootStrap的Web开发实例67.2.1SpringBoot的Thymeleaf支持在Spring5中,WebFlux的出现对于Web应用的解决方案将不再唯一。所以,spring-boot-starter-thymeleaf依赖不再包含spring-boot-starter-web模块,需要开发人员自己选择spring-boot-starter-web模块依赖。【例7-1】创建基于Thymeleaf模板引擎的SpringBootWeb应用ch7_1。7创建SpringStarterProject选择菜单“File->New->SpringStarterProject”,打开“NewSpringStarterProject”对话框,在该对话框中选择和输入相关信息后,单击“Next”按钮,打开“NewSpringStarterProjectDependencies”对话框。8选择依赖9打开项目目录10Tymeleaf模板默认将JS脚本、CSS样式、图片等静态文件默认放置在src/main/resources/static目录下;将视图页面放在src/main/resources/templates目录下。创建控制器类11@ControllerpublicclassTestThymeleafController{@RequestMapping("/")publicStringtest(){//根据Tymeleaf模板,默认将返回sr...