返回json格式 不忽略null字段
@wendal 是加到对应字段还是实体,还是哪?
@wendal 例如Jackson的@JsonInclude
@wendal 个人觉得nutz需要关注一下https://nutz.cn/yvr/t/7fmfpb9oguivrqck7add0u7i1r这个问题
我添加了@Ok("json:full")之后null字段还是没有显示
@IocBean
@Ok("json:full")
@Fail("http:500")
@At("/facManageCar")
public class FacManagerCarModule extends BaseModule{
@At
public Object queryFacManageCar(FacManageCarReq req){
FacManageCarResp resp = new FacManageCarResp();
Pager pager = dao.createPager(req.page,20);
Cnd where = Cnd.NEW();
where.and("facId","=",req.factoryId);
if(req.carStatus==1){
where.and("carStatus","=",false);
}else if(req.carStatus==2){
where.and("carStatus","=",true);
}
//车牌号
if(Strings.isNotBlank(req.carLicence)){
where.and("carLicence","like","%"+req.carLicence+"%");
}
//车主手机号
if(Strings.isNotBlank(req.cellPhone)){
where.and("cellPhone","like","%"+req.cellPhone+"%");
}
//车主姓名
if(Strings.isNotBlank(req.realName)){
where.and("realName","like","%"+req.realName+"%");
}
//保养到期
if(req.carNextTime!=null){
where.and("carNextTime","<=",req.carNextTime);
}
//保险到期
if(req.insuranceEndDate!=null){
where.and("insuranceEndDate","<=",req.insuranceEndDate);
}
//年检到期
if(req.checkEndDate!=null){
where.and("checkEndDate","<=",req.checkEndDate);
}
//根据字段名字排序
if (req.sortType == null) {
where.orderBy("createTime", "desc");
} else {
where.orderBy("convert (" + req.sortType.getName() + " using gbk)",
"" + req.sortType.getSorts() + "");
}
List <FacManageCarView> fmcvs = dao.query(FacManageCarView.class, where,pager);
int count =dao.count(FacManageCarView.class,where);
if(fmcvs==null||fmcvs.size()==0){
resp.requestCode=-1;
return resp;
}
List<FacManageCarEntity> fmces = new ArrayList<FacManageCarEntity>();
List<Dictionary> dcs = dao.query(Dictionary.class,Cnd.where("type","=","car_state"));
for(int i=0;i<fmcvs.size();i++){
FacManageCarEntity fmce = new FacManageCarEntity();
fmce.SNumber = (req.page-1)*20+i+1;//序号赋值
int code;
if(fmcvs.get(i).isCarStatus()==false){
code = 1;
}else{
code = 2;
}
for(int j=0;j<dcs.size();j++){
if(dcs.get(j).getVal().equals(""+code)){
fmce.carStatusDesc = dcs.get(j).getItems();//车辆状态描述
break;
}
}
fmce.fmcv = fmcvs.get(i);
fmces.add(fmce);
}
pager.setRecordCount(count);
resp.pageCount = pager.getPageCount();
resp.count = count;
resp.fmces = fmces;
return resp;
}
@At
public Object fetchFacManageCar(FacManageCarReq req){
FacManageCarResp resp = new FacManageCarResp();
//车辆id
if(req.Id<=0){
resp.requestCode=-1;
return resp;
}
FacManageCarView fmcv = dao.fetch(FacManageCarView.class,Cnd.where("id","=",req.Id));
if(fmcv==null){
resp.requestCode=-1;
return resp;
}
FacManageCarEntity fmce = new FacManageCarEntity();
fmce.fmcv = fmcv;
int code;
if(fmcv.isCarStatus()==false){
code = 1;
}else{
code = 2;
}
Dictionary dc = dao.fetch(Dictionary.class,Cnd.where("type","=","car_state").and("val","=",code));
fmce.carStatusDesc = dc.getItems();//车辆使用状态描述
resp.requestCode=0;
resp.fmce = fmce;
return resp;
}
@At
public Object queryFacManageRecord(FacManageCarReq req){
FacManageCarResp resp = new FacManageCarResp();
Pager pager = dao.createPager(req.page, 20);
if(req.carId<=0){
resp.requestCode = -1;
return resp;
}
Cnd where = Cnd.where("carId","=",req.carId);
if (req.sortType == null) {
where.orderBy("createTime", "desc");
} else {
where.orderBy("convert (" + req.sortType.getName() + " using gbk)",
"" + req.sortType.getSorts() + "");
}
List<RepairRecord> rrs = dao.query(RepairRecord.class,where,pager);
if(rrs==null||rrs.size()==0){
resp.requestCode =-1;
return resp;
}
int count = dao.count(RepairRecord.class,where);
pager.setRecordCount(count);
List<FacManageRepairRecordEntity> fmrres = new ArrayList<FacManageRepairRecordEntity>();
List<Dictionary> dr = dao.query(Dictionary.class,Cnd.where("type","=","repairrecord_type"));
for(int i=0;i<rrs.size();i++){
FacManageRepairRecordEntity fmrre = new FacManageRepairRecordEntity();
fmrre.rr = rrs.get(i);
fmrre.SNmuber = (req.page-1)*20+i+1;
for(Dictionary d : dr){
if(d.getVal().equals(""+rrs.get(i).getType()+1)){
fmrre.typeDesc = d.getItems();//维修保养记录类型描述
}
}
fmrres.add(fmrre);
}
resp.requestCode=0;
resp.fmrres = fmrres;
resp.count = count;
resp.pageCount = pager.getPageCount();
return resp;
}
/**
* 维修保养项目接口
* @author fjd
* @param req
* @return
*/
@At
public Object queryFacManageOrderItme(FacManageOrderItmeReq req){
FacManageOrderItmeResp resp = new FacManageOrderItmeResp();
if(req.id<=0){
resp.requestCode = -1;
return resp;
}
List<OrderItme> ois = dao.query(OrderItme.class, Cnd.where("rrId","=",req.id));
if(ois==null||ois.size()==0){
resp.requestCode = -1;
return resp;
}
int count = dao.count(OrderItme.class,Cnd.where("rrId","=",req.id));
List<FacManageOrderItmeEntity> fmoies = new ArrayList<FacManageOrderItmeEntity>();
List<Dictionary> dlist = dao.query(Dictionary.class,Cnd.where("type","=","repairrecord_type"));
for(int i=0;i<ois.size();i++){
FacManageOrderItmeEntity fmoie = new FacManageOrderItmeEntity();
fmoie.oi = ois.get(i);
fmoie.SNumber = (req.page-1)*20+i+1;//序号
for(Dictionary d : dlist){
if(d.getVal().equals(""+ois.get(i).getType())){
fmoie.typeDesc = d.getItems();//维修保养记录描述
}
}
fmoies.add(fmoie);
}
resp.count = count;
resp.fmoies = fmoies;
return resp;
}
}
返回json格式 不忽略null字段的更多相关文章
- webapi返回json格式优化 转载https://www.cnblogs.com/GarsonZhang/p/5322747.html
一.设置webapi返回json格式 在App_Start下的WebApiConfig的注册函数Register中添加下面这代码 1 config.Formatters.Remove(config.F ...
- WebApi返回Json格式字符串
WebApi返回json格式字符串, 在网上能找到好几种方法, 其中有三种普遍的方法, 但是感觉都不怎么好. 先贴一下, 网上给的常用方法吧. 方法一:(改配置法) 找到Global.asax文件,在 ...
- webapi返回json格式优化
一.设置webapi返回json格式 在App_Start下的WebApiConfig的注册函数Register中添加下面这代码 config.Formatters.Remove(config.For ...
- ajax访问服务器返回json格式
使用ajax访问服务器返回多条数据,比如返回一个表中的所有数据,页面该如何处理呢?如何获取数据呢?一直不会用ajax返回json格式,今天研究了下,分享给大家~ 首先需要引用服务,点击项目右键,添加引 ...
- SSH返回Json格式的数据
在开发中我们经常遇到客户端和后台数据的交互,使用比较多的就是json格式了.在这里以简单的Demo总结两种ssh返回Json格式的数据 项目目录如下 主要是看 上图选择的部分 WebRoot里面就 ...
- springmvc通过ajax异步请求返回json格式数据
jsp 首先创建index.jsp页面 <script type="text/javascript"> $(function () { $("#usernam ...
- (转)WebApi返回Json格式字符串
原文地址:https://www.cnblogs.com/elvinle/p/6252065.html WebApi返回json格式字符串, 在网上能找到好几种方法, 其中有三种普遍的方法, 但是感觉 ...
- 返回json格式数据乱码
本文为博主原创,未经允许不得转载: 原本返回json格式数据的代码: @ResponseBody @RequestMapping(value = "getListByTime", ...
- 3.自定义返回json格式的数据给前台(自定义Controller类中的Json方法)
在mvc的项目中,我们前台做一些操作时,后台要返回一些结果给前台,这个时候我们就需要有一个状态来标识到底是什么类型的错误, 例如: 执行删除的时候,如果操作成功(1行受影响),我们需要返回状态为1并输 ...
随机推荐
- 工具类_GsonUtils
import java.lang.reflect.Type; import com.google.gson.Gson; /** * Gson工具类 2015-02-01<br/> * 1, ...
- Tcpdump命令抓包详细分析
1 起因 前段时间,一直在调线上的一个问题:线上应用接受POST请求,请求body中的参数获取不全,存在丢失的状况.这个问题是偶发性的,大概发生的几率为5%-10%左右,这个概率已经相当高了.在排查问 ...
- Gone Fishing
原题网址 代码已经写出来了,自己测试的时候没有问题,提交上去之后反馈了我一个Runtime error 一口老血啊! 找了半天还是没找到可能越界啊啥的地方 import java.util.Scan ...
- JavaSE---Collections
1.简介: Collections是一个工具类 1.1 排序 a,正序 sort是其静态方法,有2种参数形式: public static <T extends Comparable<? ...
- [转]Passing data between pages in JQuery Mobile mobile.changePage
本文转自:http://ramkulkarni.com/blog/passing-data-between-pages-in-jquery-mobile/ I am working on a JQue ...
- c3p0 数据连接池 流行开源
注意事项:配置文件规定命名,不能更改 c3p0-config <?xml version="1.0" encoding="UTF-8"?>< ...
- Node调试之node-inspect工具
1.全局安装node-inspect模块: npm install -g node-inspect 2.通过谷歌浏览器打开:chrome://flags/#enable-devtools-experi ...
- css实现高度垂直居中
1:单行文字垂直居中: 如果一个容器中只有一行文字的话,定义height(高度)和 line-height(行高)相等即可. 如:<div style="height:25px;lin ...
- mysql时间戳
select unix_timestamp('2013-01-01 10:10:10'); , '%Y-%m-%d %H:%i:%S' ) date_format(date,'%Y-%m-%d') - ...
- 揭秘企业级web负载均衡完美架构
相信很多朋友对企业级的负载均衡高可用实例非常感兴趣,此篇文章根据成熟的线上环境而写,旨在帮助大家迅速架构一个企业级的负载均衡高可用的web环境. 此系统架构仅映射内网VIP的80及443端口于外网的J ...