[英]Beginner - Spring boot - how to print @RequestParam
I'm learning Spring Boot
. 我正在学习
Spring Boot
。
What should I do to display param (city) from @RequestParam
in the show
method? 如何在
show
方法中show
@RequestParam
参数(城市)?
(I have two html
. First with form
and button
to submit and second page to show the String
value from form
). (我有两个
html
。第一个带有要提交的form
和button
,第二个页面用于显示来自form
的String
值)。
@GetMapping("/show")
public String show(@RequestParam ("city") String city, ModelMap modelMap){
modelMap.addAttribute("article");
System.out.println(city);
return "article/show";
}
If you want show city inside a view you have to add the city to the model, something like: 如果要在视图中显示城市,则必须将城市添加到模型中,例如:
model.addAttribute("city", city);
and inside the view ${city}
并在
${city}
视图内
Instead if you want print the parameter using the console , you can use a logger: 相反,如果要使用控制台打印参数,则可以使用记录器:
inside your controllore declare it in this way 在您的控件内以这种方式声明
final Logger logger = LoggerFactory.getLogger(YourClass.class);
then inside the method: 然后在方法里面:
@GetMapping("/show")
public String show(@RequestParam ("city") String city, ModelMap modelMap){
modelMap.addAttribute("article");
logger.info("whatever you want "+city);
return "article/show";
}
Try this: modelMap.addAttribute("city", city);
试试这个:
modelMap.addAttribute("city", city);
and then retrieve it in the JSP / Thymeleaf side like ${city}
. 然后在
${city}
类的JSP / Thymeleaf端检索它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.