Reputation: 2762
I tried to code MyBatis but encounter IllegalArgumentException: Mapped Statements collection does not contain value. Could anyone please tell me what wrong.
public interface StudentMapper {
@Select("SELECT ID, Name, Address, Email FROM Student")
@Results(value = {@Result(property="id", column="ID"),
@Result(property="name", column="Name"),
@Result(property="address", column="Address"),
@Result(property="email", column="Email")})
public ArrayList<Student> getStudent();
}
Main Method:
public static void main(String args[]) throws IOException {
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
try (SqlSession session = sqlSessionFactory.openSession()) {
List<Student> student = session.selectList("getStudent");
for(Student st : student ){
System.out.println(st.getId());
System.out.println(st.getName());
System.out.println(st.getEmail());
}
System.out.println("Records Read Successfully ");
//session.commit();
//session.close();
}
Configuration located at resources folder:
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default = "development">
<environment id = "development">
<transactionManager type = "JDBC"/>
<dataSource type = "POOLED">
<property name = "driver" value = "com.mysql.jdbc.Driver"/>
<property name = "url" value = "jdbc:mysql://localhost:3306/Student"/>
<property name = "username" value = "root"/>
<property name = "password" value = "1234"/>
</dataSource>
</environment>
</environments>
<!--<mappers>
<mapper resource = "mapper.xml"/>
</mappers>
-->
</configuration>
Please help me as im stuck with it.
Upvotes: 0
Views: 1761