繁体   English   中英

具有相同路径的多个@GetMapping servlet?

[英]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.

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