运维网's Archiver

论坛 › Mybatis › mybatis 返回list(转)

zidong 发表于 2016-11-26 10:57:29

mybatis 返回list(转) pojo 类:
 view plaincopy



[*]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接口:
 view plaincopy



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


mapper对应的配置文件:
 view plaincopy



[*]<!-- 此处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>  
页: [1]
查看完整版本: mybatis 返回list(转)
Powered by Discuz! X3.4 Archiver   © 2001-2023 Discuz! Team.