[英]Multiple @GetMapping servlets with same path?
我想为/persons
路径创建多个servlet。 没有任何查询参数的路径应仅用于html页面(使用Thymeleaf
模板)。
带有参数的参数应改为使用数据填充http模型。
@Controller
@RequestMapping("/persons")
public class PricingCacheController {
//default just routing to the html template
@GetMapping(params = "")
public String personsHtml() {
System.out.println("initial page load");
return "persons";
}
@GetMapping
public String personsGet(Model model, @RequestParam MyBean bean) {
System.out.println("get request");
model.addAttribute("dto", dao.findAll());
return "persons";
}
执行localhost:8080/persons
,找不到404
。
您无法执行此操作,servlet映射是在url级别完成的,并且在解析url时将忽略查询参数,因此,由于您必须为同一路径映射(无论查询参数如何),您将得到404,为什么不使用路径变量?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.