Mybatis之程序中执行和单独执行同一条SQL出现结果不一致(部分数据没有查询出来)

1.mapper文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.enci.isms.support.service.cus.dao.IsmsCusUserInfoMapper">
    <resultMap id="BaseResultMap" type="com.enci.isms.support.service.cus.model.IsmsCusUserInfo">
        <id column="ID" property="id" jdbcType="DECIMAL" />
        <result column="OPEN_ID" property="openId" jdbcType="VARCHAR" />
        <result column="MOBILE_PHONE" property="mobilePhone" jdbcType="VARCHAR" />
        <result column="REAL_NAME" property="realName" jdbcType="VARCHAR" />
        <result column="USER_EMAIL" property="userEmail" jdbcType="VARCHAR" />
        <result column="PASSWORD" property="password" jdbcType="VARCHAR" />
        <result column="TYPE" property="type" jdbcType="VARCHAR" />
        <result column="JOB_NUMBER" property="jobNumber" jdbcType="VARCHAR" />
        <result column="USER_LEVEL" property="userLevel" jdbcType="VARCHAR" />
        <result column="STATUS" property="status" jdbcType="VARCHAR" />
        <result column="PARENT_PARENT_ID" property="parentParentId" jdbcType="DECIMAL" />
        <result column="PARENT_ID" property="parentId" jdbcType="DECIMAL" />
        <result column="TEAM_ID" property="teamId" jdbcType="DECIMAL" />
        <result column="IDENTIFY_NUMBER" property="identifyNumber" jdbcType="VARCHAR" />
        <result column="IS_AUTHORISED" property="isAuthorised" jdbcType="VARCHAR" />
        <result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" />
        <result column="LAST_OPERATOR_TIME" property="lastOperatorTime" jdbcType="TIMESTAMP" />
        <result column="SALT" property="salt" jdbcType="VARCHAR" />
        <result column="REGISTER_STATUS" property="registerStatus" jdbcType="VARCHAR" />
        <result column="REGIST_TIME" property="registTime" jdbcType="TIMESTAMP" />
        <result column="AUTHENT_TIME" property="authentTime" jdbcType="TIMESTAMP" />
    </resultMap>
<sql id="Base_Column_List" >
ID,OPEN_ID,MOBILE_PHONE,REAL_NAME,USER_EMAIL,PASSWORD,TYPE,JOB_NUMBER,USER_LEVEL,STATUS,
PARENT_PARENT_ID,PARENT_ID,TEAM_ID,IDENTIFY_NUMBER,IS_AUTHORISED,REGISTER_STATUS,
CREATE_TIME,LAST_OPERATOR_TIME,SALT,REGIST_TIME,AUTHENT_TIME
</sql>
  <select id="getDtoByPrimaryKey" resultType="com.enci.isms.support.service.cus.dto.IsmsCusUserDto">
SELECT 
<include refid="Base_Column_List" />
FROM
ISMS_CUS_USER_INFO cus
WHERE CUS."ID" = #{id}
  </select>
</mapper>

2.dto实体部分如下

public class IsmsCusUserDto implements Serializable {


    private static final long serialVersionUID = 466674771467600004L;
    
    private Long id;
    private String openId;
    private String mobilePhone;
    private String realName;
    private String userEmail;
    private String password;
    private String type;
    private String jobNumber;
    private String userLevel;
    private String status;
    private Long parentParentId;
    private Long parentId;
    private Long teamId;
    private String identifyNumber;
    private String isAuthorised;
    private Date createTime;
    private Date lastOperatorTime;
    private Long waitingAuditScore;
    private Long settlementScore;
    private Long exchangeScore;
    private Long freezeScore;}

3.就这样的在程序中执行到这个 sql的时候 查询出来的这个对象信息部分字段属性都是赋值null,但是把这条sql单独取出在数据库执行可以查询出一条完整信息的数据,百思不得其解,百度也没有门路。

4.通过对查询结果进行分析发现带有下划线的字段对应属性都没有查询出属性数据,所以问题就在resultType   的dto属性和要查询的结果集 <include refid="Base_Column_List" />   属性和查询字段名不是匹配的 ,要么给查询的字段名启别名,要么就把resultType  换成  resultMap="BaseResultMap" 即可

如有披露或问题欢迎留言或者入群探讨

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 鲸 设计师:meimeiellie 返回首页