工作中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. ansible使用3-playbook

    playbook是ansible用于配置部署的语言.使用YAML格式. 示例 --- - hosts: webservers vars: http_port: 80 max_clients: 200 ...

  2. JavaMail 的简单使用

    概述 邮件功能模块在大多数网站中,都是必不可少的功能模块.无论是用户注册还是重置密码,邮件都是比较常用的一个方式.本文主要介绍 JavaMail 的简单使用,方便大家快速开发,供大家参考.完整的 de ...

  3. vim复制粘贴到系统剪贴板

    一般来讲,如果你没有在.vimrc中配置过相关的信息的话,可以考虑下面的方法.系统环境 Ubuntu 14.04 LTS. 安装与使用 首先需要安装一个vim-gtk 命令$sudo apt-get ...

  4. 实例详解Django的 select_related

    在数据库有外键的时候,使用 select_related() 和 prefetch_related() 可以很好的减少数据库请求的次数,从而提高性能.本文通过一个简单的例子详解这两个函数的作用.虽然Q ...

  5. 贪心,二叉树搜索,ZOJ(2315)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1315 解题报告: #include <stdio.h> ...

  6. java常用输出技巧,debug

    package control; import javax.swing.JFrame; public class DebugTest { public static void main(String[ ...

  7. vuejs样式绑定

    第一种:class的对象绑定,class引用的是一个对象,这个对象的属性显示不显示由变量决定 <style> .activated{ color:red; } </style> ...

  8. CentOS6.5 配置IP的两种方式

    1.dhcp动态获取ip 编辑配置文件 /etc/sysconfig/network-scripts/ifcfg-eth0 ,配置如下: [root@localhost ~]# vi /etc/sys ...

  9. using System.Security.Cryptography

    这个命名空间主要是用来进行加密的一些类. 加密服务: 公共网络(如 Internet)不提供实体之间安全通信的方式. 此类网络上的通信易被读取或甚至被未经授权的第三方修改. 加密有助于防止数据被查看, ...

  10. 【Java】对象、类(抽象类与内部类)、接口

    博文内容概况 对象和类 抽象类 接口 内部类 对象和类 对象是对客观事物的抽象,类是对对象的抽象.类是一种数据类型,其外观和行为由用户定义.类中可以设置两种类型的元素:字段(有时被称为数据成员)和方法 ...