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

方法一:使用xml转义字符

如:ui

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转义字符spa

&lt;code

<xml

小于号io

&gt;table

>email

大于号date

&amp;select

&方法

&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})
相关文章
相关标签/搜索