Mybatis 查询返回List

   哎,查了很久百度,竟然没有直接的例子... 自己参考其他例子,写了一个...

其他的忽略,直接上关键代码:

pojo 类:

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接口:

public interface DepartmentMapper {
	//查询返回一个list
	public List<Department> queryAllDepartment();


}


mapper对应的配置文件:

<!-- 此处namespace需要指定dao接口 -->
<mapper namespace="com.mymaven.mybatisdemo.dao.DepartmentMapper">
    <!--配置一个resultMap 指定返回的类型 -->
    <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>


    <!-- 返回一个list的写法 -->
    <select id="queryAllDepartment"  resultMap="departMent" >
        select * from t_department

    </select>


   
</mapper>



 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。