All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.sunchenbin.mybatis.actable.mapping.common.BaseMysqlCRUDMapper.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" >
<mapper namespace="com.gitee.sunchenbin.mybatis.actable.dao.common.BaseMysqlCRUDMapper">
	<!-- 保存 -->
	<insert id="save" parameterType="com.gitee.sunchenbin.mybatis.actable.command.SaveOrUpdateDataCommand" useGeneratedKeys="true" keyProperty="id">

		<foreach collection="tableMap" index="key" item="value">
			insert into `${key}`(
				<foreach collection="value" index="field" item="fieldvalue" separator=",">
					<if test="fieldvalue != null">
						`${field}`
					</if>
				</foreach>
			)
			
			values(
				<foreach collection="value" item="fieldvalue" separator=",">
					<if test="fieldvalue != null">
						#{fieldvalue}
					</if>
				</foreach>
			)
		</foreach>
	</insert>
	
	<!-- 更新 -->
	<update id="update" parameterType="com.gitee.sunchenbin.mybatis.actable.command.SaveOrUpdateDataCommand" useGeneratedKeys="true" keyProperty="id">

		<foreach collection="tableMap" index="key" item="value">
			update `${key}`
			
			set 
				<foreach collection="value" index="field" item="fieldvalue" separator=",">
					<if test="fieldvalue != null">
						<if test="field != 'keyFieldMap'">
							`${field}` = #{fieldvalue}
						</if>
					</if>
				</foreach>
			
			where 1=1 
			  	<foreach collection="value" index="keyfield" item="keyvalues">
					<if test="keyfield == 'keyFieldMap'">
						<foreach collection="keyvalues" index="field" item="fieldvalue">
							 and `${field}` = #{fieldvalue}
						</foreach>
					</if>
				</foreach>
		</foreach>
	</update>
	
	<!-- 更新,可以更新null -->
	<update id="updateWithNull" parameterType="com.gitee.sunchenbin.mybatis.actable.command.SaveOrUpdateDataCommand" useGeneratedKeys="true" keyProperty="id">

		<foreach collection="tableMap" index="key" item="value">
			update `${key}`
			
			set 
				<foreach collection="value" index="field" item="fieldvalue" separator=",">
					<if test="field != 'keyFieldMap'">
						`${field}` = #{fieldvalue}
					</if>
				</foreach>
			
			where 1=1 
			  	<foreach collection="value" index="keyfield" item="keyvalues">
					<if test="keyfield == 'keyFieldMap'">
						<foreach collection="keyvalues" index="field" item="fieldvalue">
							 and `${field}` = #{fieldvalue}
						</foreach>
					</if>
				</foreach>
		</foreach>
	</update>
	
	<!-- 删除 -->
	<select id="delete" parameterType="java.util.Map">
		
		<foreach collection="tableMap" index="key" item="value">
			delete from `${key}`
			where 1=1 
			<foreach collection="value" index="field" item="fieldvalue">
				<if test="fieldvalue != null">
					 and `${field}` = #{fieldvalue}
				</if>
			</foreach>
			
		</foreach>

	</select>
	
	<!-- 查询 -->
	<select id="search" parameterType="java.util.Map" resultType="java.util.HashMap">
		
		<foreach collection="tableMap" index="key" item="value">
			<if test="key != 'start' and key != 'pageSize' and key != 'orderBy'">
				select * from `${key}`
				where 1=1 
				<foreach collection="value" index="field" item="fieldvalue">
					<if test="fieldvalue != null">
						 and `${field}` = #{fieldvalue} 
					</if>
				</foreach>
			</if>
		</foreach>
		
		<if test="tableMap.orderBy != null">
			 order by 
			 <foreach collection="tableMap.orderBy" index="field" item="sort" separator=",">
					`${field}` ${sort} 
			 </foreach>
		</if>
		
		<if test="tableMap.start != null and tableMap.pageSize != null">
			 limit #{tableMap.start},#{tableMap.pageSize}
		</if>
	</select>
	
	<!-- 查询总记录数 -->
	<select id="searchCount" parameterType="java.util.Map" resultType="int">
		
		<foreach collection="tableMap" index="key" item="value">
			<if test="key != 'start' and key != 'pageSize' and key != 'orderBy'">
				select count(1) from `${key}`
				where 1=1 
				<foreach collection="value" index="field" item="fieldvalue">
					<if test="fieldvalue != null">
						 and `${field}` = #{fieldvalue}
					</if>
				</foreach>
			</if>
		</foreach>
	</select>
	
	<!-- 动态sql查询-->
	<select id="query" parameterType="string" resultType="java.util.LinkedHashMap">
		${value}
	</select>
	
</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy