简体   繁体   中英

Spring Boot Thymeleaf Whitelabel Error Page

I have an apllication using spring boot 2.7.1, when i type the address http://localhost:9096/popup/111111, I get the below response:

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Aug 02 12:20:32 CET 2022 There was an unexpected error (type=Not Found, 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:

@Controller("popup")
public class PopupRequest {

    @GetMapping("/{requestNumber}")
    String index(@PathVariable("requestNumber") String requestNumber) {
        return "index";
    }
}

Try adding @RequestMapping("/popup") as an annotation to the class like so:

@Controller
@RequestMapping("/popup")
public class PopupRequest {

    @GetMapping("/{requestNumber}")
    String index(@PathVariable("requestNumber") String requestNumber) {
        return "index";
    }
}
   //
   You must inclose request mapping with 
   parenthesis ("/")
    //
    Controller
    @RequestMapping("/popup")
    public class PopupRequest {
    @GetMapping("/{requestNumber}")
 String index(@PathVariable("requestNumber"String r requestNumber) {
    return "index";
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM