1.确保Application应用类位于根目录下,即Application类要和controller包在同一目录下

idea中springboot请求总是404_根目录

2.Application应用类内部代码如下,MyWxutilsApplication要改成自己的应用类名

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

@SpringBootApplication
public class MyWxutilsApplication {

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

3.控制器类上要有两个注解,分别是@RestController、@RequestMapping,控制器类的方法上要有一个注解,即@RequestMapping

@RestController和@Controller的区别:

@RestController是返回字符串的,@Controller是返回页面

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
@RequestMapping("/auth")
public class AuthorizeController {

@RequestMapping("/test")
public String test(){
return "success";
}

}

4.访问路径要写对

http://localhost:8080/auth/test

5.强制刷新页面