com.starmcc.qmdata.mapper.QmDataMapper.xml Maven / Gradle / Ivy
<?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"> <!-- 全自动封装SQL --> <mapper namespace="QmBaseMapper"> <!-- 通用查询数据入口 --> <select id="selectList" resultType="map"> SELECT * FROM `${tableName}` WHERE 1 = 1 <if test="params != null and params.size != 0"> <foreach item="item" collection="params"> AND `${item.key}` = #{item.value} </foreach> </if> <if test="whereSql != null and whereSql != ''"> AND ${whereSql} </if> <if test="orderBy != null and orderBy != ''"> ORDER BY ${orderBy} </if> </select> <!-- 通用查询单数据入口 --> <select id="selectOne" resultType="map"> SELECT * FROM `${tableName}` WHERE 1 = 1 <if test="params != null and params.size != 0"> <foreach item="item" collection="params"> AND `${item.key}` = #{item.value} </foreach> </if> <if test="whereSql != null and whereSql != ''"> AND ${whereSql} </if> <if test="orderBy != null and orderBy != ''"> ORDER BY ${orderBy} </if> LIMIT 0,1 </select> <!-- 通用增加数据入口 --> <insert id="insert" parameterType="map"> INSERT INTO `${tableName}` ( <if test="primaryKey != null">`${primaryKey.key}`,</if> <if test="params != null and params.size != 0"> <foreach item="item" collection="params" separator=","> `${item.key}` </foreach> </if> ) VALUES( <if test="primaryKey != null">#{primaryKey.value},</if> <if test="params != null and params.size != 0"> <foreach item="item" collection="params" separator=","> #{item.value} </foreach> </if> ) </insert> <!-- 通用增加数据入口 --> <insert id="insertGetPrimaryKey" parameterType="map"> <selectKey resultType="Object" order="AFTER" keyProperty="INSERT_PRIMARY_MAP_KEY"> SELECT LAST_INSERT_ID() </selectKey> INSERT INTO `${tableName}` ( <if test="primaryKey != null">`${primaryKey.key}`,</if> <if test="params != null and params.size != 0"> <foreach item="item" collection="params" separator=","> `${item.key}` </foreach> </if> ) VALUES( <if test="primaryKey != null">#{primaryKey.value},</if> <if test="params != null and params.size != 0"> <foreach item="item" collection="params" separator=","> #{item.value} </foreach> </if> ) </insert> <!-- 通用更新数据入口 --> <update id="update"> UPDATE `${tableName}` SET <if test="params != null and params.size != 0"> <foreach item="item" collection="params" separator=","> `${item.key}` = #{item.value} </foreach> </if> WHERE `${primaryKey.key}` = #{primaryKey.value} <if test="whereSql != null and whereSql != ''"> AND ${whereSql} </if> </update> <!-- 通用删除数据入口 --> <delete id="delete"> DELETE FROM `${tableName}` WHERE 1 = 1 <if test="primaryKey != null"> AND `${primaryKey.key}` = #{primaryKey.value} </if> <if test="params != null and params.size != 0"> <foreach open="AND" item="item" collection="params" separator="AND"> `${item.key}` = #{item.value} </foreach> </if> <if test="whereSql != null and whereSql != ''"> AND ${whereSql} </if> </delete> <!-- 查询条数 --> <select id="selectCount" resultType="Integer"> SELECT COUNT(1) FROM `${tableName}` WHERE 1 = 1 <if test="params != null and params.size != 0"> <foreach item="item" collection="params"> AND `${item.key}` = #{item.value} </foreach> </if> <if test="whereSql != null and whereSql != ''"> AND ${whereSql} </if> </select> <!-- 全自动End --> </mapper>