发生背景
采用mybatisX-Generator自动生成的entity和maper(com.baomidou.mybatisplus.core.mapper),自己编写的查询和mapper自带的查询方法都无法将部分字段查询出来,相同的sql语句在数据库却可以查询出来。
问题相关代码
<?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.cy.store.mapper.AddressMapper">
<resultMap id="BaseResultMap" type="com.cy.store.entity.Address">
<id property="aid" column="aid" jdbcType="INTEGER"/>
<result property="province_name" column="province_name" jdbcType="VARCHAR"/>
<result property="province_code" column="province_code" jdbcType="CHAR"/>
<result property="city_name" column="city_name" jdbcType="VARCHAR"/>
<result property="city_code" column="city_code" jdbcType="CHAR"/>
<result property="area_name" column="area_name" jdbcType="VARCHAR"/>
<result property="area_code" column="area_code" jdbcType="CHAR"/>
...............(省略其他属性)
</resultMap>
<select id="findByAid" resultType="com.cy.store.entity.Address">
select * from t_address where aid=#{aid}
</select>
</mapper>
//mapper
package com.cy.store.mapper;
import com.cy.store.entity.Address;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.Date;
import java.util.List;
public interface AddressMapper extends BaseMapper<Address> {
Address findByAid(Integer aid);
}
//测试
@Test
public void findByAid() {
Address result = addressMapper.findByAid(23);
System.out.println(result);