繁体   English   中英

初学者-Spring Boot-如何打印@RequestParam

[英]Beginner - Spring boot - how to print @RequestParam

我正在学习Spring Boot

如何在show方法中show @RequestParam参数(城市)?

(我有两个html 。第一个带有要提交的formbutton ,第二个页面用于显示来自formString值)。

@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.

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