In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the java Long type into json after the data loss accuracy how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
In the project development, using the architecture of spring boot+mybatis, the database design primary key id is defined as the bigint type, do not notice after using the automatically generated code of mybatis, the type of primary key in pojo is Long. There is no problem with the value taken out from the object list obtained during the query, but after it is converted to json and passed to the front end, the data of id is never the one found in the database.
Design of database table structure
AbumTip class
Query result in database based on foreign key abum_id
The results found by Controller
Chrome browser preview results
You can see that the data of type Long queried by abumId (corresponding table abum_id) and tipId (corresponding table tip_id) is incorrect.
The first method of solution
Regenerate the pojo object, mapping all database types to bigint to String types.
Method two
For using springboot, add the configuration code:
Package com.gj.app.config; import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.module.SimpleModule;import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;import org.springframework.context.annotation.Configuration;import org.springframework.http.converter.HttpMessageConverter;import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import java.util.List @ EnableWebMvc@Configurationpublic class WebDataConvertConfig extends WebMvcConfigurerAdapter {public void configureMessageConverters (List
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.