【发布时间】:2019-05-12 11:14:29
【问题描述】:
我的控制器上有这个功能:
@RequestMapping(value = "/Myvariable")
public String fct(Model md, @RequestParam String Myparameter) {//code}
@RequestMapping(value = "/Myvariable2")
public String fct2(Model md, @RequestParam String Myparameter2) {//code}
@RequestMapping(value = "/Myvariable3")
public String fct3(Model md, @RequestParam String Myparameter3) {//code}
函数与这样的 URL 相关:
http://localhost:3000/Myvariable?Myparameter=***
http://localhost:3000/Myvariable2?Myparameter2=***
http://localhost:3000/Myvariable3?Myparameter3=***
如何使只有一个RequestMapping和一个代码只有一页html来发挥三页的作用?
【问题讨论】:
-
尽量提供更多细节,给我们一些例子来了解你的情况!
-
我有三个具有相同功能的页面:localhost:3000/home?Myparameter=01localhost:3000/study?Myparameter=02localhost:3000/work?Myparameter=05 当我输入其中一个网址时,我会调用它的控制器吗?但每个控制器内部的代码都是相同的,唯一改变的是页面名称。我想设置一页,例如localhost:3000/variable,这个变量可以是 {home,work,study} 。
-
好的,所以你可以做一个 requestMapping 并设置你的变量或参数,你喜欢一个开关或 if 条件来测试是家庭、工作还是学习,然后你返回正确的页面!
标签: html spring spring-boot jakarta-ee frameworks