查询结果封装为一个实体类,数据库可以查询到数据,返回结果一直为null,的处理方法

##1. Dao层

 ZzdacxFMJcl findCh(String ywtm) throws DaoException;
 @Override
    public ZzdacxFMJcl  findCh(String ywtm) throws DaoException {
        return  baseDao.findBySqlId("zzdacxMapper.findCh",ywtm,ZzdacxFMJcl.class);
    }

2.modal

@Data
public class ZzdacxFMJcl implements Serializable {

    /*业务条码*/
    private String ywtm;
    /*稽查档案大类名称*/
    private String jcDadlMc;

    /*稽查所属年度*/
    private String jcSsnd;

    /*稽查第几号*/
    private String jcDjh;

  }

3.mapper





-<mapper namespace="zzdacxMapper">

-<resultMap id="BaseType" type="com.digitalchina.business.model.ywda.zzdacx.ZzdacxFMJcl">

<id jdbcType="VARCHAR" property="ywtm" column="YWTM"/>

<result jdbcType="VARCHAR" property="jcDadlMc" column="JC_DADL_MC"/>

<result jdbcType="VARCHAR" property="jcSsnd" column="JC_SSND"/>

<result jdbcType="VARCHAR" property="jcDjh" column="JC_DJH"/>

resultMap>

<select id="findCh" resultMap="BaseType" parameterType="java.lang.String">
	SELECT 
		DISTINCT YWTM,JC_DADL_MC,JC_SSND,JC_DJH 
	FROM 
		YWDA_DY_FM_JCL 
	WHERE 
		YWTM = #{ywtm} 
select>

mapper>

注释:resultMap和resultType 不可以同时使用
造成此原因主要是实体类的属性字段和数据库表中的字段不一致造成,以上就是此解决方法.
4.Service

package com.digitalchina.business.service.ywda.zzdacx;

import com.digitalchina.business.dao.ywda.yxzlgl.IYxzlglDao;
import com.digitalchina.business.dao.ywda.zzdacx.IZzdacxDao;
import com.digitalchina.business.model.ywda.zzdacx.Zzdacx;
import com.digitalchina.business.model.ywda.zzdacx.ZzdacxFMJcl;
import com.digitalchina.business.model.ywda.zzdacx.ZzdacxRkwzBgqx;
import com.digitalchina.business.model.ywda.zzdagd.DyJnml;
import com.digitalchina.business.model.yxzlgl.Dalb;
import com.digitalchina.business.model.yxzlgl.YwdaDzdaJbxx;
import com.digitalchina.business.service.ywda.enums.DaztEnum;
import com.digitalchina.framework.base.exception.DaoException;
import com.digitalchina.framework.base.logger.ILogger;
import com.digitalchina.framework.base.logger.LoggerFactory;
import com.digitalchina.framework.constant.SrvConstants;
import com.digitalchina.framework.context.http.ServiceDataRequest;
import com.digitalchina.framework.context.http.ServiceDataResponse;
import com.digitalchina.framework.helper.json.JsonManager;
import com.digitalchina.utils.StringUtil;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ZzdacxService {

    private ILogger log = LoggerFactory.getLogger(ZzdacxService.class);

    @Autowired
    private IZzdacxDao zzdacxDao;

    public ServiceDataResponse queryZzdaXxList(ServiceDataRequest request) {
                String ywtm = zzdacx.getYwtm2();
                ZzdacxFMJcl zzdacxFMJcl  = zzdacxDao.findCh(ywtm);
                if(zzdacxFMJcl != null ){
                    String jcDadlMc = zzdacxFMJcl.getJcDadlMc();
                    System.err.println(jcDadlMc);
                    String jcSsnd = zzdacxFMJcl.getJcSsnd();
                    System.err.println(jcSsnd);
                    String jcDjh = zzdacxFMJcl.getJcDjh();
                    System.err.println(jcDjh);
                    zzdacx.setCh(new StringBuilder().append(jcDadlMc).append(jcSsnd).append("年度第").append(jcDjh).append("号").toString());
                    System.err.println(zzdacx.getCh());
                }else {
                    zzdacx.setCh("");
                }
        }
        return new ServiceDataResponse(SrvConstants.RTN_CODE_FAILURE, SrvConstants.RTN_FAIL, "");
    }
}

新手一枚,在成长的道路不断踩坑,如有不妥,欢迎指出!
生活不易,但也要长存理想!

你可能感兴趣的:(实体类返回值为null,java)