SysRegionDao.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.kmall.manager.dao.SysRegionDao">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.manager.entity.SysRegionEntity" id="regionMap">
  6. <result property="id" column="id"/>
  7. <result property="parentId" column="parent_id"/>
  8. <result property="name" column="name"/>
  9. <result property="type" column="type"/>
  10. <result property="agencyId" column="agency_id"/>
  11. </resultMap>
  12. <select id="queryObject" resultMap="regionMap">
  13. select * from mall_region where id = #{value}
  14. </select>
  15. <select id="queryList" resultMap="regionMap">
  16. select
  17. a.id,
  18. a.parent_Id,
  19. a.name,
  20. a.type,
  21. a.agency_Id,
  22. b.name parent_Name
  23. from mall_region a LEFT JOIN mall_region b on a.parent_id=b.id
  24. <where>
  25. <if test="name != null and name.trim() != ''">
  26. AND a.name LIKE concat('%',#{name},'%')
  27. </if>
  28. <if test="parentName != null and parentName.trim() != ''">
  29. AND b.name LIKE concat('%',#{parentName},'%')
  30. </if>
  31. <if test="type != null and type != ''">
  32. AND a.type = #{type}
  33. </if>
  34. </where>
  35. <choose>
  36. <when test="sidx != null and sidx.trim() != ''">
  37. order by ${sidx} ${order}
  38. </when>
  39. <otherwise>
  40. order by a.parent_Id
  41. </otherwise>
  42. </choose>
  43. <if test="offset != null and limit != null">
  44. limit #{offset}, #{limit}
  45. </if>
  46. </select>
  47. <select id="queryTotal" resultType="int">
  48. select count(*)
  49. from mall_region a LEFT JOIN mall_region b on a.parent_id=b.id
  50. <where>
  51. <if test="name != null and name.trim() != ''">
  52. AND a.name LIKE concat('%',#{name},'%')
  53. </if>
  54. <if test="parentName != null and parentName.trim() != ''">
  55. AND b.name LIKE concat('%',#{parentName},'%')
  56. </if>
  57. <if test="type != null and type != ''">
  58. AND a.type = #{type}
  59. </if>
  60. </where>
  61. </select>
  62. <insert id="save" parameterType="com.kmall.manager.entity.SysRegionEntity" useGeneratedKeys="true" keyProperty="id">
  63. insert into mall_region
  64. (
  65. `parent_id`,
  66. `name`,
  67. `type`,
  68. `agency_id`
  69. )
  70. values
  71. (
  72. #{parentId},
  73. #{name},
  74. #{type},
  75. #{agencyId}
  76. )
  77. </insert>
  78. <update id="update" parameterType="com.kmall.manager.entity.SysRegionEntity">
  79. update mall_region
  80. <set>
  81. <if test="parentId != null">`parent_id` = #{parentId},</if>
  82. <if test="name != null">`name` = #{name},</if>
  83. <if test="type != null">`type` = #{type},</if>
  84. <if test="agencyId != null">`agency_id` = #{agencyId}</if>
  85. </set>
  86. where id = #{id}
  87. </update>
  88. <delete id="delete">
  89. delete from mall_region where id = #{value}
  90. </delete>
  91. <delete id="deleteBatch">
  92. delete from mall_region where id in
  93. <foreach item="id" collection="array" open="(" separator="," close=")">
  94. #{id}
  95. </foreach>
  96. </delete>
  97. </mapper>