Mybatis常用xml
工作中mybatis常用的xml代码
<?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.up.sell.mapper.system.AdvertisementMapper"> <resultMap type="Advertisement" id="AdvertisementResult">
<id property="id" column="id" />
<result property="title" column="title" />
<result property="imgPath" column="img_path" />
<result property="url" column="url" />
<result property="description" column="description" />
<result property="sort" column="sort" />
<result property="place" column="place" />
<result property="provinceId" column="province_id" />
<result property="cityId" column="city_id" />
<result property="advFlag" column="adv_flag" />
<result property="createUser" column="create_user" />
<result property="createTime" column="create_time" />
<result property="updateUser" column="update_user" />
<result property="updateTime" column="update_time" />
<association property="areas" column="id" javaType="com.up.sell.vo.system.Areas" resultMap="areasResult" />
<association property="dictionary" column="id" javaType="com.up.sell.vo.system.Dictionary" resultMap="deptResult" />
</resultMap> <resultMap id="areasResult" type="Areas">
<id property="id" column="id" />
<result property="areaName" column="area_name" />
<result property="parentId" column="parent_id" />
<result property="shortName" column="short_name" />
</resultMap> <resultMap id="deptResult" type="Dictionary">
<id property="dKey" column="d_key" />
<result property="dValue" column="d_value" />
<result property="dName" column="d_name" />
<result property="parentKey" column="parent_ey" />
<result property="flag" column="flag" />
</resultMap> <select id="findList" parameterType="Advertisement" resultMap="AdvertisementResult">
SELECT
a.id ,
a.title ,
a.img_path ,
a.url ,
a.description ,
a.sort ,
a.adv_flag,
s1.short_name,
d.d_name
FROM
advertisement a
LEFT JOIN areas s1 on
a.city_id = s1.id
LEFT JOIN dictionary d ON d.parent_key = 111 AND
a.place = d.d_value
</select> <select id="findCity" parameterType="Advertisement" resultMap="AdvertisementResult">
SELECT DISTINCT
a.id ,
a.short_name
FROM
sys_company s
LEFT JOIN areas a
ON(s.city_id = a.id)
WHERE
(s.id = #{arg0} OR s.parent_id = #{arg0})
AND a.id IS NOT
NULL
AND a.short_name IS NOT NULL
</select> <select id="findPlace" parameterType="Advertisement" resultMap="AdvertisementResult">
SELECT
d.d_value ,
d_name
FROM
dictionary d
WHERE
d.parent_key = 111
AND flag
= 1
</select> <insert id="inserts" parameterType="Advertisement"
useGeneratedKeys="true" keyProperty="id">
insert into advertisement(
<if test="title != null and title != ''">title,</if>
<if test="imgPath != null and imgPath != ''">img_path,</if>
<if test="url != null and url != ''">url,</if>
<if test="sort != null and sort != ''">sort,</if>
<if test="place != null and place != ''">place,</if>
<if test="provinceId != null and provinceId != ''">province_id,</if>
<if test="cityId != null and cityId != ''">city_id,</if>
<if test="createUser != null and createUser != ''">create_user,</if>
create_time
)values(
<if test="title != null and title != ''">#{title},</if>
<if test="imgPath != null and imgPath != ''">#{imgPath},</if>
<if test="url != null and url != ''">#{url},</if>
<if test="sort != null and sort != ''">#{sort},</if>
<if test="place != null and place != ''">#{place},</if>
<if test="provinceId != null and provinceId != ''">#{provinceId},</if>
<if test="cityId != null and cityId != ''">#{cityId},</if>
<if test="createUser != null and createUser != ''">#{createUser},</if>
sysdate()
)
</insert> <select id="findSize" resultType="long">
select count(1) from advertisement
</select> <select id="selectStatus" resultType="Integer">
select adv_flag from advertisement where id = #{arg0}
</select> <select id="selectId" parameterType="Advertisement" resultMap="AdvertisementResult">
select * from advertisement where id = #{arg0}
</select> <update id="updates" parameterType="Advertisement">
update advertisement
<set>
<if test="title != null and title != ''">title = #{title},</if>
<if test="imgPath != null and imgPath != ''">img_path = #{imgPath},</if>
<if test="url != null and url != ''">url = #{url},</if>
<if test="description != null and description != ''">description = #{description},</if>
<if test="sort != null and sort != 0">sort = #{sort},</if>
<if test="place != null and place != 0">place = #{place},</if>
<if test="cityId != null and cityId != ''">city_id = #{cityId},</if>
<if test="updateUser != null and updateUser != 0">update_user = #{updateUser},</if>
update_time = sysdate()
</set>
where id = #{id}
</update> <select id="selectProvinceId" resultType="String">
select parent_id from areas where id = #{arg0}
</select> <select id="modifyStatus" resultType="Integer">
select adv_flag from advertisement where id = #{arg0}
</select> <update id="modifyOFF">
update advertisement set adv_flag = 1 where id = #{arg0}
</update> <update id="modifyNO">
update advertisement set adv_flag = 0 where id = #{arg0}
</update> <delete id="delete" parameterType="String">
delete from advertisement where id = #{arg0}
</delete> </mapper>
Mybatis常用xml的更多相关文章
- Mybatis 常用注解
Mybatis常用注解对应的目标和标签如表所示: 注解 目标 对应的XML标签 @CacheNamespace 类 <cache> @CacheNamespaceRef 类 <cac ...
- SpringBoot整合Mybatis之xml
SpringBoot整合Mybatis mybatis ORM框架.几个重要的概念: Mapper配置 : 可以使用基于XML的Mapper配置文件来实现,也可以使用基于Java注解的Mybatis注 ...
- MyBatis Mapper XML 详解
MyBatis Mapper XML 详解 MyBatis 真正的力量是在映射语句中.这里是奇迹发生的地方.对于所有的力量,SQL 映射的 XML 文件是相当的简单.当然如果你将它们和对等功能的 JD ...
- MyBatis - 常用标签与动态Sql
MyBatis常用标签 ● 定义sql语句:select.insert.delete.update ● 配置JAVA对象属性与查询结构及中列明对应的关系:resultMap ● 控制动态sql拼接:i ...
- Mybatis系列全解(四):全网最全!Mybatis配置文件XML全貌详解
封面:洛小汐 作者:潘潘 做大事和做小事的难度是一样的.两者都会消耗你的时间和精力,所以如果决心做事,就要做大事,要确保你的梦想值得追求,未来的收获可以配得上你的努力. 前言 上一篇文章 <My ...
- Mybatis的xml配置(mybatis-config.xml)精简笔记
老规矩,看着官方文档学 首先,我们需要知道的是,在MyBatis 的xml配置文件中,这些影响 MyBatis 行为的属性之间的设置是有先后顺序的.配置的先后顺序依照properties, setti ...
- MyBatis Mapper.xml文件中 $和#的区别
MyBatis Mapper.xml文件中 $和#的区别 网上有很多,总之,简略的写一下,作为备忘.例子中假设参数名为 paramName,类型为 VARCHAR . 1.优先使用#{paramN ...
- mybatis 与 xml
mybatis的两大重要组件:配置和映射文件,都是可以通过xml配置的(新版本新增了注解的方式配置Mapper),下面来解析下mybatis是怎么做的 其中,关于配置文件解析的主要是在这个类XMLCo ...
- springboot使用之二:整合mybatis(xml方式)并添加PageHelper插件
整合mybatis实在前面项目的基础上进行的,前面项目具体整合请参照springboot使用之一. 一.整合mybatis 整合mybatis的时候可以从mybatis官网下载mybatis官网整合的 ...
随机推荐
- 由Asp.Net客户端控件生成的服务器端控件
由Asp.Net客户端控件生成的服务器端控件(也就是给客户端控件添加 runnat="server"),这样的控件既能在js中通过id命.类名获取到,也能在服务器端根据id获取到
- day002-List类、泛型
1. 集合 集合是容器,可以存储任意类型的数据,集合的长度可变. 1.1 集合和数组的比较 1.2 集合分类 单列集合:每次存储时,存储一个元素(Collection),包括:list.set 双列集 ...
- 双击易语言没有反应,按住shift再双击可解决
参考资料:http://tieba.baidu.com/p/2987732743 的7楼.
- MySQL入门很简单: 15 java访问MySQL数据库
1. 连接数据库 1.1 下载安装驱动 java通过JDBC(Java Database Connectivity,Java数据库连接)来访问MySQL数据库.JDBC的编程接口提供的接口和类与MyS ...
- 那些年我用过的SAP IDE
在Google上根据关键字"程序员鄙视链"搜索,会得到68多万条结果. 玲琅满目的搜索结果里是众多不同维度划分的鄙视链. 其中有一个维度,就是编程工具的鄙视链,比如: 而我在SAP ...
- python 字符串部分总结
字符串 对于单个字符的编码,Python提供了ord()函数获取字符的整数表示,chr()函数把编码转换为对应的字符 >>> ord('A') 65 >>> ord ...
- CRUD全栈式编程架构之MVC的扩展设计
MVC执行流程 路由的扩展 我理解的路由作用有以下几个 Seo优化,用“/”分开的url爬虫更爱吃 物理和逻辑文件分离,url不再按照文件路径映射 Controller,Action的选择 MVC路由 ...
- eclipse快捷键(个人经常使用的)
周末闲来无聊,就把一直以来eclipse使用的快捷键梳理了下,希望对有需要的朋友有所帮助,绝对原创! 1.快速复制一行或者多行 首先选中你要复制的行,如果是一行,则鼠标焦点在那一行即可,如果是多行,可 ...
- HDU(4394),数论上的BFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4394 思路很巧妙,要找到m,可以这样思考,n的个位是有m的个位决定的,从0-9搜一遍,满足情况的话就继 ...
- node.js 下使用 util.inherits 来实现继承
上一篇博客说到了node.js继承events类实现事件发射和事件绑定函数,其中我们实现了一个公用基类 _base ,然后在模型中差异化的定义了各种业务需要的模型并继承 _base 公共基类.但是其中 ...