mybatis 报错:Cause: java.lang.NumberFormatException: For input string: "java"

发布时间 2023-08-23 22:28:45作者: 三刀流呀

1、所错图示:

2、为什么包这样的错误?

在if查询条件的逻辑没有错,其实在代码转换解析时,自动转换类型了,是代码在转换解析时异常。

<!--where 与if配合使用-->
<select id="selectBlogIfWhere" resultType="blog" parameterType="blog">
    <include refid="commBlog"></include>
    <where>
        <if test="title !=null and title!=' '"><!--这里报的错:java.lang.NumberFormatException-->
            and title=#{title}
        </if>
        <if test="author !=null and author!=' '">
            and author like concat('%',#{author},'%')
        </if>
        <if test="views !=null">
            and views=#{views}
        </if>
    </where>
</select>

3.解决办法:不让mybatis自动解析转换

<if test='title !=null and title!=" "'><!--单双引号互换位置-->
<if test="title !=null and title!=' '.toString()"><!--添加toString()-->