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 的时候,都知 ...
随机推荐
- Implement Queue by Two Stacks
As the title described, you should only use two stacks to implement a queue's actions. The queue sho ...
- linux系统启动自动激活网卡的解决方法
linux每次启动的时候网卡都需要激活才能上网,实在是很麻烦. 上网找了找资料,最后是这样解决的: # vi /etc/sysconfig/network-scripts/ifcfg-eth0 ...
- Codeforces Round #286 (Div. 2) B 并查集
B. Mr. Kitayuta's Colorful Graph time limit per test 1 second memory limit per test 256 megabytes in ...
- php使用 SImpleXMLElement 把 xml 和 数组 互转
<?php $xml = <<<XML <xml> <ToUserName><![CDATA[toUser]]></ToUserNam ...
- grafana模板
1.安静了这么久,换了一家公司,还有过年,去了上海,去了苏州,去了杭州,认识了一个人,跟老司机他们一起学k8s,所以很累很累,这是监控,也是在老司机的帮助下熟悉使用,3q!
- Linux常用网络工具:fping主机扫描
Linux下有很多强大网络扫描工具,网络扫描工具可以分为:主机扫描.主机服务扫描.路由扫描等. fping是一个主机扫描工具,相比于ping工具可以批量扫描主机. fping官方网站:http://f ...
- tp between
$a = array( 'time' => array('between',[c,d]) ); c<= time <= d
- 题解 UVA1184 【Air Raid】
有向无环图(DAG)的最小路径覆盖的模板题. 定义:在一个有向图中,找出最少的路径,使得这些路径经过了所有的点. 由题意可得这是一个有向图,而路径不能相交,于是我们知道这是无向图的不相交最小路径覆盖问 ...
- tomcat maven插件启动报错tomcat-users.xml cannot be read
tomcat maven插件启动报错tomcat-users.xml cannot be read [ERROR] Failed to execute goal org.codehaus.mojo:t ...
- libuv在mingw下编译
libuv是一个基于事件的异步IO库,来自node.js项目. libuv提供了Makefile.mingw,供MingW编译,由其中的规则我们可以得到一下编译步骤: cd libuv/src gcc ...