我有一个使用Spring boot 2.7.1的应用程序,当我键入地址http://localhost:9096/popup/111111时,我得到以下响应:
此应用程序没有 /error的显式映射,因此您将此视为回退。
Tue Aug 02 12:20:32 CET 2022出现意外错误(type=Not Find,status=404)。
pom. xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
application. yml
server:
port: 9096
spring:
thymeleaf:
cache: false
enabled: true
mode: HTML5
prefix: /templates/
suffix: .html
控制器:
@Controller("popup")
public class PopupRequest {
@GetMapping("/{requestNumber}")
String index(@PathVariable("requestNumber") String requestNumber) {
return "index";
}
}
尝试将@Request estMaps("/popup")作为注释添加到类中,如下所示:
@Controller
@RequestMapping("/popup")
public class PopupRequest {
@GetMapping("/{requestNumber}")
String index(@PathVariable("requestNumber") String requestNumber) {
return "index";
}
}
您必须用括号("/")封闭请求映射
Controller
@RequestMapping("/popup")
public class PopupRequest {
@GetMapping("/{requestNumber}")
String index(@PathVariable("requestNumber")String r requestNumber){
return "index";
}
}