工作模板-----MySQL示例
<?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">
<!--
//namespace属性值是dao层 maper接口文件的项目路径
1.id的属性值表示接口中的方法名
2.resultType 表示返回的类型,如果有返回类型,一定要书写。
如果返回的类型是单列集合类型,那么这里书写List集合的泛型类型
这里要书写类的全名,如果在核心配置文件中配置了别名那么只数写别名即可
typeAliases package name="com.sh.pojo" 别名和类名一致,不区分大小写
-->
<mapper namespace="com.sheca.ent.auth.entauthservice.dao.BusLicenseMapper">
<select id="selectStatusById" parameterType="java.lang.String"
resultType="com.sheca.ent.auth.entauthservice.vo.QueryBusLicModel">
SELECT
t.status as "status",
t.bizid as "bizId",
t.ent_name as "entName",
t.credit_num as "creditNum",
t.remark as "remark"
from
tb_ent_business_verify t
WHERE
bizid = #{bizId}
</select>
<update id="updateBusLicInfo" parameterType="com.sheca.ent.auth.entauthservice.entity.BusLicenseEntity">
update tb_ent_business_verify
<set>
<if test="entName != null and entName != ''">ent_name=#{entName},</if>
<if test="creditNum != null and creditNum != ''">credit_num=#{creditNum},</if>
<if test="status != null">status=#{status},</if>
//时间不需要判空字符
<if test="updateTime != null">updateTime=#{updateTime},</if>
<if test="legalName != null and legalName != ''">legal_name=#{legalName},</if>
<if test="legalIdnum != null and legalIdnum != ''">legal_idnum=#{legalIdnum},</if>
<if test="remark != null and remark != ''">remark=#{remark},</if>
</set>
where qrcode_id = #{qrcodeId}
</update>
<insert id="save" parameterType="com.sheca.ent.auth.entauthservice.entity.BusLicenseEntity">
insert into tb_ent_business_verify
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="bizId != null">bizid,</if>
<if test="entName != null and entName != ''">ent_name,</if>
<if test="status != null">status,</if>
<if test="qrcodeId != null and qrcodeId != ''">qrcode_id,</if>
<if test="createTime != null">create_time,</if>
<if test="creditNum != null and creditNum != ''">credit_num,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="bizId != null">#{bizId},</if>
<if test="entName != null and entName != ''">#{entName},</if>
<if test="status != null">#{status},</if>
<if test="qrcodeId != null and qrcodeId != ''">#{qrcodeId},</if>
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
<if test="creditNum != null and creditNum != ''">#{creditNum},</if>
</trim>
</insert>
//执行顺序
<select id="selectBusByQrcode" parameterType="java.lang.String"
resultType="com.sheca.ent.auth.entauthservice.dto.BusLicDto">
SELECT
t.ent_name as "entName",
t.credit_num as "creditNum"
from
tb_ent_business_verify t
WHERE
qrcode_id = #{qrCodeid} and
like %2%
GROUP BY entName
having ent_name = #{entName}
ORDER BY
create_time DESC
LIMIT 1 5
</select>
//模糊查询 区间查询
<select id="selectVerifyInfo" parameterType="com.sheca.ent.auth.entauthservice.vo.QueryVerifyResultVO"
resultType="com.sheca.ent.auth.entauthservice.entity.ManualVerifyEntity">
SELECT
ent_name as "entName",
app_id as "appid",
app_name as "appName",
status as "status",
biz_id as "bizid",
create_time as "createTime"
from
tb_ent_manual_verify
<where>
<if test="status != null and status != ''">status=#{status}</if>
<if test="entName != null and entName != ''">
AND ent_name like CONCAT('%',#{entName},'%')
</if>
<if test="appName != null and appName != ''">
AND app_name like CONCAT('%',#{appName},'%')
</if>
<if test="creditNum != null and creditNum != ''">AND credit_num=#{creditNum}</if>
<if test="beginTime != null and endTime != null">AND create_time between #{beginTime} and #{endTime}</if>
</where>
</select>
//多分支结构 多个when只执行一个。如果输入了用户名则按照用户名模糊查找,
否则就按照住址查找,多个条件只能成立一个,
如果都不输入就查找用户名为“孙悟空”的用户。
<select id="queryUserByUsernameAndAddr" resultType="User">
select * from user where sex='男'
<choose>
<!--<when test="username!=null and username.trim()!=''">
and user_name like '%${username}%'
</when>-->
<when test="username!=null and username.trim()!=''">
and user_name like concat('%',#{username},'%')
</when>
<when test="address!=null and address.trim()!=''">
and address =#{address}
</when>
<otherwise>
and user_name ='孙悟空'
</otherwise>
</choose>
</select>
//循环 key=and device_no 采用拼接的方式形成sql语句
<select id="listLicenseCode" parameterType="java.util.Map"
resultMap="LicenseCodeVO">
-- select
-- a.active_code,a.status,a.app_id,a.device_id,a.active_time,a.create_time,a.create_user,a.update_time,a.update_user,
-- d.device_id,d.device_name,d.version,d.mac_address,d.create_time,d.create_user
-- from tb_active_code a
-- left join tb_device_info d on a.device_id = d.device_id
<include refid="selectLicenseCodeVO"/>
<where>
<foreach collection="_parameter" item="tm" index="key">
<if test='tm != null and tm.toString().trim() != ""'>
${key} #{tm}
</if>
</foreach>
</where>
</select>
//循环一个id匹配多个值
<delete id="batchDeleteLicenseCode" parameterType="java.lang.Long">
DELETE FROM tb_license_code WHERE id IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectVerifyInfo" resultType="com.sheca.ent.auth.entauthservice.entity.ManualVerifyEntity">
SELECT
ent_name as "entName",
app_id as "appid",
app_name as "appName",
status as "status",
biz_id as "bizid",
create_time as "createTime"
from
tb_ent_manual_verify
where id=#{Id} and article_id in (
<foreach collection="collections" item = "item" separator = ",">
#{item}
</foreach>
)
</select >
//循环插入
<insert id="selectVerifyInfo">
insert into tb_ent_manual_verifyc (entry_id,article_id,create_time) values
<foreach collection="collections" item = "item" separator = ",">
(#{entryId},#{articleId},now())
</foreach>
//循环 key=and device_no 采用拼接的方式形成sql语句
<resultMap id="DeviceInfoVO" type="DeviceInfo">
<id property="id" column="id"/>
<result property="deviceId" column="device_id"/>
<result property="deviceName" column="device_name"/>
<result property="version" column="version"/>
<result property="macAddress" column="mac_address"/>
<result property="serialNo" column="serial_no"/>
<result property="createTime" column="d.create_time"/>
<result property="createUser" column="d.create_user"/>
</resultMap>
<sql id="selectLicenseCodeVO">
select a.id,
a.license_code,
a.status,
a.app_id,
a.device_id,
a.begin_time,
a.end_time,
a.valid_date,
a.create_time,
a.create_user,
a.batch
from tb_license_code a
</sql>
<select id="listDeviceInfo" parameterType="java.util.Map"
resultMap="DeviceInfoVO">
<include refid="selectDeviceInfoVO"></include>
<where>
<foreach collection="_parameter" item="tm" index="key">
<if test='tm != null and tm.toString().trim() != ""'>
${key} #{tm}
</if>
</foreach>
</where>
</select>
//一对多
<select id="queryOneToMany" resultMap="oneToMany">
SELECT
tbo.id AS oid,
tbo.user_id,
tbo.order_number,
tbu.id AS uid,
tbu.user_name,
tbu. PASSWORD,
tbu. NAME,
tbu.age,
tbu.sex
FROM
tb_user AS tbu
INNER JOIN tb_order AS tbo ON tbu.id = tbo.user_id
WHERE
tbu.id = #{id}
</select>
//多对多
<select id="queryManyToMany" resultMap="manyToMany">
SELECT
tbo.id AS oid,
tbo.user_id,
tbo.order_number,
detail.id AS did,
detail.order_id,
detail.item_id,
detail.total_price,
detail. STATUS,
item.id AS iid,
item.item_name,
item.item_price,
item.item_detail
FROM
tb_order AS tbo
INNER JOIN tb_orderdetail AS detail ON tbo.id = detail.order_id
INNER JOIN tb_item AS item ON detail.item_id = item.id
WHERE
tbo.order_number = #{orderNumber}
</select>
<select id="queryManyToMany2" resultMap="manyToMany2">
SELECT
tbo.id AS oid,
tbo.user_id,
tbo.order_number,
detail.id AS did,
detail.order_id,
detail.item_id,
detail.total_price,
detail. STATUS,
item.id AS iid,
item.item_name,
item.item_price,
item.item_detail,
tbu.id AS uid,
tbu.user_name,
tbu. PASSWORD,
tbu. NAME,
tbu.age,
tbu.sex
FROM
tb_order AS tbo
INNER JOIN tb_orderdetail AS detail ON tbo.id = detail.order_id
INNER JOIN tb_item AS item ON detail.item_id = item.id
INNER JOIN tb_user AS tbu ON tbo.user_id = tbu.id
WHERE
tbo.order_number = #{orderNumber}
</select>
//分页 前面穿过来什么字段根据什么字段查询 字段涉及到四张表
//难点 多个join不能完全使用字段匹配不上多表查询实现不了 多个区间查询不在一张表上
//exists关键字 判断子查询能否查到数据 根据字段查到数据返回true 说明有数据 反之false
<select id="queryList" parameterType="com.sheca.order.orderservice.dto.req.OrderListVO"
resultType="com.sheca.order.orderservice.dto.resp.OrderListResp">
SELECT
t.order_id AS "orderNo",
t.create_time AS "createTime",
t.order_amount AS "amount",
t.order_status AS "orderStatus",
t.pay_time AS "payTime",
t.pay_status AS "payStatus",
t.invoice_status AS "invoiceStatus",
info.app_name as "appName"
FROM
tb_order t ,tb_app_info info where t.app_id=info.app_id
<if test="orderNo != null and orderNo != ''">AND t.order_id=#{orderNo}</if>
<if test="orderStatus != null and orderStatus != ''">AND t.order_status=#{orderStatus}</if>
<if test="payStatus != null and payStatus != ''">AND t.pay_status=#{payStatus}</if>
<if test="invoiceStatus != null and invoiceStatus != ''">AND t.invoice_status=#{invoiceStatus}</if>
<if test="beginPayTime != null and endPayTime != null">AND t.pay_time between #{beginPayTime} and #{endPayTime}</if>
<if test="maxAmount != null and minAmount != null">AND t.order_amount between #{minAmount} and #{maxAmount}</if>
<if test="beginCreateTime != null and endCreateTime != null">AND t.create_time between #{beginCreateTime} and #{endCreateTime}</if>
<if test="appName != null and appName != ''">AND info.app_name like CONCAT('%',#{appName},'%')</if>
<if test="(merchId != null and merchId != '') or (name != null and name != '') or ((endMinTime != null ) or (endMaxTime != null )) or (beginMinTime != null ) or (beginMaxTime != null )">
and exists (select * FROM tb_order_detail tod where t.order_id = tod.order_id
<if test="merchId != null and merchId != ''">AND tod.merch_id=#{merchId}</if>
<if test="name != null and name != ''">AND tod.name like CONCAT('%',#{name},'%')</if>
<if test="merchName != null and merchName != ''">AND tod.merch_name like CONCAT('%',#{merchName},'%')</if>
<if test="endMinTime != null">AND tod.end_time>=#{endMinTime}</if>
<if test="endMaxTime != null">AND tod.end_time<#{endMaxTime}</if>
<if test="beginMinTime != null">AND tod.begin_time>=#{beginMinTime}</if>
<if test="beginMaxTime != null">AND tod.begin_time<#{beginMaxTime}</if>
)
</if>
<if test="(payWay != null and payWay != '') or (transNo != null and transNo != '') or (thirdTransNo != null and thirdTransNo != '')">
and exists (select * FROM tb_order_pay top where t.order_id = top.order_id
<if test="payWay != null and payWay != ''">AND top.pay_way=#{payWay}</if>
<if test="transNo != null and transNo != ''">AND top.trans_id=#{transNo}</if>
<if test="thirdTransNo != null and thirdTransNo != ''">AND top.third_trans_id=#{thirdTransNo}</if>
)
</if>
</select>
<select id="selectExportOrder" parameterType="com.sheca.order.orderservice.dto.req.OrderListVO"
resultType="com.sheca.order.orderservice.dto.resp.OrderExportResp">
SELECT
info.app_name as "appName",
d.order_id AS "orderNo",
t.create_time AS "createTime",
t.order_amount AS "amount",
t.order_status AS "orderStatus",
(select p.trans_id from tb_order_pay p where t.order_id=p.order_id and p.resp_code = '0' limit 1) AS "transNo",
(select p.pay_way from tb_order_pay p where t.order_id=p.order_id and p.resp_code = '0' limit 1) AS "payWay",
(select p.third_trans_id from tb_order_pay p where t.order_id=p.order_id and p.resp_code = '0' limit 1) AS "thirdTransNo",
t.pay_time AS "payTime",
t.pay_status AS "payStatus",
d.merch_name AS "merchName",
d.business_type AS "businessType",
d.price AS "price",
d.merch_sn AS "merchSn",
d.name AS "name",
d.card_no AS "cardNo",
d.begin_time AS "beginTime",
d.end_time AS "endTime",
t.invoice_status AS "invoiceStatus"
FROM
tb_order_detail d,
tb_order t,
tb_app_info info
where
t.app_id=info.app_id AND d.order_id=t.order_id
<if test="orderNo != null and orderNo != ''">AND d.order_id=#{orderNo}</if>
<if test="appName != null and appName != ''">AND info.app_name like concat('%',#{appName},'%')</if>
<if test="invoiceStatus != null and invoiceStatus != ''">AND invoice_status=#{invoiceStatus}</if>
<if test="beginPayTime != null">AND t.pay_time>=#{beginPayTime}</if>
<if test="endPayTime != null">AND t.pay_time<=#{endPayTime}</if>
<if test="beginCreateTime != null">AND t.create_time>=#{beginCreateTime}</if>
<if test="endCreateTime != null">AND t.create_time<=#{endCreateTime}</if>
<if test="minAmount != null and minAmount != ''">AND t.order_amount>=#{minAmount}</if>
<if test="maxAmount != null and maxAmount != ''">AND t.order_amount<=#{maxAmount}</if>
<if test="orderStatus != null and orderStatus != ''">AND t.order_status=#{orderStatus}</if>
<if test="payStatus != null and payStatus != ''">AND t.pay_status=#{payStatus}</if>
<if test="merchId != null and merchId != ''">AND d.merch_id=#{merchId}</if>
<if test="name != null and name != ''">AND d.name like CONCAT('%',#{name},'%')</if>
<if test="cardNo != null and cardNo != ''">AND d.card_no=#{cardNo}</if>
<if test="beginMinTime != null">AND d.begin_time>=#{beginMinTime}</if>
<if test="beginMaxTime != null">AND d.begin_time<=#{beginMaxTime}</if>
<if test="endMinTime != null">AND d.end_time>=#{endMinTime}</if>
<if test="endMaxTime != null">AND d.end_time<=#{endMaxTime}</if>
<if test="invoiceStatus != null and invoiceStatus != ''">AND invoice_status=#{invoiceStatus}</if>
<if test="(payWay != null and payWay != '') or (transNo != null and transNo != '') or (thirdTransNo != null and thirdTransNo != '')">
and exists (select * FROM tb_order_pay top where t.order_id = top.order_id and top.resp_code = '0'
<if test="payWay != null and payWay != ''">AND top.pay_way=#{payWay}</if>
<if test="transNo != null and transNo != ''">AND top.trans_id=#{transNo}</if>
<if test="thirdTransNo != null and thirdTransNo != ''">AND top.third_trans_id=#{thirdTransNo}</if>
)
</if>
</select>
</mapper>
工作模板-----MySQL示例相关推荐
- MySQL 示例数据库 employees 的导入与使用
导入 MySQL 示例数据库 employees 本博客记录将 employees.db 数据库导入本地 MySQL 数据库中. 文章目录 导入 MySQL 示例数据库 employees 1. 导入 ...
- 工作中MySql的了解到的小技巧
工作中MySql的小技巧 1. 跑脚本时,经常遇到有则更新无插入的 逻辑操作:通常情况下,来一波if()判断然后选择 更新还是插入,前两天逛论坛时发现有人在比较REPLACE INTO 和 INSET ...
- 安装MySQL示例 docker pull mysql
安装MySQL示例 docker pull mysql 错误的启动 docker run --name mysql01 -d mysql 正确的启动 docker run --name mys ...
- python3图片转代码_python3图片转换二进制存入mysql示例代码
python3图片转换二进制存入mysql示例代码 发布于 2014-09-29 18:00:01 | 198 次阅读 | 评论: 0 | 来源: 网友投递 Python编程语言Python 是一种面 ...
- Python MySQL示例教程
Welcome to Python MySQL example tutorial. MySQL is one of the most widely used database and python p ...
- 工作模板文档实践整理
学习上要善于积累人非生而知之,而是学而知之,行而知之.学习,实践是获取知识的唯一途径,是成才的必由之路.学习是个日积月累的过程.善于积累,是提高个人素质的重要环节.古人说:"积土成山,风雨兴 ...
- Python操作Excel工作簿的示例代码(.xlsx)
前言 Excel 作为流行的个人计算机数据处理软件,混迹于各个领域,在程序员这里也是常常被处理的对象,可以处理 Excel 格式文件的 Python 库还是挺多的,比如 xlrd.xlwt.xluti ...
- MySQL示例数据库sakila-db的安装导入
MySQL示例数据库sakila-db的安装导入 sakila库是一个MySQL官方提供的模拟电影出租厅信息管理系统的数据库,类似于Oracle的scott库,sakila库的下载地址为:htt ...
- 华为 静态NAT---动态NAT---NAPT---Easy IP---NAT服务器工作原理和示例配置
目 录 一.NAT简介 二.NAT好处: 三.静态NAT工作原理和示例配置 1. 静态NAT工作原理 2. 静态NAT配置示例 四.动态NAT工作原理和示例配置 1. 动态NAT工作原理 2.动 ...
- 子模板继承父模板示例_模板设计模式示例
子模板继承父模板示例 本文是我们名为" Java设计模式 "的学院课程的一部分. 在本课程中,您将深入研究大量的设计模式,并了解如何在Java中实现和利用它们. 您将了解模式如此重 ...
最新文章
- ubuntu14.04 LTS 更新源
- 计算机二级的考试c模板,2013年9月全国计算机等级《二级C++》上机模考试卷(5)
- saturate_cast<uchar>(int v)的作用
- (Lesson2)根据类名称和属性获得元素-JavaScript面向对象
- Linux操作系统-命令-free
- 总结redis中对象的类型与编码
- Vue2.x总结(1)
- 最大隶属度原则_商圈广告精准投放,请牢记这四大黄金原则!
- 百度推出完全端到端的并行音频波形生成模型,比WaveNet快千倍 | 论文
- libevent源码分析系列
- win10 桌面设置为远程桌面
- java 调用 easypr_EasyPR-Java项目maven版本所需jar包
- 英语国际音标发音——见标能读
- 计算机录制视频的方法,怎么录制电脑屏幕视频步骤(电脑录屏的方法有4种)...
- UFS系列六:UFS设备初始化和启动
- PYMOL-note
- 招投标过程---投标之述标 大杂烩
- 牛客网力扣算法编程之十四 | 字符串 - 字符个数统计 - Java代码实现
- 微信网页长按二维码不识别问题
- 行政和IT人员为什么需要一款固定资产管理系统?