为了账号安全,请及时绑定邮箱和手机立即绑定

MyBatis在注解上使用动态SQL(@select使用if)

MyBatis在注解上使用动态SQL(@select使用if)

精慕HU 2019-02-03 23:09:41
@Select({            "<script>",            "select * from user_info where 1=1",            "<when test='name!=null and name!='' '>",            "and name = #{name}",            "</when>",            "</script>"})判断条件是name不为空并且不等于''(空字符串)这该怎么写呢?上面这个写法是错的
查看完整描述

1 回答

?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

这样试试

@Select("<script>" +    "select * from user_info where 1=1" +        "<where>" +            "<if test=test='name!=null and name!=''>" +                "and name = #{name}"+            "</if>" +        "</script>")


查看完整回答
反对 回复 2019-02-03
  • 1 回答
  • 0 关注
  • 586 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

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

帮助反馈 APP下载

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

公众号

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