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})
相關文章
相關標籤/搜索