package com.zhenshan.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.zhenshan.entity.BorrowCar;
import com.zhenshan.entity.Condition;
public interface BorrowCarDao {
List<BorrowCar> findAll(Condition con);
List<BorrowCar> list();
int jia(BorrowCar borrowCar);
int add(@Param("borrowCar")BorrowCar borrowCar);
BorrowCar toChe(Integer bid);
int updateAmount(BorrowCar borrowCar);
int updateNumber(BorrowCar borrowCar);
}
------------------------------------------------------sql
<?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">
<!-- 命名空间的值为dao层接口的权限定名 -->
<mapper namespace="com.zhenshan.dao.BorrowCarDao" >
<select id="findAll" resultMap="carMapper">
select * from borrow_car b LEFT JOIN borrow_car_detail c ON b.bid=c.user_id
<where>
<if test="userName!=null and userName!='' ">
and b.user_name like "%" #{userName} "%"
</if>
<if test="carNumber!=null and carNumber!='' ">
and c.car_number like "%" #{carNumber} "%"
</if>
<if test="borrowCarDate!=null and borrowCarDate!='' ">
and c.borrow_car_date like "%" #{borrowCarDate} "%"
</if>
<if test="borrowCarAmount!=null">
and b.borrow_car_amount =#{borrowCarAmount}
</if>
</where>
<if test="paixu!=null and paixu!='' ">
order BY ${paixu}
</if>
</select>
<resultMap type="BorrowCar" id="carMapper">
<id property="bid" column="bid" />
<result property="userName" column="user_name" />
<result property="totalAmount" column="total_amount" />
<result property="borrowCarNumber" column="borrow_car_number" />
<result property="boorowCarAmount" column="borrow_car_amount" />
<association property="bcd" javaType="BorrowCarDetail">
<id property="cid" column="cid" />
<result property="borrowCarDate" column="borrow_car_date" />
<result property="userId" column="user_id" />
<result property="carNumber" column="car_number" />
<result property="borrowAmount" column="borrow_amount" />
</association>
</resultMap>
<select id="list" resultType="BorrowCar">
select * from borrow_car
</select>
<update id="jia">
update borrow_car set total_amount=total_amount+#{totalAmount} where user_name=#{userName}
</update>
<insert id="add">
insert into borrow_car values(null,#{borrowCar.userName},#{borrowCar.totalAmount},#{borrowCar.borrowCarNumber},#{borrowCar.boorowCarAmount})
</insert>
<select id="toChe" resultMap="carMapper">
select * from borrow_car b LEFT JOIN borrow_car_detail c ON b.bid=c.user_id where b.bid=#{bid}
</select>
<update id="updateAmount">
update borrow_car set borrow_car_amount=borrow_car_amount+1 where user_name=#{userName}
</update>
<update id="updateNumber">
update borrow_car set borrow_car_number=borrow_car_number+1 where user_name=#{userName}
</update>
</mapper>