[英]Beginner - Spring boot - how to print @RequestParam
我正在学习Spring Boot
。
如何在show
方法中show
@RequestParam
参数(城市)?
(我有两个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";
}
如果要在视图中显示城市,则必须将城市添加到模型中,例如:
model.addAttribute("city", city);
并在${city}
视图内
相反,如果要使用控制台打印参数,则可以使用记录器:
在您的控件内以这种方式声明
final Logger logger = LoggerFactory.getLogger(YourClass.class);
然后在方法里面:
@GetMapping("/show")
public String show(@RequestParam ("city") String city, ModelMap modelMap){
modelMap.addAttribute("article");
logger.info("whatever you want "+city);
return "article/show";
}
试试这个: modelMap.addAttribute("city", city);
然后在${city}
类的JSP / Thymeleaf端检索它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.