工作中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的更多相关文章

  1. Mybatis 常用注解

    Mybatis常用注解对应的目标和标签如表所示: 注解 目标 对应的XML标签 @CacheNamespace 类 <cache> @CacheNamespaceRef 类 <cac ...

  2. SpringBoot整合Mybatis之xml

    SpringBoot整合Mybatis mybatis ORM框架.几个重要的概念: Mapper配置 : 可以使用基于XML的Mapper配置文件来实现,也可以使用基于Java注解的Mybatis注 ...

  3. MyBatis Mapper XML 详解

    MyBatis Mapper XML 详解 MyBatis 真正的力量是在映射语句中.这里是奇迹发生的地方.对于所有的力量,SQL 映射的 XML 文件是相当的简单.当然如果你将它们和对等功能的 JD ...

  4. MyBatis - 常用标签与动态Sql

    MyBatis常用标签 ● 定义sql语句:select.insert.delete.update ● 配置JAVA对象属性与查询结构及中列明对应的关系:resultMap ● 控制动态sql拼接:i ...

  5. Mybatis系列全解(四):全网最全!Mybatis配置文件XML全貌详解

    封面:洛小汐 作者:潘潘 做大事和做小事的难度是一样的.两者都会消耗你的时间和精力,所以如果决心做事,就要做大事,要确保你的梦想值得追求,未来的收获可以配得上你的努力. 前言 上一篇文章 <My ...

  6. Mybatis的xml配置(mybatis-config.xml)精简笔记

    老规矩,看着官方文档学 首先,我们需要知道的是,在MyBatis 的xml配置文件中,这些影响 MyBatis 行为的属性之间的设置是有先后顺序的.配置的先后顺序依照properties, setti ...

  7. MyBatis Mapper.xml文件中 $和#的区别

    MyBatis Mapper.xml文件中 $和#的区别   网上有很多,总之,简略的写一下,作为备忘.例子中假设参数名为 paramName,类型为 VARCHAR . 1.优先使用#{paramN ...

  8. mybatis 与 xml

    mybatis的两大重要组件:配置和映射文件,都是可以通过xml配置的(新版本新增了注解的方式配置Mapper),下面来解析下mybatis是怎么做的 其中,关于配置文件解析的主要是在这个类XMLCo ...

  9. springboot使用之二:整合mybatis(xml方式)并添加PageHelper插件

    整合mybatis实在前面项目的基础上进行的,前面项目具体整合请参照springboot使用之一. 一.整合mybatis 整合mybatis的时候可以从mybatis官网下载mybatis官网整合的 ...

随机推荐

  1. centos6.5_64bit-Tomcat7安装部署

    此次安装系统版本及软件版本 centos6.5-64bit java -1.7.0_45 jdk1.8.0_111 apache-tomcat-7.0.73   一.检查java版本信息        ...

  2. Ubuntu Deb包安装<个人笔记>

    安装 删除 卸载 Deb 包文件   图形界面: 安装deb 直接双击图标,输入密码后就可自动安装. 卸载deb 1. 菜单-系统->系统管理->新立得软件包管理器 或 Alt+F2(运行 ...

  3. 重写KVC

    #import "NSObject+WQKVC.h" #import <objc/runtime.h> /** KVC 首先调用的方法顺序: |- setter: se ...

  4. flexslider 图片轮播插件参数

    $(window).load(function() { $('.flexslider').flexslider({ animation: "fade", //String: Sel ...

  5. loss 和accuracy的关系梳理

    最近打算总结一下这部分东西,先记录留个脚印.

  6. fcc初级算法方法总结

    var arr = str.split("分隔符"): var newArr = arr.reverse(); var str = arr.join("连接符" ...

  7. Java日志框架介绍

    一.序言 日志为系统的必不可少的一部分,通过输出的日志我们可以排查线上出现的各种问题,就像断案的线索一样.我们还可以通过日志数据分析用户的行为习惯做大数据分析. 二.日志框架分类及其历史 框架的种类: ...

  8. Excle 常用函数

    1. 查找函数VLOOKUP 使用示例: =VLOOKUP(A1,$C$1:$D$19,2,0) 表示以A1单元格为基准,匹配C1开始到D19的范围数据,在公式行显示D单元格文本,也就是匹配范围的第二 ...

  9. 关于 Angular引用Material出现node_modules/@angular/material/button-toggle/typings/button-toggle.d.ts(154,104): error TS2315: Type 'ElementRef' is not generic.问题

    百度了好久 ,,,最后谷歌出来了.. 该错误可能来自于您将@ angular / material设置为6.0.0, 但所有其他Angular包都是5.x.您应该始终确保Material主要版本与An ...

  10. MyEclipse的快捷键大全(超级实用,方便)

    常用快捷键 1. [ALT+/] 能为用户提供内容的辅助,不要为记不全方法和属性名称犯愁,当记不全类.方法和属性的名字时,多体验一下[ALT+/]快捷键带来的好处吧. 2. [Ctrl+O]  显示类 ...