Mybaits学习过程中出现的错误
2016-04-10 14:32
495 查看
错误集合
1.Mybaits 中出现
Cause:org.apache.ibatis.reflection.ReflectionException:Error,instantiating,class Mybaits.haha.Teacher with invalid types () or values (). Cause: java.lang.NoSuchMethodException: Mybaits.haha.Teacher.<init>()
解决方法 : 是因为实体类中无无参构造函数
如: 建立SQL查询结果字段与实体属性的映射关系信息
示例1:通过setter构造领域模型
/**
* 必须提供一个无参数的构造函数
*/
2.用Mybaits 中查询,则生成的List结果会有问题
List查询的都是同一个类
例如:可见返回的结果中有 三个 一模一样的 Goods(id=1,且包含5个GoodsImg),
而我们期待的结果应该是 List{ Goods(id=1), Goods(id=2), Goods(id=3) }
解决方法 : resultMap
的 column=... 定义不能一样:
相同错误链接 :http://www.cnblogs.com/zemliu/archive/2013/08/16/3263053.html
3.没有在conf.xml中注册
Mapped Statements collection does not contain value for Mybaits.haha.ClassesMapper3.getUser
4.测试框架
在使用所有注释前必须使用@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境
5.一直困扰我两天的问题居然是因为@Autowired
是无法注入的static类型的数据
静态方法是属于类(class)的,普通方法才是属于实体对象(也就是New出来的对象)的,spring注入是在容器中实例化对象,所以不能使用静态方法
问题连接:http://blog.csdn.net/z69183787/article/details/38402007
Mybaits:
1.Mybaits 中出现
Cause:org.apache.ibatis.reflection.ReflectionException:Error,instantiating,class Mybaits.haha.Teacher with invalid types () or values (). Cause: java.lang.NoSuchMethodException: Mybaits.haha.Teacher.<init>()
解决方法 : 是因为实体类中无无参构造函数
如: 建立SQL查询结果字段与实体属性的映射关系信息
示例1:通过setter构造领域模型
/**
* 必须提供一个无参数的构造函数
*/
2.用Mybaits 中查询,则生成的List结果会有问题
List查询的都是同一个类
例如:可见返回的结果中有 三个 一模一样的 Goods(id=1,且包含5个GoodsImg),
而我们期待的结果应该是 List{ Goods(id=1), Goods(id=2), Goods(id=3) }
解决方法 : resultMap
的 column=... 定义不能一样:
相同错误链接 :http://www.cnblogs.com/zemliu/archive/2013/08/16/3263053.html
3.没有在conf.xml中注册
Mapped Statements collection does not contain value for Mybaits.haha.ClassesMapper3.getUser
4.测试框架
在使用所有注释前必须使用@RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境
5.一直困扰我两天的问题居然是因为@Autowired
是无法注入的static类型的数据
静态方法是属于类(class)的,普通方法才是属于实体对象(也就是New出来的对象)的,spring注入是在容器中实例化对象,所以不能使用静态方法
问题连接:http://blog.csdn.net/z69183787/article/details/38402007
相关文章推荐
- 题目1436:Repair the Wall
- STL学习笔记— —无序容器(Unordered Container)
- Pass-Muraille
- Deeplearning ,AI,Machine Learning 的关系
- [www.51kuaisou.com]最全的maven中央仓库
- 如何逃过taint droid的跟踪
- 一张图系列——从CreateProcess到main函数的过程
- POJ 3421 X-factor Chains
- Installation error: INSTALL_FAILED_CONFLICTING_PROVIDER 解决方案
- Rails的一些設定、Bundler,以及Command Line指令的用法
- CF 346 B vector<pair> s[100]
- POJ2585 Window Pains
- 我与小娜(49):距离人工智能创造音乐已经不远了
- leetcode---Factorial Trailing Zeroes
- beaglebone black xenomai移植 ---fwqlzz love is for ever
- Rails中scope和类方法的区别
- 【转】Condition的await-signal流程详解
- LeetCode *** 219. Contains Duplicate II
- InvalidateRect只是增加重绘区域,在下次WM_PAINT的时候才生效
- InvalidateRect只是增加重绘区域,在下次WM_PAINT的时候才生效