zoukankan      html  css  js  c++  java
  • fastjson @JSONField自定义输出字段

    在数据库和JAVA实体类命名转换过程中,命名不一致是经常发生的问题。fastjson中注解@JSONField帮忙解决了这个问题。

    Java代码 

     收藏代码

    1. public class RoleData{  
    2. @JSONField(name="role_name")  
    3. private String roleName;  
    4. @JSONField(name="role_server")  
    5. private String roleServer;  
    6. @JSONField(name="role_level")  
    7. private String roleLevel;  
    8. @JSONField(name="role_coin")  
    9. private String roleCoin;  
    10. public String getRoleName() {  
    11. return roleName;  
    12. }  
    13. public void setRoleName(String roleName) {  
    14. this.roleName = roleName;  
    15. }  
    16. public String getRoleServer() {  
    17. return roleServer;  
    18. }  
    19. public void setRoleServer(String roleServer) {  
    20. this.roleServer = roleServer;  
    21. }  
    22. public String getRoleLevel() {  
    23. return roleLevel;  
    24. }  
    25. public void setRoleLevel(String roleLevel) {  
    26. this.roleLevel = roleLevel;  
    27. }  
    28. public String getRoleCoin() {  
    29. return roleCoin;  
    30. }  
    31. public void setRoleCoin(String roleCoin) {  
    32. this.roleCoin = roleCoin;  
    33. }  
    34.    
    35. }  

    可以通过@JSONField制定日期格式

    Java代码 

     收藏代码

    1. public class A {  
    2.       // 配置date序列化和反序列使用yyyyMMdd日期格式  
    3.       @JSONField(format="yyyyMMdd")  
    4.       public Date date;  
    5.  }  

    也可以通过@JSONField指定字段的顺序

    Java代码 

     收藏代码

    1. public static class VO {  
    2.     @JSONField(ordinal = 3)  
    3.     private int f0;  
    4.    
    5.     @JSONField(ordinal = 2)  
    6.     private int f1;  
    7.    
    8.     @JSONField(ordinal = 1)  
    9.     private int f2;  
    10. }  
  • 相关阅读:
    poj 3253超时
    poj 3617输出格式问题
    dfs的返回条件
    hdu1010感想
    2018.7.19训练赛总结
    2018.7.12训练赛 -G
    汇编实验16 编写包含多个功能子程序的中断例程——浅谈直接地址表
    新的一年来了,先看一看自己的编程能力吧!
    汇编实验15:安装新的int 9中断例程
    汇编实验14:访问CMOS RAM
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13317468.html
Copyright © 2011-2022 走看看