Some minor problems encountered in the springBoot project demo

1. When creating a project, select project -> springInitializr (if you don't have it, you can search for and install spring Boot in plugins), and then write the project name, all the way to next, finish.
2. After the project is created, the jsp directory recognized by springboot by default needs to be configured, otherwise access to jsp will fail 404. Springboot does not need a web.xml file. Create a webApp directory in the main directory, click file->project Structure ->Modules, pay attention Look at the directory under the web Resource Directory in the picture below (the default is not available, you can click the "+" on the right to create it), select the webApp directory you just created, this means that the jsp file can be recognized in the webApp directory.
Insert picture description here
3. Configure the relevant configuration of the project in application.properties. For
some simple configurations, please refer to my following configuration:

#服务器端的配置
server.port=8080
server.tomcat.uri-encoding=UTF-8
#頁面的配置
spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp
#静态数据的配置,css、js等之类的静态资源就放在该目录下
spring.mvc.static-path-pattern=/static/**

4. JSP access 404 error
. Check carefully whether there is an external dependency of tomcat in your porm.xml (I don't have it by default anyway). If not, please add it, and then it will be ok.

        <!-- 加入tomcat依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <!-- SpringBoot 外部tomcat支持 -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

Guess you like

Origin blog.csdn.net/qq_39719415/article/details/94395682