"id" : 24787807536939046,
"acId" : 24768209282400257,
"insertTime" : 1476957265000,
"lastUpdateTime" : 1476957265000,
这里返回的id,acid因为是long类型,如果数值太大在js里会失真,怎么在返回的时候让24787807536939046为string类型,通过注解
巴扎黑2017-04-18 10:29:00
Change the type of id to String
, and do the conversion between Long and String when processing.
天蓬老师2017-04-18 10:29:00
Similar to this question about portal.
If it doesn’t meet your needs, you need to customize a Gson serialization method yourself.
天蓬老师2017-04-18 10:29:00
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);
}
伊谢尔伦2017-04-18 10:29:00
(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.