Reputation: 189
In my project I use mybatis as dao and I want to get the result which an arraylist of the select row from database for example
I have an Employee class and a dao interface Employee.java
public class Employee {
private int id;
private String name;
private String sex;
private String phonenumber;
}
EmpInterface.java
public interface EmpInterface {
public ArrayList<Employeer> selectAll();
}
How should I write the select tag in mapper.xml
of mybatis?
Upvotes: 1
Views: 6860
Reputation: 985
Something like this:
<resultMap id="BaseResultMap" type="package.Employee">
<id column="ID" jdbcType="NUMERIC" property="id" />
<result column="NAME" jdbcType="VARCHAR" property="name" />
<result column="SEX" jdbcType="VARCHAR" property="sex" />
<result column="PHONE_NUMBER" jdbcType="VARCHAR" property="phonenumber" />
</resultMap>
<select id="selectAll" resultMap="BaseResultMap">
SELECT
emp.ID,
emp.NAME,
emp.SEX,
emp.PHONE_NUMBER
FROM EMPLOYEES emp
</select>
Upvotes: 2