java.lang.NumberFormatException: For input string: F
在通過myBatis執行sql時,報錯:?java.lang.NumberFormatException: For input string: "F"
xml中sql內容為:
<if test="myKey == 'P' ">and `Field1` = #{fieldname}</if>其中 fieldname的值為 F, 沒明白會報?NumberFormatException, 明明是字符型,后一步步調試代碼到:
\.m2\repository\org\mybatis\mybatis\3.5.2\mybatis-3.5.2.jar!\org\apache\ibatis\ognl\ASTNotEq.class
報錯的代碼為(OgnlOps.equal):
protected Object getValueBody(OgnlContext context, Object source) throws OgnlException {Object v1 = this._children[0].getValue(context, source);Object v2 = this._children[1].getValue(context, source);return OgnlOps.equal(v1, v2) ? Boolean.FALSE : Boolean.TRUE;}v1,v2值分別為下圖:
?
?
?v2的值成了P,得到v2的類型為:?
?
?
?沒明白,后邊試著把?<if test="myKey == 'P' "> 調整為:??<if test="myKey == 'PP' "> 多加了一個P
這時v2的類型就為String了,估計MyBatis如果發現為單字符,都統一處理為了 Character, 試著調整為:?<if test="myKey == "P" "> 單引號改為雙引號(或加轉義符),都不行
試著轉換單雙引號為(test里外包的將雙引號改為單引號, P字符調整為雙引號):?
?
<if test='myKey == "P" '>and `Field1` = #{fieldname}</if>?
再試,功能正常
轉載于:https://www.cnblogs.com/Wicher-lsl/p/11535942.html
總結
以上是生活随笔為你收集整理的java.lang.NumberFormatException: For input string: F的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Repeater嵌套绑定
 - 下一篇: 【经典问题】maximum subset