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>

 

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值