In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
When the front-end interface is docked, if the id or other fields in the background use the long integer Long, it is easy to lose the precision of js. When called by interface tools, id returns are often correct, but once on the page, js will be suffixed with 000.
The front end says there is a problem with the returned value, F12 take a look! The back end says no problem, Postman look!
This is a problem supported by js, and the solution to this problem is obviously to return a string.
How to achieve it, you can directly change the id of vo object to String type, but it will bring the inconvenience of copyProperties, so I have seen many people achieve it by adding virtual fields. Here's an overall solution: (Need a little understanding of Spring's message serialization principles, such as MappingJackson2 HttpMessage Converter is what)
MainConfig (usually the main config class, annotated with @Configuration, used to import some basic configuration) added MessageConvert rewrite extendMessageConverters:
@Overridepublic void extendMessageConverters(List converter : converters) { if (converter instanceof MappingJackson2HttpMessageConverter) { jacksonConverter = (MappingJackson2HttpMessageConverter) converter; } } if (jacksonConverter != null) { jacksonConverter.setObjectMapper(new CustomObjectMapper()); converters.add(jacksonConverter); }}CustomObjectMapper implementation: public class CustomObjectMapper extends ObjectMapper {public CustomObjectMapper() { super(); SimpleModule simpleModule = new SimpleModule(); simpleModule.addSerializer(Long.class, ToStringSerializer.instance); simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); registerModule(simpleModule);}}
So, when the interface returns, all the long fields are treated as strings and are automatically quoted.
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.