java.lang.NumberFormatException: For input string: "F"

In the implementation of sql by myBatis, error: java.lang.NumberFormatException: For input string: "F"

xml in sql says:

                    <if test="myKey == 'P' ">
                        and `Field1` = #{fieldname}
                    </if>

Where fieldname value F, did not understand will be reported NumberFormatException, obviously character, after a step by step debugging code to:

\.m2\repository\org\mybatis\mybatis\3.5.2\mybatis-3.5.2.jar!\org\apache\ibatis\ognl\ASTNotEq.class

The error code (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 values ​​were below:

 

 

 V2 values ​​become P, to give v2 of type: 

 

 

 Did not understand, behind try <if test = "myKey == 'P'"> adjusted: <if test = "myKey == 'PP'"> added an extra P

Then type v2 on a String, with an estimated MyBatis if found to be a single character, are unified treatment for Character, try to adjust to: <if test = "myKey ==" P ""> double quotes instead of single quotes (or an escape character), not OK

Try to convert single and double quotation marks (test in double quotes outsourcing will be changed to single quotes, P characters adjusted to double quotes): 

 

                    <if test='myKey == "P" '>
                        and `Field1` = #{fieldname}
                    </if>

 

Try and functioning properly

Guess you like

Origin www.cnblogs.com/Wicher-lsl/p/11535942.html