### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collectio

本文探讨了在使用MyBatis进行数据库操作时遇到的一个常见错误:MappedStatements集合中未找到对应的方法。通过调整XML配置文件中的<select>元素及Java代码中的返回类型,成功解决了查询学生列表总数的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.domain.StudentMappper.selectCountStudent

### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.domain.StudentMappper.selectCountStudent

 

Mybatis中的xml文件是这样子写的

<!-- 查找列表总数 -->

 <select id="Count" resultType="int">

   select count(1) from student;

 </select> 

 

最好返回类型不能是int,用int就会报以上类型的错,改用为HashMap

@Override

public HashMap<String, String> selectCount() {

//int a = 0 ;

/*Count c=new CountImp();

Connection conn;

try {

try {

Class.forName("com.mysql.jdbc.Driver");

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_database11","root","123456");

a=c.selectCount(conn);

} catch (SQLException e) {

e.printStackTrace();

}*/

    SqlSession session=sqlSessionFactory.openSession();

   /* a=session.selectOne("com.domain.StudentMappper.Count");*/

    HashMap<String, String> map=new HashMap<String, String>();

    String a=String.valueOf(session.selectOne("com.domain.StudentMapper.Count"));

    map.put("a", a);

/*a=session.selectMap("map", "com.domain.StudentMappper.selectCountStudent");*/

    return  map;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值