package com.zjy.ibatis.model;
import java.util.List;
public class Customer {
private int id;
private String username;
private String password;
private Account account;
private List<Order> orders;
private List<Activity> activitys;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
public List<Order> getOrders() {
return orders;
}
public void setOrders(List<Order> orders) {
this.orders = orders;
}
public List<Activity> getActivitys() {
return activitys;
}
public void setActivitys(List<Activity> activitys) {
this.activitys = activitys;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zjy.ibatis.ICustomerDao" >
<resultMap type="com.zjy.ibatis.model.Customer" id="customerResultMap">
<id property="id" column="id"/>
<result property="username" column="user_name"/>
<result property="password" column="user_pass"/>
<association property="account" select="com.zjy.ibatis.IAccountDao.findAccountByCustomerId" column="id"></association>
<collection property="orders" javaType="ArrayList" ofType="Order"
select="com.zjy.ibatis.IOrderDao.findOrderByCustomerId" column="id"/>
<collection property="activitys" javaType="ArrayList" ofType="Activity"
select="com.zjy.ibatis.IActivityDao.findActivitysByCustomerId" column="id"/>
</resultMap>
<insert id="insert" parameterType="Customer">
insert into customer(username,password)values(#{username},#{password})
</insert>
<delete id="delete" parameterType="java.lang.Integer">
delete from customer where id=#{id}
</delete>
<update id="update" parameterType="Customer">
update customer set username=#{username},password=#{password} where id=#{id}
</update>
<select id="findById" parameterType="java.lang.Integer" resultType="Customer" resultMap="customerResultMap" >
select * from customer where id=#{id}
</select>
<select id="query" parameterType="Customer" resultMap="customerResultMap">
select * from customer
<where>
<if test="username!=null and username!=''">
user_name like concat(concat('%',#{username}),'%')
</if>
<if test="password!=null and password!=''">
or user_pass like concat(concat('%',#{password}),'%')
</if>
</where>
</select>
</mapper>
IBatis一对一,一对多,多对多
原创
©著作权归作者所有:来自51CTO博客作者体系架构的原创作品,请联系作者获取转载授权,否则将追究法律责任
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
ibatis配置多表关联(一对一、一对多、多对多)
iBatis的多表关联。ibatis的表关联,和数据库语句无关,是在Java程序中,把若干语句的结果关联到一起。这种关联形式,虽然在大数据量时是
iBATIS DAO .net XML Blog -
表关系(一对一,一对多,多对多)
可以在数据库图表中的表之间创建关系,以显示一个表中的列与另一个表中的列是如何相链接的。在一个关
出版数据库工作 jobs电话null 数据库表关系 一对多关系数据库建立 唯一性约束