前后端不分离
1.对静态资源的映射处理
2.模板引擎:
模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档。
官网定义:As well as REST web services, you can also use Spring MVC to serve dynamic HTML content. Spring MVC supports a variety of templating technologies, including Thymeleaf, FreeMarker, and JSPs. Also, many other templating engines include their own Spring MVC integrations(兼容方式).
为什么要放弃使用JSP?
JSP 是一种 embedded servlet container (and is packaged as an executable archive),嵌入式servlet容器,可以在jsp页面写java语句获取后端数据,运行时被打包成可以执行的压缩文件
1.With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.
2.Undertow does not support JSPs.
3.Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.
Spring Boot不支持JSP的打包方式。
Undertow 是红帽公司开发的一款基于 NIO 的高性能 Web 嵌入式服务器,它不支持JSP
error.jsp应该进行改进
3.Thymeleaf百里香叶
官网定义:
Thymeleaf is a modern server-side Java template engine for both web and standalone environments.独立环境*
Thymeleaf's main goal is to bring elegant优雅的 natural templates to your development workflow — HTML that can be correctly displayed in browsers and also work as static prototypes静态原型, allowing for stronger collaboration 合作in development teams.
With modules for Spring Framework, a host of integrations with your favourite(favorite是美式英语,而favourite是英式英语) tools, and the ability to plug in your own functionality, Thymeleaf is ideal for modern-day HTML5 JVM web development — although there is much more it can do.
4.使用Thymeleaf【官网对这一部分只是介绍极少】
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
前后端分离
get post put delete 四种请求方式
涉及到的注解:
@RestController返回JSON格式数据
@GetMapping("/goods/{id}")处理get请求id要用@PathVariable("id")接收
@PostMapping("/goods")传JSON数据可以使用@RequestBody
@PutMapping处理修改数据
@DeleteMapping
同时结合postman处理数据
接口自动化测试
swagger生成在线API文档
Simplify API development for users, teams, and enterprises with the Swagger open source and professional toolset. Find out how Swagger can help you design and document your APIs at scale大规模的.
看到非常棒的一个Spring Boot教程 分享给大家:
http://www.imooc.com/wiki/springbootlesson/cors.html