GoodsMapper.xml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.jeeplus.modules.test.manytoone.mapper.GoodsMapper">
  4. <sql id="goodsColumns">
  5. a.id AS "id",
  6. a.name AS "name",
  7. a.category_id AS "category.id",
  8. a.price AS "price",
  9. a.create_by AS "createBy.id",
  10. a.create_date AS "createDate",
  11. a.update_by AS "updateBy.id",
  12. a.update_date AS "updateDate",
  13. a.remarks AS "remarks",
  14. a.del_flag AS "delFlag",
  15. category.name AS "category.name"
  16. </sql>
  17. <sql id="goodsJoins">
  18. LEFT JOIN test_category category ON category.id = a.category_id
  19. </sql>
  20. <select id="get" resultType="Goods" >
  21. SELECT
  22. <include refid="goodsColumns"/>
  23. FROM test_goods a
  24. <include refid="goodsJoins"/>
  25. WHERE a.id = #{id}
  26. </select>
  27. <select id="findList" resultType="Goods" >
  28. SELECT
  29. <include refid="goodsColumns"/>
  30. FROM test_goods a
  31. <include refid="goodsJoins"/>
  32. <where>
  33. a.del_flag = #{DEL_FLAG_NORMAL}
  34. ${dataScope}
  35. <if test="name != null and name != ''">
  36. AND a.name = #{name}
  37. </if>
  38. <if test="category != null and category.id != null and category.id != ''">
  39. AND a.category_id = #{category.id}
  40. </if>
  41. </where>
  42. <choose>
  43. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  44. ORDER BY ${page.orderBy}
  45. </when>
  46. <otherwise>
  47. ORDER BY a.update_date DESC
  48. </otherwise>
  49. </choose>
  50. </select>
  51. <select id="findAllList" resultType="Goods" >
  52. SELECT
  53. <include refid="goodsColumns"/>
  54. FROM test_goods a
  55. <include refid="goodsJoins"/>
  56. <where>
  57. a.del_flag = #{DEL_FLAG_NORMAL}
  58. ${dataScope}
  59. </where>
  60. <choose>
  61. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  62. ORDER BY ${page.orderBy}
  63. </when>
  64. <otherwise>
  65. ORDER BY a.update_date DESC
  66. </otherwise>
  67. </choose>
  68. </select>
  69. <insert id="insert">
  70. INSERT INTO test_goods(
  71. id,
  72. name,
  73. category_id,
  74. price,
  75. create_by,
  76. create_date,
  77. update_by,
  78. update_date,
  79. remarks,
  80. del_flag
  81. ) VALUES (
  82. #{id},
  83. #{name},
  84. #{category.id},
  85. #{price},
  86. #{createBy.id},
  87. #{createDate},
  88. #{updateBy.id},
  89. #{updateDate},
  90. #{remarks},
  91. #{delFlag}
  92. )
  93. </insert>
  94. <update id="update">
  95. UPDATE test_goods SET
  96. name = #{name},
  97. category_id = #{category.id},
  98. price = #{price},
  99. update_by = #{updateBy.id},
  100. update_date = #{updateDate},
  101. remarks = #{remarks}
  102. WHERE id = #{id}
  103. </update>
  104. <!--物理删除-->
  105. <update id="delete">
  106. DELETE FROM test_goods
  107. WHERE id = #{id}
  108. </update>
  109. <!--逻辑删除-->
  110. <update id="deleteByLogic">
  111. UPDATE test_goods SET
  112. del_flag = #{DEL_FLAG_DELETE}
  113. WHERE id = #{id}
  114. </update>
  115. <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
  116. <select id="findUniqueByProperty" resultType="Goods" statementType="STATEMENT">
  117. select * FROM test_goods where ${propertyName} = '${value}'
  118. </select>
  119. </mapper>