recently I want to try a relatively simple development method.
only writes sql statements in the xml file, and both incoming and outgoing parameters are map. Do something else in controller and service.
then write a test code.
this is the param, of sqlId and map types passed into the general Dao,service layer according to the sqlId call corresponding to the sql statement, and the returned result is also map
public class BaseDao {
private static SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
public static List<Map> select(String sqlId, Map param) {
try {
factoryBean.setDataSource(new DruidDataSource());
SqlSessionFactory sessionFactory = factoryBean.getObject();
SqlSession sqlSession = sessionFactory.openSession();
return sqlSession.selectList(sqlId, param);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Custom mapper.xml
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapper.JinBoot">
<select id="test" parameterType="hashMap" resultType="hashMap">
select * from user
</select>
</mapper>
also configured in application
mybatis.mapperLocations=classpath:mapper/*.xml
When is executed, through the controller interface and the service layer, the sqlId passed to the Dao layer is mapper.JinBoot.test
, and the param is empty.
executes an error message.
the error message is as follows:
Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mapper.JinBoot.test
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at cn.tianyustudio.jinboot.dao.BaseDao.select(BaseDao.java:20)
at cn.tianyustudio.jinboot.service.BaseService.select(BaseService.java:10)
at cn.tianyustudio.jinboot.controller.BaseController.test(BaseController.java:21)
look it up on the Internet, it probably means that there is no sql statement corresponding to mapper.JinBoot.test, the id, but isn"t it found according to namespace+id in mybatis? I don"t use mybatis"s mapper mapping here (there is a corresponding Dao.java), but this way of manually specifying id should be feasible in theory, is it a configuration problem or is it a configuration problem?