SpringBoot整合JSP笔记整理

  1. pom添加依赖
    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.apache.tomcat.embedgroupId>
            <artifactId>tomcat-embed-jasperartifactId>
        dependency>
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>jstlartifactId>
        dependency>
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>javax.servlet-apiartifactId>
            <scope>providedscope>
        dependency>
    dependencies>
    
  2. springboot build plugin版本1.4.2, 高版本404错误
     <plugin>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-maven-pluginartifactId>
        <version>1.4.2.RELEASEversion>
        <executions>
            <execution>
                <id>repackageid>
                <goals>
                    <goal>repackagegoal>
                goals>
            execution>
        executions>
    plugin>
    
  3. maven配置jsp资源路径
    <resources>
        
        <resource>
            
            <directory>src/main/webappdirectory>
            
            <targetPath>META-INF/resourcestargetPath>
            <includes>
                <include>**/**include>
            includes>
        resource>
    resources>
    
  4. application中添加配置
    ## 这里目录是以webapp为根目录的相对路径配置
    spring.mvc.view.prefix=/pages/
    spring.mvc.view.suffix=.jsp
    
  5. 必须使用jdk1.8 (使用17 Unable to open root Jar file 'war:… shiro-web-1.13.0.jar)
  6. webapp/pages/index.jsp
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    
    
        Home
    
    
        

    欢迎登录, ${user.username}

  7. Controller编写
    @Slf4j
    @Controller
    public class HelloController {
        @RequestMapping("/index")
        public String index(){
            return "index" ;
        }
    }
    

你可能感兴趣的:(java,spring,boot,jsp)