发表于: 2017-05-02 23:25:36
3 1270
今天完成的事情:
①昨天遇到一个问题。运行单元测试时(使用mapper ),
@Test
public void findStudent(){
Student studentById = studentService.findStudentById((long)12434264);
System.out.print(studentById);
}
报错:“Mapped Statements collection already contains value for findStudentById"。
百度上说造成这个问题的原因是mapper.xml文件中有重复的属性值。
后来因为我同时用了Mybatis的配置文件(.xml)和Annotation方式去配置数据库。
也就是StudentMapper.java 和 StudentMapper.xml中都有findStudentById等方法。
<mappers>
<!--<mapper resource="mapper/StudentMapper.xml" />-->
<mapper class="com.jn.mapper.StudentMapper"/>
</mappers>
遇到的问题:
收获:
在MyBatis中,Mapper中的namespace用于绑定Dao接口的,即面向接口编程。
它的好处在于当使用了namespace之后就可以不用写接口实现类,业务逻辑会直接通过这个绑定寻找到相对应的SQL语句进行对应的数据处理
明天计划:
评论