12 映射-- 集合类的映射(Set,List,Map,Array)

来源:互联网 发布:ubuntu安装mysql命令 编辑:程序博客网 时间:2024/04/30 06:24

部门类Department ,   他有 empa1, empa2, empa3, empa4是四种集合类型

 

 

public class Department {private int id;private String name;private Set<Employee> emps1; //Setprivate List<Employee> emps2; //Listprivate Map<String, Employee> emps3; //Mapprivate Employee[] emps4; //数组}

 

员工类Employee 略...(前面的笔记有这个类)

 

Set 类型的映射 :

<set name="emps" inverse="true"><key column="depart_id"/><one-to-many class="Employee" /></set>

List集合的映射:(要保存顺序 )

<list name="emps"><key column="depart_id" /><!-- List集合是有顺序的, 要保存住顺序 --><!-- order_col字段 用来保存顺序--><list-index column="order_col" /><one-to-many class="Employee" /></list>

 List集合的映射:(不要保存顺序 )

<bag name="emps"><key column="depart_id" /><one-to-many class="Employee" /></bag>

 Map 集合的映射:

<map name="emps"><key column="depart_id" /><map-key type="string" column="name"/><one-to-many class="Employee" /></map>

 数组 的映射:  (与List一样)

<array name="emps"><key column="depart_id" /><!-- 集合是有顺序的, 要保存住顺序 --><!-- order_col字段 用来保存顺序--><list-index column="order_col" /><one-to-many class="Employee" /></array >

 

0 0
原创粉丝点击