java - spring boot返回json数据时long类型数据失真
大家讲道理
大家讲道理 2017-04-18 10:27:00
0
4
824

"id" : 24787807536939046,
"acId" : 24768209282400257,
"insertTime" : 1476957265000,
"lastUpdateTime" : 1476957265000,

这里返回的id,acid因为是long类型,如果数值太大在js里会失真,怎么在返回的时候让24787807536939046为string类型,通过注解

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
巴扎黑

Change the type of id to String, and do the conversion between Long and String when processing.

Peter_Zhu

Similar to this question about portal.

If it doesn’t meet your needs, you need to customize a Gson serialization method yourself.

Peter_Zhu

Customized ObjectMapper will automatically convert the Long type into string and send it to the front end

public class CustomObjectMapper extends ObjectMapper {

    private static final long serialVersionUID = 3223645203459453114L;

    /**
     * 构造函数
     */
    public CustomObjectMapper() {
        super();
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
        simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
        registerModule(simpleModule);
}
伊谢尔伦

(1) If the acId type can be changed, change it to string.
If the acId type implementation cannot be changed. (2) Method 1, redefine a javabean, but change the acId type to string.
(3) Method two, process the gson string again and add "" to both sides of 24768209282400257.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template