<正则吃饺子> :关于mybatis中使用的问题(一)

在公司项目开始之前,根据springboot 、mybatis、Swagger2 整合了一个demo,在测试时候,遇到的问题,简单记录。之前在使用mybatis时候,没有注意到这一点。

1、错误:There is no getter for property named 'classid' in 'class java.lang.String'

2、错误场景:再代码传递参数时候,只是传递了 字符串 类型的,但是在 mapper.xml 文件中使用了类似这样的判断

如下:

注意:这种写法本身是没有问题的
<select id="getStudentById" resultMap="selectAllStudentMap" parameterType="java.lang.String">
        select * from t_student
        <where>
            <if test="id != null and id != '' ">
                id = #{id,jdbcType=VARCHAR }
            </if>
        </where>
    </select>

因为在 dao ,service层中,传递的是对象student,<if>标签的判断是完全可以的。

但是为了测试单个字符串传递参数的情况(参数不封装到map或者对象中),这种写法就会报错,如上的错误。

解决方式,如下,使用了 “_parameter” 这个标识,如下:

<select id="getStudentById2" resultMap="selectAllStudentMap" parameterType="java.lang.String">
        select * from t_student
        <where>
            <if test="_parameter != null and _parameter != '' ">
                id = #{id,jdbcType=VARCHAR }
            </if>
        </where>
    </select>

解决方式2::去掉<if>标签,因为这是给bean进行判断的,如下:

去掉<if>标签
<select id="getStudentById2" resultMap="selectAllStudentMap" parameterType="java.lang.String">
        select * from t_student
        <where>
            id = #{id,jdbcType=VARCHAR }
        </where>
    </select>

问题解决,可以使用  Swagger2 生成的 api文档页面进行测试了。

3、参考的文档(一个问题的讨论)http://bbs.csdn.net/topics/350253850?page=1

4、插一句嘴吧

       springboot使用起来很清爽;

       zookeeper和dubbo;

         springcloud;

         搜索;

         淘淘商城的视频;  

  

        

原文地址:https://www.cnblogs.com/zhengzeze/p/7511026.html