访问springboot项目接口404错误

这是启动类和controller位置情况

这是接口代码

这是启动类代码

这是boot项目加的依赖代码

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>8.0.21</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>po</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>service</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.1</version>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

这是配置文件代码

这是postman中调用接口的结果

在浏览器中调用也是一样的结果

在网上尝试了各种办法解决不了,求大神帮忙解决一下,这个问题跨不过去的话我接下来的学习无法开展,感激不尽!

org.example.*应该是你的service类所在包吧,你的controller类所在包为com.example.controller包里

你的配置@ComponentScan(basePackages= 只扫描了org.example.*下面的包,MajorController类没有扫描到,只需要添加扫描一下com.example.controller包就可以了

@MapperScan("org.example.*")
@SpringBootApplication
// @ComponentScan(basePackages = {"org.example.*"})
@ComponentScan(basePackages = {"com.example.controller","org.example.*"})
public class ControllerApplication {

@ComponentScan(value = "org.example")

去掉*号试试

你这个/major/list  总感觉有点问题

 

您好,可以参考https://blog.csdn.net/Im1997/article/details/112991648这个链接,我感觉你的mapper没有扫描到,已经配置文件yml里面也有问题,配置扫码Mapper.xml文件。

您好,可以参考https://blog.csdn.net/Im1997/article/details/112991648这个链接,我感觉你的mapper没有扫描到,配置文件yml里面也有问题,配置扫码Mapper.xml文件。

这项目的结构好奇怪啊     你这启动项应该是需要手动配置扫描的...

 

我的问题犯的很粗心,因为是聚合项目,po,mapper,service都放在org.example路径下,唯独controller放在com.example下,启动类没有扫描到,

谢谢大家的帮助

你的启动类应该放在包的外面,不要和controller放在同一个包下