请问xml的if test如何转换成mysql语句?

请问xml的if test如何转换成mysql语句?

1
2
3
4
5
6
7
8
9
10
<select id="selectByDepartmentAndPost" resultMap="employee">
    select e.*,d.sn dsn,d.name dname from employee e left join department d on d.sn=e.department_sn
    where e.sn is not NULL
    <if test="dsn!=null">
        and e.department_sn=#{dsn}
    </if>
    <if test="post!=null">
        and e.post=#{post}
    </if>
</select>

这个该如何转换成mysql语句?

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学是不理解sql的动态拼接么?if test的意思是,如果dsn的值不为null,我们就在查询语句中增加and e.department_sn=#{dsn}的条件,转换成sql语句是下面这个样子的,如果有明白的地方可以继续提问,祝学习愉快~

1
select e.*,d.sn dsn,d.name dname from employee e left join department d on d.sn=e.department_sn  where e.sn is not NULL and e.department_sn=#{dsn}


问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
SSM主流框架入门与综合项目实战2018版
  • 参与学习           人
  • 提交作业       205    份
  • 解答问题       4317    个

Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码