当前位置:   article > 正文

关于JSONObject,当返回数据较简单且无集合,对象等嵌套的属性时,可以不需要建立VO类,可直接返回json结构的数据给前端。_hutoo的jsonobject有set方法没

hutoo的jsonobject有set方法没

首先导入依赖

  1. <!-- hutool国产工具包 -->
  2. <dependency>
  3. <groupId>cn.hutool</groupId>
  4. <artifactId>hutool-all</artifactId>
  5. <version>5.7.15</version>
  6. </dependency>

用法:

  1. JSONObject jsonObject = new JSONObject();
  2. jsonObject.set("baseAchieveCount", baseAchieveCount);
  3. jsonObject.set("baseNeedCount", baseNeedCount);
  4. jsonObject.set("selectAchieveCount", selectAchieveCount);
  5. jsonObject.set("selectNeedCount", selectNeedCount);
  6. jsonObject.set("scoreAchieveCount", scoreAchieveCount);
  7. jsonObject.set("scoreNeedCount", scoreNeedCount);
  8. return ResponseResult.success(jsonObject);

可直接new一个json对象,如何对应赋值属性名与属性值

结果:

 与对应VO实体类返回是一样的效果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/485442
推荐阅读
相关标签
  

闽ICP备14008679号