ProvinceMapper.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.fdkankan.user.mapper.IProvinceMapper">
  4. <resultMap id="resultMap" type="com.fdkankan.user.entity.Province">
  5. <id column="id" jdbcType="VARCHAR" property="id" />
  6. <result column="name" jdbcType="VARCHAR" property="name" />
  7. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  8. <result column="rec_status" jdbcType="VARCHAR" property="recStatus" />
  9. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  10. <result column="tb_status" jdbcType="INTEGER" property="tbStatus" />
  11. </resultMap>
  12. <sql id="columnList">
  13. id,name,create_time,rec_status,update_time,tb_status </sql>
  14. <insert id="insert" useGeneratedKeys="true" keyProperty="entity.id">
  15. INSERT INTO ${tableName} (
  16. name, rec_status
  17. ) VALUES (
  18. #{entity.name}, #{entity.recStatus}
  19. ) </insert>
  20. <insert id="insertByBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id" >
  21. INSERT INTO ${tableName} (
  22. name, rec_status
  23. ) VALUES
  24. <foreach collection="list" item="entity" index="index" separator=",">
  25. (#{entity.name}, #{entity.recStatus})
  26. </foreach>
  27. </insert>
  28. <update id="update" parameterType="java.util.List" >
  29. <foreach collection="list" item="entity" index="index" separator=";">
  30. UPDATE ${tableName} SET
  31. name=#{entity.name}, rec_status=#{entity.recStatus}, tb_status=#{entity.tbStatus}
  32. WHERE
  33. id = #{entity.id}
  34. </foreach>
  35. </update>
  36. <update id="updateByBatch" >
  37. UPDATE ${tableName} SET
  38. ${field}
  39. <where>
  40. <foreach collection="condition" index="key" item="value">
  41. ${value} ${key}
  42. </foreach>
  43. </where>
  44. </update>
  45. <select id="getById" parameterType="java.lang.Integer" resultMap="resultMap">
  46. select
  47. <include refid="columnList" />
  48. from ${tableName}
  49. where id = #{id}
  50. </select>
  51. <select id="getOne" parameterType="java.util.Map" resultMap="resultMap">
  52. select
  53. <if test="field == null">
  54. <include refid="columnList" />
  55. </if>
  56. <if test="field != null">
  57. ${field}
  58. </if>
  59. from ${tableName}
  60. <where>
  61. <foreach collection="condition" index="key" item="value">
  62. ${value} ${key}
  63. </foreach>
  64. </where>
  65. limit 1;
  66. </select>
  67. <select id="getCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  68. select
  69. count(id)
  70. from ${tableName}
  71. <where>
  72. <foreach collection="condition" index="key" item="value">
  73. ${value} ${key}
  74. </foreach>
  75. </where>
  76. </select>
  77. <!-- 这部分为根据传递参数,自动生成SQL -->
  78. <select id="getList" parameterType="java.util.Map" resultMap="resultMap">
  79. select
  80. <if test="field == null">
  81. <include refid="columnList" />
  82. </if>
  83. <if test="field != null">
  84. ${field}
  85. </if>
  86. from ${tableName}
  87. <where>
  88. <foreach collection="condition" index="key" item="value">
  89. ${value} ${key}
  90. </foreach>
  91. </where>
  92. <if test="order != null">
  93. order by ${order}
  94. </if>
  95. <if test="limit != 0">
  96. <if test="offset != 0">
  97. limit ${offset}, ${limit}
  98. </if>
  99. <if test="offset == 0">
  100. limit ${limit}
  101. </if>
  102. </if>
  103. </select>
  104. <!-- 判断表格是否存在,如果不存在可以配合createTable使用,用于动态创建表格 -->
  105. <select id="existTable" parameterType="String" resultType="java.lang.Integer">
  106. select count(table_name) from information_schema.TABLES WHERE table_name=#{tableName} ;
  107. </select>
  108. <update id="createTable" parameterType="String">
  109. <!-- 这里是创建表格的SQL,复制过来,表名作为参数传递 -->
  110. <!-- create table ${tableName} ( // 表名要这样写 -->
  111. </update>
  112. </mapper>