mybatis xml注釋sql的注意事項及說明
mybatis xml注釋sql的注意事項
說明:在mybatis 的sql里不是不能寫注釋,而是注釋不能有#{},mybatis仍舊會把#{}算成一個帶注入的參數(shù)
如代碼段2所示,mysql數(shù)據(jù)庫更換為oracle數(shù)據(jù)庫時,#{date}需要明確jdbcType,而該代碼段中僅將適用于mysql的sql注釋,依舊會報同樣的錯,最好是將注釋的sql刪除。
<select id="slectSlagsteelRatioByDate" resultType="java.lang.Double">
-- select slagsteel_ratio FROM process_history WHERE r furnace_num = #{furnaceNum}
-- ORDER BY real_time DESC limit 0,1
select slagsteel_ratio FROM(
select slagsteel_ratio FROM process_history WHERE real_time <= #{date,jdbcType=TIMESTAMP}
ORDER BY real_time DESC ) WHERE ROWNUM = 1
</select>注意事項
1、where語句等用到大于小于等符號時候,需要使用 <![CDATA[ > ]]>或者 <![CDATA[ < ]]>進行識別。
2、如果sql文中有動態(tài)sql文標簽,比如sql文,此時wwww為傳遞的參數(shù),不需用#{wwww }取值,直接使用即可。
3、如果超過一個參數(shù),需要在接口方法的每個參數(shù)定義時候使用@Param注解。
4、order by語句可以使用動態(tài)sql
ORDER BY eeee ORDER BY rrrrrr
5、SELECT
CASE
WHEN 條件1 THEN 字段1WHEN 條件2 THEN 字段2
ELSE 字段3
END
FROM.....只要滿足一個WHEN,后面的WHEN就不會執(zhí)行了,跳出CASE WHEN 語句
mybatis xml 注釋問題
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘mybatis_plus_first’, mode=IN, javaType=long, jdbcType=null, numericScale=null, resultMapId=‘null’, jdbcTypeName=‘null’, expression=‘null’}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).] with root cause
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
解決辦法
在mybatis里面注釋語句的時候,不要用–,用 <!- -需要注釋的內(nèi)容–>。
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
springboot 中 inputStream 神秘消失之謎(終破)
這篇文章主要介紹了springboot 中 inputStream 神秘消失之謎,為了能夠把這個問題說明,我們首先需要從簡單的http調用說起,通過設置body等一些操作,具體實現(xiàn)代碼跟隨小編一起看看吧2021-08-08
SpringBoot+TestNG單元測試的實現(xiàn)
本文主要介紹了SpringBoot+TestNG單元測試的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-07-07

