因为自己马大哈,经常犯这个错误,原以为是拷贝的代码问题,最后发现是自己的遗漏问题!
看代码,先看不生效的
<resultMap type="Price" id="PriceResult">
<id property="priceId" column="price_id" />
<result property="shopId" column="shop_id" />
<result property="projectId" column="project_id" />
<result property="levelId" column="level_id" />
<result property="unitId" column="unit_id" />
<result property="status" column="status" />
<result property="orderType" column="order_type" />
<result property="priceSort" column="price_sort" />
<result property="amount" column="amount" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<association property="shopInfo" javaType="Configbase" resultMap="shopInfoResult" />
<association property="projectInfo" javaType="Project" resultMap="projectInfoResult" />
<association property="levelInfo" javaType="Level" resultMap="levelInfoResult" />
<association property="unitInfo" javaType="Unit" resultMap="unitInfoResult" />
</resultMap>
<resultMap id="shopInfoResult" type="Configbase">
<id property="shopId" column="shop_id" />
<result property="shopName" column="shop_name" />
</resultMap>
<resultMap id="projectInfoResult" type="Project">
<id property="projectId" column="project_id" />
<result property="projectTitle" column="project_title" />
</resultMap>
<resultMap id="levelInfoResult" type="Level">
<id property="levelId" column="level_id" />
<result property="levelTitle" column="level_title" />
</resultMap>
<resultMap id="unitInfoResult" type="Unit">
<id property="unitId" column="unit_id" />
<result property="unitTitle" column="unit_title" />
</resultMap>
<sql id="selectPriceVo">
select g.price_id, g.shop_id, g.project_id, g.level_id, g.unit_id, g.order_type, g.status, g.price_sort, g.amount,
g.del_flag, g.create_by, g.update_by, g.create_time, g.update_time, g.remark,
s.shop_name,
p.project_title,
l.level_title,
u.unit_title
from tb_market_price g
left join tb_shop_config_base s on s.shop_id = g.shop_id
left join tb_market_project p on p.project_id = g.project_id
left join tb_market_level l on l.level_id = g.level_id
left join tb_market_unit u on u.unit_id = g.unit_id
</sql>
<select id="selectPriceList" parameterType="Price" resultMap="PriceResult">
select g.price_id, g.shop_id, g.project_id, g.level_id, g.unit_id, g.order_type, g.status, g.price_sort, g.amount,
g.del_flag, g.create_by, g.update_by, g.create_time, g.update_time, g.remark,
s.shop_name
from tb_market_price g
left join tb_shop_config_base s on s.shop_id = g.shop_id
where g.del_flag = '0' and 1 = 1
<if test="priceId != null and priceId != ''">
AND g.price_id = #{priceId}
</if>
<if test="shopId != null and shopId != ''">
AND g.shop_id = #{shopId}
</if>
<if test="projectId != null and projectId != ''">
AND g.project_id = #{projectId}
</if>
<if test="levelId != null and levelId != ''">
AND g.level_id = #{levelId}
</if>
<if test="unitId != null and unitId != ''">
AND g.unit_id = #{unitId}
</if>
<if test="status != null and status != ''">
AND g.status = #{status}
</if>
<if test="orderType != null and orderType != ''">
AND g.order_type = #{orderType}
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(g.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(g.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
再看生效的
<resultMap type="Price" id="PriceResult">
<id property="priceId" column="price_id" />
<result property="shopId" column="shop_id" />
<result property="projectId" column="project_id" />
<result property="levelId" column="level_id" />
<result property="unitId" column="unit_id" />
<result property="status" column="status" />
<result property="orderType" column="order_type" />
<result property="priceSort" column="price_sort" />
<result property="amount" column="amount" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<association property="shopInfo" javaType="Configbase" resultMap="shopInfoResult" />
<association property="projectInfo" javaType="Project" resultMap="projectInfoResult" />
<association property="levelInfo" javaType="Level" resultMap="levelInfoResult" />
<association property="unitInfo" javaType="Unit" resultMap="unitInfoResult" />
</resultMap>
<resultMap id="shopInfoResult" type="Configbase">
<id property="shopId" column="shop_id" />
<result property="shopName" column="shop_name" />
</resultMap>
<resultMap id="projectInfoResult" type="Project">
<id property="projectId" column="project_id" />
<result property="projectTitle" column="project_title" />
</resultMap>
<resultMap id="levelInfoResult" type="Level">
<id property="levelId" column="level_id" />
<result property="levelTitle" column="level_title" />
</resultMap>
<resultMap id="unitInfoResult" type="Unit">
<id property="unitId" column="unit_id" />
<result property="unitTitle" column="unit_title" />
</resultMap>
<sql id="selectPriceVo">
select g.price_id, g.shop_id, g.project_id, g.level_id, g.unit_id, g.order_type, g.status, g.price_sort, g.amount,
g.del_flag, g.create_by, g.update_by, g.create_time, g.update_time, g.remark,
s.shop_name,
p.project_title,
l.level_title,
u.unit_title
from tb_market_price g
left join tb_shop_config_base s on s.shop_id = g.shop_id
left join tb_market_project p on p.project_id = g.project_id
left join tb_market_level l on l.level_id = g.level_id
left join tb_market_unit u on u.unit_id = g.unit_id
</sql>
<select id="selectPriceList" parameterType="Price" resultMap="PriceResult">
<include refid="selectPriceVo"/>
where g.del_flag = '0' and 1 = 1
<if test="priceId != null and priceId != ''">
AND g.price_id = #{priceId}
</if>
<if test="shopId != null and shopId != ''">
AND g.shop_id = #{shopId}
</if>
<if test="projectId != null and projectId != ''">
AND g.project_id = #{projectId}
</if>
<if test="levelId != null and levelId != ''">
AND g.level_id = #{levelId}
</if>
<if test="unitId != null and unitId != ''">
AND g.unit_id = #{unitId}
</if>
<if test="status != null and status != ''">
AND g.status = #{status}
</if>
<if test="orderType != null and orderType != ''">
AND g.order_type = #{orderType}
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(g.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(g.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
原因是因为只写了查询单个的以下这段,而查列表的时候没有
select g.price_id, g.shop_id, g.project_id, g.level_id, g.unit_id, g.order_type, g.status, g.price_sort, g.amount,
g.del_flag, g.create_by, g.update_by, g.create_time, g.update_time, g.remark,
s.shop_name,
p.project_title,
l.level_title,
u.unit_title
from tb_market_price g
left join tb_shop_config_base s on s.shop_id = g.shop_id
left join tb_market_project p on p.project_id = g.project_id
left join tb_market_level l on l.level_id = g.level_id
left join tb_market_unit u on u.unit_id = g.unit_id
核心代码,修改下即可
<include refid="selectPriceVo"/>
仅是个人常犯错误,记录下