mybatis 总结
2016-07-24 12:50
323 查看
<resultMap id="blogMap" type="Blog" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="content" property="content" jdbcType="VARCHAR" />
</resultMap>
<sql id="bloglist" >
id, title, content
</sql>
select
<include refid="bloglist" />
from blog
where id = #{id}
</select>
delete from blog
where id = #{id,jdbcType=INTEGER}
</delete>
insert into blog(id, title, content)
values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="blog" >
insert into blog
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="title != null" >
title,
</if>
<if test="describe != null" >
describe,
</if>
<if test="content != null" >
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="title != null" >
#{title,jdbcType=VARCHAR},
</if>
<if test="content != null" >
#{content,jdbcType=VARCHAR},
</if>
</trim>
</insert>
update blog
<set >
<if test="title != null" >
title = #{title,jdbcType=VARCHAR},
</if>
<if test="content != null" >
content = #{content,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
update blog
set title = #{title,jdbcType=VARCHAR},
content = #{content,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<id column="id" property="id" jdbcType="INTEGER" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="content" property="content" jdbcType="VARCHAR" />
</resultMap>
<sql id="bloglist" >
id, title, content
</sql>
1 select
<select id="selectById" resultMap="blogMap" parameterType="java.lang.Integer" >select
<include refid="bloglist" />
from blog
where id = #{id}
</select>
2 delete
<delete id="deleteById" parameterType="java.lang.Integer" >delete from blog
where id = #{id,jdbcType=INTEGER}
</delete>
3 insert
<insert id="insert" parameterType="blog" >insert into blog(id, title, content)
values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="blog" >
insert into blog
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="title != null" >
title,
</if>
<if test="describe != null" >
describe,
</if>
<if test="content != null" >
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="title != null" >
#{title,jdbcType=VARCHAR},
</if>
<if test="content != null" >
#{content,jdbcType=VARCHAR},
</if>
</trim>
</insert>
4 update
<update id="updateByIdSelective" parameterType="blog" >update blog
<set >
<if test="title != null" >
title = #{title,jdbcType=VARCHAR},
</if>
<if test="content != null" >
content = #{content,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
5 update
<update id="updateByID" parameterType="blog" >update blog
set title = #{title,jdbcType=VARCHAR},
content = #{content,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
相关文章推荐
- MyBatis学习教程(八)-Mybatis3.x与Spring4.x整合图文详解
- mybatis3批量更新 批量插入
- Spring3.2+mybatis3.0+atomikos的jta系统搭建
- mybatis 动态列 查询
- mybatis3中@SelectProvider的使用技巧
- Could not find result map JxjlcMapper.JxjlcModelResult
- memcached支持mybatis3
- mybatis整合spring 之 基于接口映射的多对一关系
- 使用mybatis3--注解方式
- 使用mybatis3--mapping文件方式
- spring4mvc整合mybatis3
- 使用MyBatis调用Oracle存储过程
- spring 整合mybatis 出现解析不了配置文件的问题
- mybatis3的中文官方文档
- Spring Mvc + Spring + Mybatis3 搭建Web工程详解
- ibatis迁移到mybatis3
- 企业信息化快速开发平台 JeeSite
- intellij idea创建的maven找不到mybatis映射器xml
- ibatis迁移到mybatis3的注意事项
- SpringMVC4 + MyBatis3 + SQL Server 2014整合教程(含增删改查分页)