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官网整合的 ...
随机推荐
- centreon-engine 性能调优
http://documentation.centreon.com/docs/centreon-engine/en/latest/user/configuration/best_practice.ht ...
- [转]linux tcp/ip调优
LINUX tcp/ip性能调优 On 2011年03月15日, in linux, tips, by netoearth 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接 ...
- .net 控制器调用外部链接传参方法
public class RequestHelper { /// <summary> /// 发起post请求 /// </summary> /// <typeparam ...
- 用户管理的设计--4.jquery的ajax实现登录名的校验
页面效果 鼠标失去焦点时,不需要刷新页面进行校验,判断登录名是否重复. 实现步骤 1.引入struts2-json-plugin-2.5.10.1插件包 2.页面使用jquery的ajax实现后台校验 ...
- 笨办法学Python(六)
习题 6: 字符串(string)和文本 虽然你已经在程序中写过字符串了,你还没学过它们的用处.在这章习题中我们将使用复杂的字符串来建立一系列的变量,从中你将学到它们的用途.首先我们解释一下字符串是什 ...
- 如何处理Eclipse错误消息 The declared package does not match the expected package
我从github下载了一个开源项目后,导入到自己Eclipse之后,遇到了这个烦人的错误消息: The declared package "com.sap.smartService" ...
- SQL语句关于时间的查询小心得,希望大家给点意见
完全使用时间函数去搞定查询日期,之前写的可能有些问题,现在删了修正一下 本月记录: SELECT * FROM 表 WHERE datediff(month,[dateadd],getdate())= ...
- 使用 NetBackup 命令创建 Hyper-V 策略(命令创建其他策略也是如此)
Veritas NetBackup™ for Hyper-V 管理指南 Product(s): NetBackup (8.1) 使用 NetBackup 命令创建 Hyper-V 策略 本主题介绍如何 ...
- Java从入门到放弃——04.数组
本文目标 数组 1.数组 定义一个数组的三个姿势: 数组类型 [] 数组名 = new 数组类型[数组数量]: 数组类型 [] 数组名 = new 数组类型[]{对象1 ...
- 2017.9.25 JSP内置对象的概述
1.JSP的定义: 在JSP中是为了便于数据信息的存储.传递.获取,专门设置了九个内置对象, jsp内置对象是指他们是预先设定的,不需创建,每个对象都有自己的属性和方法. 2.JSP内置对象 对象名称 ...