
为需求相关的页面定义自己的vo,在vo中只定义前端用到的字段。而不是像第一种方式一样vo中一层一层的嵌套model。然后使用sql语句进行表关联,查询用到的字段。组装为vo直接返回
<resultMap id="checkAccountReturn" type="javautilHashMap">
<id property="account_id" column="account_id" />
<result property="sub_account_id" column="sub_account_id"/>
<result property="status" column="status"/>
<result property="account_status" column="account_status"/>
<result property="total_count" column="total_count"/>
<result property="sms_sign" column="sms_sign"/>
</resultMap>
<select id="checkSub_account" resultMap="checkAccountReturn">
SELECT account_id,sub_account_id,status,account_status,total_count,sms_sign
FROM sub_account
<where>
<if test="account_id!=null">
account_id=#{account_id}
</if>
<if test="sub_account_id!=null">
and sub_account_id = #{sub_account_id} and status=1 and total_count!=0 and account_status=1
</if>
</where>
</select>mybatis的mapperxml里通过判断值来选择不同的语句,xml文件部分内容如下:
项目跑起来后发现两个都没生效,经过资料查找,最后发现由于MyBatis是使用的OGNL表达式,所以单个的字符要写到双引号里面才行,改为<if test=' contain == "0" ' >或者改为<if test=" contain == '0'toString() ">,问题解决。
完全可以
<!-- 根据条件模糊查询 --><select id="findTrackerByPuzzy" parameterType="javautilMap"
resultMap="trackerDevice_resultMap">
select
d,ureal_name as u_name
from tb_tracker_device d
left outer join
tb_user u
on uid=duser_id
<where>
<if test="condition !=null and condition !=''">
(dtracker_id like
CONCAT('%',#{condition},'%')
or
dnumber like
CONCAT('%',#{condition},'%')
or
dimei like
CONCAT('%',#{condition},'%')
or
dsim like
CONCAT('%',#{condition},'%')
or
dtelephone like
CONCAT('%',#{condition},'%')
or
(ureal_name like
CONCAT('%',#{condition},'%')
<if test="channel !=null">
and uchannel=#{channel}
</if>
))
</if>
<if test="channel !=null">
and dchannel=#{channel}
</if>
</where>
order by dsync_time desc
</select>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)