黑马程序员技术交流社区

标题: 【郑州校区】传智健康项目讲义第七章 五 [打印本页]

作者: 我是楠楠    时间: 2019-11-7 11:02
标题: 【郑州校区】传智健康项目讲义第七章 五
【郑州校区】传智健康项目讲义第七章 五

2.2.5 Mapper映射文件
OrderSettingDao.xml
[AppleScript] 纯文本查看 复制代码
 <!‐‐根据日期查询预约设置信息‐‐>
<select id="findByOrderDate" parameterType="date"
resultType="com.itheima.pojo.OrderSetting">
select * from t_ordersetting where orderDate = #{orderDate}
</select>
<!‐‐更新已预约人数‐‐>
<update id="editReservationsByOrderDate"
parameterType="com.itheima.pojo.OrderSetting">
update t_ordersetting set reservations = #{reservations} where
orderDate = #{orderDate}
</update>

MemberDao.xml

[AppleScript] 纯文本查看 复制代码
<?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.itheima.dao.MemberDao" >
<select id="findAll" resultType="com.itheima.pojo.Member">
select * from t_member
</select>
<!‐‐根据条件查询‐‐>
<select id="selectByCondition"
parameterType="string" resultType="com.itheima.pojo.Member">
select * from t_member
<if test="value != null and value.length > 0">
where fileNumber = #{value} or phoneNumber = #{value} or name
= #{value}
</if>
</select>
<!‐‐新增会员‐‐>
<insert id="add" parameterType="com.itheima.pojo.Member">
<selectKey resultType="java.lang.Integer" order="AFTER"
keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>
insert into
t_member
(fileNumber,name,sex,idCard,phoneNumber,
regTime,password,email,birthday,remark)
values
(#{fileNumber},#{name},#{sex},#{idCard},#{phoneNumber},
#{regTime},#{password},#{email},#{birthday},#{remark})
</insert>
<!‐‐删除会员‐‐>
<delete id="deleteById" parameterType="int">
delete from t_member where id = #{id}
</delete>
<!‐‐根据id查询会员‐‐>
<select id="findById" parameterType="int"resultType="com.itheima.pojo.Member">
select * from t_member where id = #{id}
</select>
<!‐‐根据id查询会员‐‐>
<select id="findByTelephone"
parameterType="string" resultType="com.itheima.pojo.Member">
select * from t_member where phoneNumber = #{phoneNumber}
</select>
<!‐‐编辑会员‐‐>
<update id="edit" parameterType="com.itheima.pojo.Member">
update t_member
<set>
<if test="fileNumber != null">
fileNumber = #{fileNumber},
</if>
<if test="name != null">
name = #{name},
</if>
<if test="sex != null">
sex = #{sex},
</if>
<if test="idCard != null">
idCard = #{idCard},
</if>
<if test="phoneNumber != null">
phoneNumber = #{phoneNumber},
</if>
<if test="regTime != null">
regTime = #{regTime},
</if>
<if test="password != null">
password = #{password},
</if>
<if test="email != null">
email = #{email},
</if>
<if test="birthday != null">
birthday = #{birthday},
</if><if test="remark != null">
remark = #{remark},
</if>
</set>
where id = #{id}
</update>
<!‐‐根据日期统计会员数,统计指定日期之前的会员数‐‐>
<select id="findMemberCountBeforeDate" parameterType="string"
resultType="int">
select count(id) from t_member where regTime <= #{value}
</select>
<!‐‐根据日期统计会员数‐‐>
<select id="findMemberCountByDate" parameterType="string"
resultType="int">
select count(id) from t_member where regTime = #{value}
</select>
<!‐‐根据日期统计会员数,统计指定日期之后的会员数‐‐>
<select id="findMemberCountAfterDate" parameterType="string"
resultType="int">
select count(id) from t_member where regTime >= #{value}
</select>
<!‐‐总会员数‐‐>
<select id="findMemberTotalCount" resultType="int">
select count(id) from t_member
</select>
</mapper>

OrderDao.xml

[AppleScript] 纯文本查看 复制代码
<?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.itheima.dao.OrderDao" >
<resultMap id="baseResultMap" type="com.itheima.pojo.Order">
<id column="id" property="id"/>
<result column="member_id" property="memberId"/>
<result column="orderDate" property="orderDate"/>
<result column="orderType" property="orderType"/>
<result column="orderStatus" property="orderStatus"/>
<result column="setmeal_id" property="setmealId"/>
</resultMap>
<!‐‐新增‐‐>
<insert id="add" parameterType="com.itheima.pojo.Order">
<selectKey resultType="java.lang.Integer" order="AFTER"
keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>
insert into
t_order
(member_id,orderDate,orderType,orderStatus,setmeal_id)
values
(#{memberId},#{orderDate},#{orderType},#{orderStatus},#
{setmealId})
</insert>
<!‐‐动态条件查询‐‐>
<select id="findByCondition"
parameterType="com.itheima.pojo.Order"
resultMap="baseResultMap">
select * from t_order
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="memberId != null">
and member_id = #{memberId}
</if>
<if test="orderDate != null">
and orderDate = #{orderDate}</if>
<if test="orderType != null">
and orderType = #{orderType}
</if>
<if test="orderStatus != null">
and orderStatus = #{orderStatus}
</if>
<if test="setmealId != null">
and setmeal_id = #{setmealId}
</if>
</where>
</select>
</mapper>







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2