返回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并输 ...
随机推荐
- linux 远程装机
首先,服务器配置dhcp 关闭火墙yum install dhcp -ycd /etc/dhcpcp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ...
- caffe 日志保存以及matlab绘制方法(windows以及ubuntu下)
caffe 用matlab解析日志画loss和accuracy clc; clear; % load the log file of caffe model fid = fopen('log-prev ...
- 多线程读写shared_ptrshared_ptr要加锁分析!学习笔记
(shared_ptr)的引用计数本身是安全且无锁的,但对象的读写则不是,“因为 shared_ptr 有两个数据成员,读写操作不能原子化".使得多线程读写同一个 shared_ptr 对 ...
- JavaSE---线程同步
1.当多个线程同时访问同一个数据时,容易出现线程安全问题,必须进行线程同步: 2.解决方案: 1.1 Java的多线程引入了 同步监视器 ,使用同步监视器的通用方法就是 同步代码块 //线程开始 ...
- Readthedocs+Github搭建文档
一.文档撰写前提 环境部署: > git clone https://github.com/toooney/demo-readthedocs.git > pip install sphin ...
- #define\const\inline的区别与联系
总结: const用于代替#define一个固定的值,inline用于代替#define一个函数.是#define的升级版,为了消除#define的缺陷. 参考内容:http://www.cnblog ...
- 开发安全的 API 所需要核对的清单
开发安全的 API 所需要核对的清单 以下是当你在设计, 测试以及发布你的 API 的时候所需要核对的重要安全措施. 身份认证 不要使用 Basic Auth 使用标准的认证协议 (如 JWT, OA ...
- js 去掉字符串前后空格5种方法
第一种:循环检查替换 //供使用者调用 function trim(s){ return trimRight(trimLeft(s)); } //去掉左边的空白 function trimLeft(s ...
- c++ 控制台输入参数
#include <iostream>#include <string> using namespace std; int main(int argc,char **argv) ...
- C#使用进度条,并用线程模拟真实数据 ProgressBar用法(转)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...