美文网首页Java
springboot(一):集成jsp

springboot(一):集成jsp

作者: 修远路 | 来源:发表于2018-08-29 15:10 被阅读0次

    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
    

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

    相关文章

      网友评论

        本文标题:springboot(一):集成jsp

        本文链接:https://www.haomeiwen.com/subject/maxkwftx.html