<正则吃饺子> :关于mybatis中使用的问题(一)
2024-09-06 23:39:24
在公司项目开始之前,根据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;
搜索;
淘淘商城的视频;
最新文章
- 2016年8月ios面试问题总结
- 最近Google经常打不开?
- C++ STL,list vector区别
- [java基础]分支结构(2)
- ActiveReports 报表应用教程 (6)---分组报表
- Linux cscope命令
- Developing a plugin framework in ASP.NET MVC with medium trust
- C#编写windows服务程序
- SLua
- 如何启用Service,如何停用Service
- KAFKA分布式消息系统[转]
- Java错误提示is not an enclosing class
- 数据结构与算法(十):红黑树与TreeMap详细解析
- Java笔记(day9~day10)
- 可编程并行接口8255A详解
- [转]Docker(三):Dockerfile 命令详解
- android展示注册进度效果源码
- L3-021 神坛 (30 分)
- Codeforces 911D. Inversion Counting (数学、思维)
- makefile使用.lds链接脚本以及 $@ ,$^, $,<; 解析【转】