IntelliJ IDEA 快速创建基于Spring Boot的web项目

1、直接选择Spring Initializr项目点击【next】

2、直接【next】

3、选择Web-->web直接【next】

4、Finish

5、项目创建完成,项目结构

6、写个Controller启动一下看是否可以访问,可以打个断点进行测试

此时页面显示,需要导入jsp包

7、pom.xml文件中导入jar包。

导入jar

<dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency>
在创建jsp页面之前先创建webapp和WEB-INF文件夹:File-->Project Structure-->Modules-->Web,指定目录

创建WEB-INF文件夹

7、创建web.xml

8、此时项目目录结构

9、配置jsp文件存放目录在application.properties文件中

spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp

9、创建indexPage.jsp文件在WEB-INF目录下

10、重启我们的项目,直接访问:http://localhost:8080/demo/indexPage

11、问题

出现此种问题是配置文件没有配正确:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Oct 30 16:45:05 CST 2018

There was an unexpected error (type=Internal Server Error, status=500).

Circular view path [indexPage]: would dispatch back to the current handler URL [/demo/indexPage] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

出现此种问题是jar包没有配置正确:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Oct 30 16:48:43 CST 2018

There was an unexpected error (type=Not Found, status=404).

No message available

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

 

展开阅读全文

没有更多推荐了,返回首页