public interface CustomerMapper {
@Select("select * from customer where id=#{id}")
@Results(value={@Result(property="id",column="id"),
@Result(property="username",column="username"),
@Result(property="password",column="password"),
@Result(property="account",column="id",javaType=Account.class,
one=@One(select="com.zjy.ibatis.annon.AccountMapper.findByCustomerId")),
@Result(property="orders",column="id",javaType=List.class,
many=@Many(select="com.zjy.ibatis.annon.OrderMapper.getOrdersByCustomerId")),
@Result(property="activities",column="id",javaType=List.class,
many=@Many(select="com.zjy.ibatis.annon.ActivityMapper.getActivitiesByCustomerId"))})
public Customer findById(int id);
@Update(value={"update customer set username=#{username},password=#{password} where id=#{id}"})
public void update(Customer customer);
@Delete(value="delete from customer where id=#{id}")
public void delete(Customer customer);
@Insert(value="insert into customer(username,password)values(#{username},#{password})")
public void save(Customer customer);
@Select("select * from customer")
public List<Customer> findAll();
@Select("select * from customer limit #{start},#{length}")
public List<Customer> getPage(int start,int length);
}
package com.zjy.ibatis;
public class CustomerSqlBuilder extends SqlBuilder{
public String makeSelect(CustomerBuilder c){
SELECT("c.id,c.username,c.password");
FROM("customer c");
if(c.getUsername()!=null){
WHERE("c.username=#{username}");
}