In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to customize parameter binding in SpringBoot, the content is very detailed, interested friends can refer to, hope to be helpful to you.
1. Custom parameter converter
The custom parameter converter implements the Converter interface, as follows:
Public class DateConverter implements Converter {private SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("yyyy-MM-dd"); @ Override public Date convert (String s) {if (".equals (s) | | s = = null) {return null;} try {return simpleDateFormat.parse (s);} catch (ParseException e) {e.printStackTrace ();} return null;}}
The convert method takes a string parameter, which is the date string from the front end, which meets the yyyy-MM-dd format, and then converts the string to a Date object through SimpleDateFormat and returns it.
two。 Configuration converter
Custom WebMvcConfig inherits WebMvcConfigurerAdapter and is configured in the addFormatters method:
Configurationpublic class WebMvcConfig extends WebMvcConfigurerAdapter {@ Override public void addFormatters (FormatterRegistry registry) {registry.addConverter (new DateConverter ());}}
OK, after the above two steps, we can receive a string date from the front end on the server side and convert it to a Date object in Java. The front end date control is as follows:
The server APIs are as follows:
@ RequestMapping (value = "/ emp", method = RequestMethod.POST) public RespBean addEmp (Employee employee) {if (empService.addEmp (employee) = = 1) {return new RespBean ("success", "add successful!");} return new RespBean ("error", "add failed!") } on how to customize the parameter binding in SpringBoot to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.