ku叽ᝰ 2022-06-30 11:13 采纳率: 0%
浏览 46

无法跳转页面,404

问题遇到的现象和发生背景

闲来无事想自己创一个springboot项目练练手,可是项目起来了无法跳转到页面,页面刷新提示404,有没有大boss可以帮帮忙?
个人猜测是哪里配置不对

问题相关代码,请勿粘贴截图

Controller:

package com.myspringboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/hello")
public class Mydemo {
    @GetMapping("/hello")
    public ModelAndView hello(){
        return new ModelAndView("mydemo");
    }
}

启动类:

package com.myspringboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages="com.myspringboot")
public class MydemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(MydemoApplication.class, args);
    }

}

html:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>hihihihihihihihihihihi</h1>
</body>
</html>

application.properties:

#端口号
server.port=8080

#应用的上下文路径(项目路径)
#server.servlet.context-path=/allModel

#指定POJO扫描包来让mybatis自动扫描到自定义的POJO
#mybatis.type-aliases-package=com.cxs.allmodel.model

#指定mapper.xml的路径
#(application上配置了@MapperScan(扫面mapper类的路径)和pom.xml中放行了mapper.xml后,
#配置mapper-locations没有意义。如果mapper类和mapper.xml不在同一个路径下时,mapper-locations就有用了)
#mybatis.mapper-locations=classpath:com/cxs/allmodel/mapper

#session失效时间(单位s)
spring.session.timeout=18000


#数据库连接配置
#mysql数据库url
mysql.one.jdbc-url=jdbc:mysql://127.0.0.1:3306/mydemo?serverTimezone=Asia/Shanghai&useSSL=false
#mysql数据库用户名
mysql.one.username=root
mysql.one.password=root
#线程池允许的最大连接数
#mysql.one.maximum-pool-size=


#日志打印:日志级别 trace<debug<info<warn<error<fatal 默认级别为info,即默认打印info及其以上级别的日志
#logging.level设置日志级别,后面跟生效的区域,比如root表示整个项目,也可以设置为某个包下,也可以具体到某个类名(日志级别的值不区分大小写)
logging.level.com.cxs.allmodel.=debug
logging.level.com.cxs.allmodel.mapper=debug
logging.level.org.springframework.web=info
logging.level.org.springframework.transaction=info
logging.level.org.apache.ibatis=info
logging.level.org.mybatis=info
logging.level.com.github.pagehelper = info
logging.level.root=info
#日志输出路径
logging.file.name=D://logs/mydemo.log

#配置pagehelper分页插件
#pagehelper.helperDialect=mysql
#pagehelper.reasonable=true
#pagehelper.supportMethodsArguments=true
#pagehelper.params=count=countSql

#jackson时间格式化
spring.jackson.serialization.fail-on-empty-beans=false
#指定日期格式,比如yyyy-MM-dd HH:mm:ss,或者具体的格式化类的全限定名
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
#指定日期格式化时区,比如America/Los_Angeles或者GMT+10
spring.jackson.time-zone=GMT+8

#设置统一字符集
#server.servlet.encoding.charset=utf8

#redis连接配置
# redis所在主机ip地址
#spring.redis.host=

#redis服务器密码
#spring.redis.password=

#redis服务器端口号
#spring.redis.port=

#redis数据库的索引编号(0到15
#spring.redis.database=14

## 连接池的最大活动连接数量,使用负值无限制
#spring.redis.pool.max-active=8
#
## 连接池的最大空闲连接数量,使用负值表示无限数量的空闲连接
#spring.redis.pool.max-idle=8
#
## 连接池最大阻塞等待时间,使用负值表示没有限制
#spring.redis.pool.max-wait=-1ms
#
## 最小空闲连接数量,使用正值才有效果
#spring.redis.pool.min-idle=0
#
## 是否启用SSL连接.
##spring.redis.ssl=false
#
## 连接超时,毫秒为单位
#spring.redis.timeout= 18000ms
#
## 集群模式下,集群最大转发的数量
#spring.redis.cluster.max-redirects=
#
## 集群模式下,逗号分隔的键值对(主机:端口)形式的服务器列表
#spring.redis.cluster.nodes=
#
## 哨兵模式下,Redis主服务器地址
#spring.redis.sentinel.master=
#
## 哨兵模式下,逗号分隔的键值对(主机:端口)形式的服务器列表
#spring.redis.sentinel.nodes= 127.0.0.1:5050,127.0.0.1:5060

#com.cxs.baidu=https://www.baidu.com

#配置中文编码格式
server.tomcat.uri-encoding=UTF-8
server.servlet.encoding.force=true
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true


#html????
spring.freemarker.suffix=.html
spring.freemarker.template-loader-path=classpath:/templates/
#?????
spring.freemarker.cache=false

#thymeleaf ??
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.check-template-location=true
#???
server.context-path=/thymeleaf

#服务名,必须与OPUS对应,否则登录失败
spring.application.name=mydemo
#服务访问虚拟路径
server.servlet.context-path=/${spring.application.name}




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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->

    </parent>
    <groupId>com.example</groupId>
    <artifactId>mydemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mydemo</name>
    <description>mydemo</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </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>

        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>

    </build>



</project>




img

运行结果及报错内容

运行结果:

img

页面:

img

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

3条回答 默认 最新

  • 专业些bug中 2022-06-30 11:46
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 6月30日

悬赏问题

  • ¥15 关于#hadoop#的问题,请各位专家解答!
  • ¥15 如何批量抓取网站信息
  • ¥15 Spring Boot离线人脸识别
  • ¥15 NRF24L01能发送但是不能接收
  • ¥15 想问一下这种情况怎么解决呢(关键词-file)
  • ¥15 python Flassk 模块部署 服务器时报错
  • ¥15 Opencv(C++)异常
  • ¥15 VScode上配置C语言环境
  • ¥15 汇编语言没有主程序吗?
  • ¥15 这个函数为什么会爆内存