码迷,mamicode.com
首页 > 其他好文 > 详细

一个ibatis映射文件的例子(包含增删改单查,多查)

时间:2018-07-05 12:15:34      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:cti   odi   dtd   query   result   create   包含   col   model   


<?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.ZXC.lesson.dao.LessonUserDao">

<sql id="table">
user
</sql>
<sql id="insert_parm">
u_id,u_name,u_sex,u_age
</sql>
<sql id="query_parm">
u_id,u_name,u_sex,u_age,u_create_time,u_update_time
</sql>


<resultMap id="id" type="com.ZXC.lesson.model.LessonUser">
<id column="u_id" property="ID"/>
<result column="u_name" property="Name"/>
<result column="u_sex" property="Sex"/>
<result column="u_age" property="Age"/>
</resultMap>

<insert id="save" parameterType="com.ZXC.lesson.model.LessonUser"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO <include refid="table"/>
(<include refid="insert_parm"/>)
VALUES
(#{ID},#{Name},#{Sex},#{Age})
</insert>

<update id="update" parameterType="com.ZXC.lesson.model.LessonUser">
UPDATE <include refid="table"/>
<set>
<if test="Sex!=null">u_sex=#{Sex}</if>
<if test="Age!=null">u_age=#{age}</if>
</set>
</update>

<update id="delete" parameterType="com.ZXC.lesson.model.LessonUser">
UPDATE <include refid="table" />
SET is_delete=1
WHERE u_id=#{ID}
</update>

<select id="querybyid" parameterType="com.ZXC.lesson.model.LessonUser">
SELECT <include refid="query_parm"/>
FROM <include refid="table"/>
WHERE u_id=#{ID} AND is_delete=0
</select>

<select id="querylist" parameterType="com.ZXC.lesson.model.LessonUser">
SELECT <include refid="query_parm"/>
FROM <include refid="table"/>
WHERE id IN
<foreach collection="uid_list" open="(" close=")" item="uid" separator=",">
       #{ID}
   </foreach>
AND is_delete=0
</select>
</mapper>
 

一个ibatis映射文件的例子(包含增删改单查,多查)

标签:cti   odi   dtd   query   result   create   包含   col   model   

原文地址:https://www.cnblogs.com/television/p/9267391.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!