简体   繁体   English

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

[英]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 。第一个带有要提交的formbutton ,第二个页面用于显示来自formString值)。

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

相关问题 spring启动时如何处理RequestParam中的大括号 - How to handle curly braces in RequestParam in spring boot 如何在Spring Boot中不解码@RequestParam设置的字符串? - How to not decode the string set by @RequestParam in Spring Boot? Spring Boot发送RequestBody和RequestParam - Spring boot send RequestBody and RequestParam 在 Spring 引导中使用 LocalDateTime RequestParam - Use LocalDateTime RequestParam in Spring boot 如何将未知的传入 requestParam 传递给 spring boot 中的帖子? - How to pass an unknown incoming requestParam to a post in spring boot? 如何在Spring boot中将多维数组列表处理为@RequestParam - How to handle List of multidimensional array as @RequestParam in Spring boot Spring 引导 - 如何区分 @PathVariable 和查询参数 (@RequestParam) 的验证 - Spring Boot - how to differentiate between validation for @PathVariable and query params (@RequestParam) 如何在@Requestparam java spring 引导中传递加密值 - How to pass encrypted value in @Requestparam java spring boot Web服务使用Spring Boot支持RequestBody或RequestParam - Webservice supporting RequestBody or RequestParam using spring boot Spring Boot:是否可以将@RequestParam 作为 json 使用? - Spring Boot: Is it possible to consume @RequestParam's as json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM