<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "/dtd/mybatis-3-mapper.dtd">
<mapper namespace="batisdemo.daomapper.StudentMapper">
<resultMap id="BaseResultMap" type="ity.Student">
<result column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="age" jdbcType="INTEGER" property="age" />
<result column="sex" jdbcType="CHAR" property="sex" />
</resultMap>
//--以上内容是⾃动⽣成得
//插⼊⼀条新得数据,部分字段更新
//parameterType  ⼊参是对象
<insert id="insertStudent" parameterType="ity.Student">
insert into mysql_student ( name, age, sex)
values  (#{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER},
#{sex,jdbcType=CHAR})
</insert>
//插⼊⼀条新得数据,每个字段都更新切判断
//useGeneratedKeys="true"  keyProperty="id":当主键id是⾃增的情况下,添加⼀条记录的同时,我们要获取到主键id。
// <trim prefix="(" suffix=")" suffixOverrides=","> ,prefix:在trim标签内sql语句加上前缀"(",suffix:在trim标签内sql语句加上后缀")",suffixOverrides:指定去除多余的后缀内容"," <insert id="insertSelectiv
e" parameterType="ity.Student"  useGeneratedKeys="true"
keyProperty="id">
insert into mysql_student
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
name,
</if>
<if test="age != null">
mysql下载失败怎么办
age,
</if>
<if test="sex != null">
sex,
</if>
二郎我已经爱上你</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="age != null">
#{age,jdbcType=INTEGER},
</if>
<if test="sex != null">
#{sex,jdbcType=CHAR},
</if>
</trim>
</insert>
-------------------------------------------------------------------------
/
特斯拉最新新闻
/修改,每个字段判空
<update id="update" parameterType="addressMappingDto">
update address_base
<set>
<trim prefix="" suffix="" suffixOverrides=",">
<if test="road != null">
road = #{road,jdbcType=VARCHAR},
</if>
createtask创建线程<if test="stationId != null">
station_id = #{stationId,jdbcType=INTEGER},
</if>
<if test="stationName != null and stationName !=''">
station_name = #{stationName,jdbcType=VARCHAR},
</if>
update_time = now(),
update_user = #{updateUser,jdbcType=VARCHAR}
</trim>
</set>
where id = #{id,jdbcType=BIGINT}
AND is_delete = 0
</update>
//简单得update
<update id="updateUser" parameterType="ity.Student">
update mysql_studentmysql菜鸟教程增删改查
set name = #{name,jdbcType=VARCHAR},
age = #{age,jdbcType=INTEGER},
sex = #{sex,jdbcType=CHAR}
where id = #{id,jdbcType=INTEGER}
</update>
-----------------------------------------------------------
<!-- 删除实体 -->
<update id="delete" parameterType="addressMappingDto">
html多久可以学会update address_base
<set>
is_delete = 1,
update_time = now(),
update_user = #{updateUser,jdbcType=VARCHAR}
</set>
where id = #{id,jdbcType=BIGINT}
AND is_delete = 0
</update>
<delete id="deleteUserById" parameterType="java.lang.Integer">
delete from mysql_student
where id = #{id,jdbcType=INTEGER}
</delete>
------------------------------------------------------
//查询根据id
<select id="selectStudentId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select  * from mysql_student where  id = #{id,jdbcType=INTEGER}
</select>
//查询多条件
<select id="getUserByCondition" parameterType="java.lang.String" resultMap="BaseResultMap">
select  * from mysql_student where  name = #{name,jdbcType=VARCHAR} and age=#{age,jdbcType=INTEGER} </select>
//根据条件查询⼀个实体
<select id="findOneByCky2AndAddress" resultMap="BaseResultMap"
parameterType="addressMappingDto">
select
id,
province_id,
city_id,
county_id,
town_id,
cky2,
address,
road,
station_id,
station_name
from address_base
where cky2 = #{cky2,jdbcType=INTEGER}
AND address = #{address,jdbcType=VARCHAR}
AND is_delete = 0
ORDER BY id DESC LIMIT 1
</select>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。