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官网整合的 ...
随机推荐
- C#实现屏幕指定区域截屏
//string Opath = @"C:/Picture"; //if (Opath.Substring(Opath.Length - 1, 1) != @ ...
- python 输出奇偶数并排序
random_numbers = [] for i in range(40): random_numbers.append(random.randint(1, 100)) num1 = [] num2 ...
- 谁动了我的I/O?
首先,是信用卡账单欠款0.13美刀~~~然后上亚马逊云查了一下账单. 3M次I/O...(1215133次超额的,2000000次免费的.) 于是监控了一下数据:每秒至少写5次,每秒写300KB,平均 ...
- SVN建立分支、代码合并以及常用操作
在项目开发的过程中,现在遇到这样一个问题: 现在是9月份,在同一个项目中我要开发A.B两个模块,A模块是11月份上线,B模块是12月份上线,但是SVN上的trunk(主干)上的代码必须是上线的. 假设 ...
- SQL的注入式攻击方式和避免方法
SQL 注入是一种攻击方式,在这种攻击方式中,恶意代码被插入到字符串中,然后将该字符串传递到 SQL Server 的实例以进行分析和执行.任何构成 SQL 语句的过程都应进行注入漏洞检查,因为 SQ ...
- 【CCPC-Wannafly Winter Camp Day3 (Div1) F】小清新数论(莫比乌斯反演+杜教筛)
点此看题面 大致题意: 让你求出\(\sum_{i=1}^n\sum_{j=1}^n\mu(gcd(i,j))\). 莫比乌斯反演 这种题目,一看就是莫比乌斯反演啊!(连莫比乌斯函数都有) 关于莫比乌 ...
- 怎样在 Ubuntu Linux 上安装 MySQL
本教程教你如何在基于 Ubuntu 的 Linux 发行版上安装 MySQL.对于首次使用的用户,你将会学习到如何验证你的安装和第一次怎样去连接 MySQL. -- Sergiu MySQL 是一个典 ...
- 问题 A: E2 驾驭const
题目描述 引入了const关键词,用于指定“常”对象及“常”对象成员,提供了对数据的一种保护机制,这C++语言的特色之一.但由此,也引出了一些语法上的要求.这些语法要求,实际上有一套完善的原则,需要熟 ...
- 20145238-荆玉茗 《Java程序设计》实验三
20145238-荆玉茗-实验三 实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法应用到软件的开发.运营 ...
- Intel MKL 多线程设置
对于多核程序,多线程对于程序的性能至关重要. 下面,我们将对Intel MKL 有关多线程方面的设置做一些介绍: 我们提到MKL 支持多线程,它包括的两个概念:1>MKL 是线程安全的: MKL ...