Java

springboot(一):集成jsp

2018-08-29  本文已影响0人  修远路

1.注解

@RestController <=> @Controller + @ResponseBody

@GetMapping("users") <=> @RequestMapping(value = "users", method = RequestMethod.GET)

@PostMapping @PutMapping @DeleteMapping同理

2.JSP集成

pom添加

<!-- 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>
<!-- 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

[附]git源码地址
https://github.com/SaltzmanAlaric/springboot-jsp

上一篇 下一篇

猜你喜欢

热点阅读