AgentMapper.xml 5.1 KB

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