在我的项目中,我使用mybatis作为dao,我想从数据库中获取选择行的arraylist的结果,例如
我有一个Employee类和一个dao接口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();
}
我应该如何在mybatis的mapper.xml
中编写select标签?
答案 0 :(得分:2)
这样的事情:
<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>