Mybatis Common Mapper文件
表名/条件/字段 都可以传入进去
<?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="dao.CommonDao"> <!--通用删除-->
<delete id="delete" parameterType="map">
DELETE FROM ${tablename} where ${key}=#{value}
</delete> <!--通用更新-->
<update id="update" parameterType="map">
update ${tablename} set
<foreach collection="data.keys" item="key" separator=",">
<if test="null!=data[key]">
${key}=#{data[${key}]}
</if>
</foreach>
where 1=1
<foreach collection="conditions.keys" item="key" separator="and" open="and">
<if test="null!=conditions[key]">
${key}=#{conditions[${key}]}
</if>
</foreach>
</update> <!--查询表字段信息-->
<select id="getTableFieldInfo" parameterType="string" resultType="map">
select COLUMN_NAME,DATA_TYPE from user_tab_cols WHERE TABLE_NAME=#{0} ORDER BY COLUMN_ID
</select> <!--获取表字段-->
<select id="getTableField" parameterType="string" resultType="string">
select COLUMN_NAME from user_tab_cols WHERE TABLE_NAME=#{0} ORDER BY COLUMN_ID
</select> <!--通用插入方法-->
<insert id="insert" parameterType="map">
<selectKey keyProperty="id" resultType="integer" order="BEFORE">
select ${seq}.nextval from dual
</selectKey>
insert into ${tablename}
(id,
<foreach collection="map.keys" item="key" separator=",">
${key}
</foreach>
)
values
(#{id},
<foreach collection="map.values" item="value" separator=",">
#{value}
</foreach>
)
</insert> <!--一个条件的情况下,获取map返回值-->
<select id="getResultMapByCondition" parameterType="map" resultType="map">
select
<foreach collection="fields" item="field" separator=",">
${field}
</foreach>
from ${tablename} where
${con1}=#{val1}
</select> <!--两个条件的情况下,获取map返回值-->
<select id="getResultMapByConditions" parameterType="map" resultType="map">
select
<foreach collection="fields" item="field" separator=",">
${field}
</foreach>
from ${tablename}
where 1=1
<foreach collection="conditions.keys" item="key" separator="and" open="and">
<if test="null!=conditions[key]">
${key}=#{conditions[${key}]}
</if>
</foreach>
</select> <!--查询一个字段,根据多个条件-->
<select id="getResultObjectByConditions" parameterType="map" resultType="object">
select ${field} from ${tablename}
where 1=1
<foreach collection="conditions.keys" item="key" separator="and" open="and">
<if test="null!=conditions[key]">
${key}=#{conditions[${key}]}
</if>
</foreach>
</select> <!--查询一个字段-->
<select id="getResultObjectByCondition" parameterType="map" resultType="object">
select ${field} from ${tablename} where ${con} = #{val}
</select> </mapper>
Mybatis Common Mapper文件的更多相关文章
- MyBatis的Mapper文件的foreach标签详解
MyBatis的Mapper文件的foreach标签用来迭代用户传递过来的Lise或者Array,让后根据迭代来拼凑或者批量处理数据.如:使用foreach来拼接in子语句. 在学习MyBatis M ...
- 逆向工程生成的mybatis中mapper文件。mapper接口,实例化成对象
逆向工程生成的mybatis中mapper文件中,*mapper文件只是接口,而不是类文件.但是却可以通过spring的容器获得实例. 例如: //1.获得mapper代理对象,从spring容器获得 ...
- 自动生成Mybatis的Mapper文件
自动生成Mybatis的Mapper文件 工作中使用mybatis时我们需要根据数据表字段创建pojo类.mapper文件以及dao类,并且需要配置它们之间的依赖关系,这样的工作很琐碎和重复,myba ...
- mybatis写mapper文件注意事项(转)
原文链接:http://wksandy.iteye.com/blog/1443133 xml中某些特殊符号作为内容信息时需要做转义,否则会对文件的合法性和使用造成影响 < < > & ...
- Spring配置扫描mybatis的mapper文件注意:
一般会将不业务的mapper文件放到不同的包中: spring配置扫描就需要配置下面的方式(两个*): <!-- mybatis文件配置,扫描所有mapper文件 --> <bean ...
- mybatis的Mapper文件配置
一.resultMap resultMap 元素是 MyBatis 中最重要最强大的元素. 该配置节点下如下子节点配置 id – 一个 ID 结果;标记结果作为 ID 可以帮助提高整体效能 const ...
- mybatis的mapper文件的大于号特殊符号使用
第一种方法: 用了转义字符把>和<替换掉,然后就没有问题了. SELECT * FROM test WHERE 1 = 1 AND start_date <= CURRENT_DA ...
- 使用逆向工程生成mybatis的Mapper文件
之前有写过一篇博客: 使用MyBatis Generator自动生成MyBatis的代码链接:http://www.cnblogs.com/klslb/p/6908535.html 这个太麻烦了,而且 ...
- 【坑】解决maven管理SSM中mybatis的mapper文件扫描失败的问题
文章目录 前言 改进方式来替换原始的使用方式 后记 好久没有写博客了,11月底来到公司实习,上个月写个小demo,趁此回顾下SSM,今天将最近的积累记录下: 前言 在学习 mybatis 的时候,都知 ...
随机推荐
- PD模型创建完获取生成表脚本
1.双击表名,弹出属性对话框-->General----> Owner 表名前缀,如XX.SYS_TABLE 最好去掉 2.Preview 复制里面的脚本到数据库执行下即可
- 【HDU5919】SequenceII(主席树)
[HDU5919]SequenceII(主席树) 题面 Vjudge 翻译(by ppl) 给一个长度为N的数列A,有m个询问,每次问 数列[l,r]区间中所有数的第一次出现的位置的中位 数是多少 题 ...
- 【NOIP考试范围】
※号为可能考察的算法[历年有出现过,但概率小,但最好掌握] [本图片仅作参考] 梦想总是要有的,万一实现了呢?
- Zookeeper(三) Zookeeper原理与应用
一.zookeeper原理解析 1.进群角色描述 2.Paxos 算法概述( ZAB 协议) 分布式一致性算法 3.Zookeeper 的选主(恢复模式) 以一个简单的例子来说明整个选举的过程. ...
- Work at DP
转载请注明出处:http://www.cnblogs.com/TSHugh/p/8858805.html Prepared: (无notes的波兰题目的notes见我的波兰题目补全计划)BZOJ #3 ...
- laravel 5.1 单元测试 Cannot modify header information 错误
运行phpunit的时候加上参数 --stderr ./vendor/bin/phpunit --stderr
- advanced bash shell guide读书笔记
http://note.youdao.com/noteshare?id=fc23a679849b4627d131d3ef07c74a71
- OpenCV---膨胀与腐蚀
膨胀 腐蚀 一:膨胀实现dilate import cv2 as cv import numpy as np def dilate_demo(image): #膨胀 print(image.shape ...
- Spring Boot + Swagger
前言: 在互联网公司, 微服务的使用者一般分为两种, 客户端和其他后端项目(包括关联微服务),不管是那方对外提供文档 让别人理解接口 都是必不可少的.传统项目中一般使用wiki或者文档, 修改繁琐,调 ...
- 目前最快速的多线程Kmeans算法,java实现
目前最快速Kmeans算法,并由java实现!面对很大的K值表现依然很好. 代码地址: https://github.com/Jethu1/fastKmeans #1.这是一个由java实现的的,多线 ...