1.注解
@RestController <=> @Controller + @ResponseBody
@GetMapping("users") <=> @RequestMapping(value = "users", method = RequestMethod.GET)
@PostMapping @PutMapping @DeleteMapping同理
2.JSP集成
pom添加
- dependencies节点
<!-- springboot内嵌的tomcat对jsp的解析包 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- servlet依赖jar包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- jsp依赖jar包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
</dependency>
<!-- jstl依赖jar包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
- build节点
<!-- compile -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
application.yml添加
spring:
# 编码
http:
encoding:
charset: utf-8
enabled: true
force: true
# jsp
mvc:
view:
# 默认src/main/webapp下面
prefix: /
suffix: .jsp
网友评论