Ah, looked for a long time Baidu, unexpectedly there is no direct example ... Own reference to other examples, wrote a ...
Other ignores, directly on the key code:
Transfer from http://www.xuebuyuan.com/782623.html
Pojo class:
Package Com.mymaven.mybatisdemo.po;public class Department {private string dp_id;private string Dp_name;private string Cost_center;public String getdp_id () {return dp_id;} public void setdp_id (String dp_id) {this.dp_id = dp_id;} Public String Getdp_name () {return dp_name;} public void Setdp_name (String dp_name) {this.dp_name = Dp_name;} Public String Getcost_center () {return cost_center;} public void Setcost_center (String cost_center) {this.cost_center = Cost_center;} Public Department () {super ();}}
Mapper Interface:
Public interface Departmentmapper {//query returns a listpublic list<department> queryalldepartment ();}
Mapper the corresponding configuration file:
<!--here namespace need to specify DAO interface--><mapper namespace= "Com.mymaven.mybatisdemo.dao.DepartmentMapper" > <!--Configure a resultmap to specify the type returned-- <resultmap id= "departMent" type= "departMent" > <id column= "Dp_ ID "property=" dp_id "/> <result column=" Dp_name "property=" Dp_name "/> <result column=" Cost_ Center "property=" Cost_center "/> </resultMap> <!--returns a list of the notation-- <select id=" Queryalldepartment " resultmap=" departMent "> select * from T_department </select> </ Mapper>
Attention
<select id= "queryalldepartment" resultmap= "DepartMent" Here the return type is Resultmap, not resulttype. I got it wrong.
MyBatis return list<object> method