Springboot+mybatis, native dao development issues

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?


change the id of the query method in mapper to select. That is, the method name of dao.


mapper.JinBoot should be an interface, which declares a test method, and mapper.JinBoot posts it to see
error source code

.
public V get(Object key) {
/* 670 */       V value = super.get(key);
/* 671 */       if (value == null) {
/* 672 */         throw new IllegalArgumentException(this.name + " does not contain value for " + key);
/*     */       }
/* 674 */       if ((value instanceof Ambiguity)) {
/* 675 */         throw new IllegalArgumentException(((Ambiguity)value).getSubject() + " is ambiguous in " + this.name + " (try using the full name including the namespace, or rename one of the entries)");
/*     */       }
/*     */       
/* 678 */       return value;
/*     */     }
protected final Map<String, MappedStatement> mappedStatements = new StrictMap("Mapped Statements collection");

Mybatis parses the xml file, uses StrictMap to store namespace+id as key,MappedStatement as value, and executes the selectList method to find the corresponding MappedStatement, based on sqlId. If value is null, this exception Mapped Statements collection does not contain value for mapper.JinBoot.test is reported.


Has

been added to the IncompleteStatement collection? If the conversion fails to read the XML file, it will be added directly to the collection and no exception will be reported.

it is recommended to have a look at the breakpoint. Mapper files will be scanned through this method

// 
// mybatis-3.4.4.jar
// org.apache.ibatis.builder.xml.XMLMapperBuilder line:132
private void buildStatementFromContext(List<XNode> list, String requiredDatabaseId) {
    for (XNode context : list) {
      final XMLStatementBuilder statementParser = new XMLStatementBuilder(configuration, builderAssistant, context, requiredDatabaseId);
      try {
        statementParser.parseStatementNode();
      } catch (IncompleteElementException e) {
        configuration.addIncompleteStatement(statementParser);
      }
    }
  }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31a3c-2bda8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31a3c-2bda8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?