8. sql 片段
<sql id="periodicalColumns">
a.id AS "id",
a.name AS "name",
a.country AS "country",
a.type AS "type",
a.publish AS "publish",
a.introduction AS "introduction",
a.logo AS "logo",
a.company AS "company",
a.CN AS "cn",
a.size AS "size",
a.address AS "address",
a.ISSN AS "issn",
a.languages AS "languages",
a.email AS "email",
a.year AS "year",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</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">
<mapper namespace="com.thinkgem.jeesite.modules.tpydg.periodical.dao.PeriodicalDao">
<sql id="periodicalColumns">
a.id AS "id",
a.name AS "name",
a.country AS "country",
a.type AS "type",
a.publish AS "publish",
a.introduction AS "introduction",
a.logo AS "logo",
a.company AS "company",
a.CN AS "cn",
a.size AS "size",
a.address AS "address",
a.ISSN AS "issn",
a.languages AS "languages",
a.email AS "email",
a.year AS "year",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="periodicalJoins">
</sql>
<select id="get" resultType="Periodical">
SELECT
<include refid="periodicalColumns"/>
FROM periodical a
<include refid="periodicalJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Periodical">
SELECT
<include refid="periodicalColumns"/>
FROM periodical a
<include refid="periodicalJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
<if test="type != null and type != ''">
AND type = #{type}
</if>
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Periodical">
SELECT
<include refid="periodicalColumns"/>
FROM periodical a
<include refid="periodicalJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO periodical(
id,
name,
country,
type,
publish,
introduction,
logo,
company,
CN,
size,
address,
ISSN,
languages,
email,
year,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{name},
#{country},
#{type},
#{publish},
#{introduction},
#{logo},
#{company},
#{cn},
#{size},
#{address},
#{issn},
#{languages},
#{email},
#{year},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE periodical SET
name = #{name},
country = #{country},
type = #{type},
introduction = #{introduction},
logo = #{logo},
company = #{company},
CN = #{cn},
size = #{size},
address = #{address},
ISSN = #{issn},
languages = #{languages},
email = #{email},
year = #{year}
WHERE id = #{id}
</update>
<update id="delete">
UPDATE periodical SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
</mapper>
8. sql 片段的更多相关文章
- MyBatis的一系列问题的处理(遍历Map集合和智能标签和属性和字段不一样的解决办法 和sql片段)(三)
一.字段名与属性名(数据库的名字)不一样怎么办? 方案一:在小配置中配置一个resultMapper <!--方案一:resultMapper 字段名与属性名不一致 --> <res ...
- 6.Mybatis中的动态Sql和Sql片段(Mybatis的一个核心)
动态Sql是Mybatis的核心,就是对我们的sql语句进行灵活的操作,他可以通过表达式,对sql语句进行判断,然后对其进行灵活的拼接和组装.可以简单的说成Mybatis中可以动态去的判断需不需要某些 ...
- mybatis动态SQL中的sql片段
在mybatis中通过使用SQL片段可以提高代码的重用性,如下情景: 1.创建动态SQL <sql id="sql_count">select count(*)< ...
- ibatis复用SQL片段、引入片段 动态条件增加
1:ibatis复用SQL片段.引入片段 使用[sql]和[include]标签: 通常情况下,你会这样写:xml 代码 <select id="selectItemCount&qu ...
- Mybatis Sql片段的应用
在一个查询里,针对各种不同数据库,有时候只是一部分 SQL 是不相同的,为避免相同的部分复制多次,所以将不相同的部分进行适当的隔离,再重用就可以了. 在 MyBatis 里声明两段 <sql d ...
- 03_MyBatis基本查询,mapper文件的定义,测试代码的编写,resultMap配置返回值,sql片段配置,select标签标签中的内容介绍,配置使用二级缓存,使用别名的数据类型,条件查询ma
1 PersonTestMapper.xml中的内容如下: <?xmlversion="1.0"encoding="UTF-8"?> < ...
- SSM-MyBatis-05:Mybatis中别名,sql片段和模糊查询加getMapper
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 简单概述一下本讲 别名,sql片段简单写一下,模糊查询多写一点 一.别名 <typeAliases> ...
- sql片段
1):定义sql片段 <!-- 定义sql片段 --> <!-- id: sql片段的标识 经验:1:基于单表来定义sql片段,这样的话sql片段的可重用性才高 2:sql片段中不要 ...
- 使用mybatis提供的各种标签方法实现动态拼接Sql。使用sql片段提取重复的标签内容
Sql中可将重复的sql提取出来,使用时用include引用即可,最终达到sql重用的目的,如下: <select id="findUserByNameAndSex" par ...
- java-mybaits-00402-Mapper-动态sql-if、where、foreach、sql片段
1.动态sql(重点) 通过mybatis提供的各种标签方法实现动态拼接sql. 什么是动态sql mybatis核心 对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装. ...
随机推荐
- Spring事务SPI及配置介绍
Spring事务SPI及配置介绍 标签: spring事务aop数据管理 2015-05-17 11:42 606人阅读 评论(0) 收藏 举报 分类: Spring(12) 版权声明:本文为 ...
- html乱码原因与网页乱码解决方法
造成html网页乱码原因主要是html源代码内中文字内容与html编码不同造成.但无论是哪种情况造成乱码在网页开始时候都需要设置网页编码. charset编码设置 html网页乱码效果截图 一.乱码造 ...
- activity的四种加载模式介绍
四种加载模式的介绍: a) Standard : 系统默认模式,一次跳转即会生成一个新的实例: b) SingleTop : 和 standard 类似,唯一的区别就是当跳转的对象是位于栈顶 ...
- 第5章 选举模式和ZooKeeper的集群安装 5-1 集群的一些基本概念
xx就是我们的master,也就是我们的主节点.心跳机制,当有一个节点挂掉之后,整个集群还是可以工作的.选举模式,我们现在的master是正常运行的,但是在某些情况下它宕机了死机了,那么这个时候它这个 ...
- Mybatis的批处理以及执行Update返回行数为负数
项目中用到了批量更新. 在开发当中,可能经常会遇到批量处理这种情况,一般都再在java层面进行, 其本质是节省数据库连接打开关闭的的次数,占用更少的运行内存. 下面先记一下批处理映射吧: mybati ...
- JS中数组的内建函数说明
函数简述 map():返回一个新的Array,每个元素为调用func的结果 filter():返回一个符合func条件的元素数组 some():返回一个boolean,判断是否有元素是否符合func条 ...
- resize函数有五种插值算法
转自http://blog.csdn.net/fengbingchun/article/details/17335477 最新版OpenCV2.4.7中,cv::resize函数有五种插值算法:最近邻 ...
- HDOJ 1121 Complete the Sequence
[题目大意]有一个数列P,它的第i项是当x=i时,一个关于x的整式的值.给出数列的前S项,你需要输出它的第S+1项到第S+C项,并且使整式的次数最低.多测. [数据范围]数据组数≤5000,S+C≤1 ...
- 使用Eclipse创建Maven javaweb项目
其实是我自己不会创建Maven JavaWeb项目,就自己瞎蒙了一下,竟然成功了. 这里有个条件就是你的Maven已经在电脑上配好了. 第一步就是File->New->Maven Proj ...
- js/jq基础(日常整理记录)-2-一个简单的js方法实现集合的非引用拷贝
一.一个简单的js方法实现集合拷贝 做web项目的时候,少不了和js中的数组,集合等对象接触,那么你肯定会发现,在js中存在一个怪异的现象就是数组和集合的拷贝都是地址复制,并不是简单的数据的拷贝. 举 ...