MyBatis SQL不能使用运算符的解决方案

方法一:使用xml转义字符

如:

select phone, user_head, nickname, real_name, certificate_type, certificate_number, email, birthday_date,
(year(now())-year(birthday_date)-1) + (DATE_FORMAT(birthday_date, '%m%d') <= DATE_FORMAT(now(),'%m%d')) as age,heigth, weight, profession from yxs_user_info
where user_uuid = (select uuid from yxs_user_login_info from uuid2=#{uuid2})

 

select phone, user_head, nickname, real_name, certificate_type, certificate_number, email, birthday_date,<![CDATA[(year(now())-year(birthday_date)-1) + (DATE_FORMAT(birthday_date, '%m%d') &lt;= DATE_FORMAT(now(),'%m%d')) as age]]>,heigth, weight, profession 
from yxs_user_info  where user_uuid = (select uuid from yxs_user_login_info from uuid2=#{uuid2})

附:XML转义字符

&lt;

<

小于号

&gt;

>

大于号

&amp;

&

&apos;

单引号

&quot;

"

双引号

方法二: 使用<![CDATA[运算内容]]>

因为这个是xml格式的,所以不允许出现类似“>”这样的字符,但是都可以使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析。

select phone, user_head, nickname, real_name, certificate_type, certificate_number, email, birthday_date,<![CDATA[(year(now())-year(birthday_date)-1) + (DATE_FORMAT(birthday_date, '%m%d') <= DATE_FORMAT(now(),'%m%d')) as age]]>,heigth, weight, profession from yxs_user_info  where user_uuid = (select uuid from yxs_user_login_info from uuid2=#{uuid2})

 

转载于:https://my.oschina.net/u/2289161/blog/838226

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值