Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as

 一、错误原因


1. 先查看application.yml中的serve配置或数据库的配置是否正确:
 

# 服务器配置
server:
  port: 8081  # 应用服务的 WEB 访问端口

# MyBatis 配置
mybatis:
  mapper-locations: classpath:mappers/*.xml  # 指定 MyBatis 的 Mapper 文件路径
  type-aliases-package: com.example.shop.mybatis.entity  # 指定 MyBatis 的实体类包路径

#数据库配置
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver  # 数据库驱动类名
    url: jdbc:mysql://localhost:3306/shop?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false  # 数据库连接 URL
    username: root  # 数据库用户名
    password: 123  # 数据库密码

2. 文件结构不对:
   查看启动类的位置是否如下

Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as_第1张图片

 

3.controller层请求路径不对

package com.example.shop.controller;

import com.example.shop.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//接口入口:用于前端调用
@RestController
@RequestMapping("/user")
public class UserController {
    @GetMapping//无论是否要配置访问路径,这个注解一定一定要记得加上!!!
    public String start(){
        return "hello springboot!";
    }
    @GetMapping("/getUser")
    public User user(){
        return new User(1,"user1", "password1");
    }
}

二、小结

今日份大讨厌鬼又又叕叕被我拿下,一定要狠狠分析,不然对不起我这一下午了!!!!!

 

 

你可能感兴趣的:(java学习,笔记)