Ibatis 实现多对多映射
来源:互联网 发布:怎样关闭淘宝退款申请 编辑:程序博客网 时间:2024/06/06 04:43
1.创建表Factory(工厂),InwarehouseType(入厂类型),FactoryWarehouseBw(中间表,工厂和入场类型是多对多关系)
create table Factory
(
factoryid varchar(3)
factoryname varchar(20)
)
create table InwarehouseType
(
inwarehousetypeid varchar(3)
intwarehousetypename varchar(20)
)
create table FactoryWarehouseBw
(
factoryid varchar(3)
warehousetypeid varchar(3)
)
2.定义两个Factory,InWarehouseType两个JavaBean
public class Factory {
private String factoryid;
private String factoryname;
private List<InWarehouseType> listwarehousetype=new ArrayList<InWarehouseType>();
get,set略
}
public class InWarehouseType {
private String typeid;
private String typename;
get,set略
}
3.定义Factory.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="factory_space">
<!-- 定义一个工厂类,一个工厂下有多个入厂类型 -->
<typeAlias alias="factory" type="com.ibatis.bean.Factory"/>
<typeAlias alias="inwarehousetype" type="com.ibatis.bean.InWarehouseType"/>
<resultMap id="FactoryResult" class="factory">
<result property="factoryid" column="factoryid" javaType="String" jdbcType="varchar"/>
<result property="factoryname" column="factoryname" javaType="String" jdbcType="varchar"/>
<result property="listwarehousetype" column="factoryid"
javaType="java.util.List" jdbcType="varchar"
select="factory_space.selectInwarehouseType"/>
</resultMap>
<!-- 返回结果为List
-->
<select id="selectFactoryByFactoryId" parameterClass="String" resultMap="FactoryResult">
<![CDATA[
select
factoryid,
factoryname
from factory
where factoryid = #factoryid#
]]>
</select>
<!-- 有3个表Factory,InWarehouseType,FactoryWarehouseBw(是多对多关系) -->
<select id="selectInwarehouseType" parameterClass="String" resultClass="inwarehousetype">
<![CDATA[
select intype.inwarehousetypeid as typeid,intype.inwarehousetypename as typename
from InWarehouseType intype
left join FactoryWarehouseBw bw
on intype.inwarehousetypeid=bw.warehousetypeid
where bw.inorout=1 and bw.factoryid=#factoryid#
]]>
</select>
</sqlMap>
4.生成测试类,调用即可
总结:集合必须使用List,用Set会报错
- Ibatis 实现多对多映射
- ibatis多对多映射
- ibatis一对多映射
- 解决IBatis中的多对一映射n+1问题
- 解决IBatis中的多对一映射n+1问题
- ibatis多对一表关联映射的解决过程
- hibernate实现单向多对多映射
- ibatis-2.3.4全面解析(全局性配置,sql语句映射,一对一,多对多)
- 使用ibatis映射实体间一对多、多对一的关系
- ibatis一对多关系映射技巧
- ibatis 实体映射(一对多)
- ibatis多对多示例
- 多对多映射
- 多对多映射
- 多对多映射
- 多对一映射
- 多对一映射
- Hibernate使用Map实现多对多映射
- 区别C#中的两个属性(Property和Attribute)
- [POJ]2301 Beat the Spread!
- linux虚拟机VMware vSphere上安装VMware Tools
- Android下增加APK访问/data目录权限的方法
- centos No package 'glib-2.0' found解决办法
- Ibatis 实现多对多映射
- 数字图像处理基本算法实现(1)--section3.2基本灰度变换
- .net framework 知识点
- windows form (窗体) 之间传值小结
- JAVA中int、String的类型转换
- QLPreviewController用法
- 台湾程序员的Blog
- 体内湿气重怎样祛除?
- tkprof