Java中根据namespace和id获取mybatis的*mapper.xml文件中的SQL时需要区分大小写
<mapper namespace="person" >
<select id="queryPersonList" parameterType="xxx.xxx.Person" resultType="xxx.xxx.Person">
select * from person ...
</select>
</mapper>
sqlSessionTemplate.selectList("person.queryPersonList", person);
selectList
方法的第一个参数的值为:namespace.id
,且区分大小写。
若大小写不一致(比如:将query的首字母改为大写)
sqlSessionTemplate.selectList("person.QueryPersonList", person);
则在执行该代码时报错,提示找不到对应的语句(Mapped Statements collection does not contain value for ...
)
为避免因大小写导致的bug,建议使用接口方式映射SQL
2018-11-03 补充
接口映射
java 接口全路径 与 XML 文件的命名空间
com.example.demo.dao.StreetDao
namespace="com.example.demo.dao.StreetDao"
java 接口方法名称 与 元素ID
Street queryStreet(Long streetId);
id="queryStreet"
修改映射元素ID的大小写,结果如下
2019-03-16 补充
SpringBoot 整合 mybatis 的demo