PublicMapper.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.pj.project4sp.public4mapper.PublicMapper">
  4. <!-- ======================== 一些工具方法 ======================== -->
  5. <!-- 返回上一句SQL插入的自增主键值 -->
  6. <select id="getPrimarykey" resultType="long">
  7. SELECT @@identity
  8. </select>
  9. <!-- 返回上一句SQL插入的自增主键值 -->
  10. <select id="getPrimarykeyStr" resultType="string">
  11. SELECT @@identity
  12. </select>
  13. <!-- ======================== 新增SQL相关 ======================== -->
  14. <!-- ======================== 删除SQL相关 ======================== -->
  15. <!-- 删除一条记录,指定表名,id -->
  16. <delete id="deleteById">
  17. delete from ${tableName} where id = #{id}
  18. </delete>
  19. <!-- 根据指定列指定值删除一条记录,// 参数: 表名、条件列表、条件列值 -->
  20. <delete id="deleteBy">
  21. delete from ${tableName} where ${whereName} = #{whereValue}
  22. </delete>
  23. <!-- 删除一条记录,指定表名,id列表 -->
  24. <delete id="deleteByIds">
  25. delete from ${tableName}
  26. where id in
  27. <foreach collection="ids" item="id" open="(" separator="," close=")">
  28. #{id}
  29. </foreach>
  30. </delete>
  31. <!-- 根据指定列指定值删除多条记录 -->
  32. <delete id="deleteByWhereList">
  33. delete from ${tableName}
  34. where ${whereName} in
  35. <foreach collection="whereList" item="item" open="(" separator="," close=")">
  36. #{item}
  37. </foreach>
  38. </delete>
  39. <!-- ======================== 修改SQL相关 ======================== -->
  40. <!-- 指定表的指定字段加num(可以小于0 ),根据指定id -->
  41. <update id="columnAdd">
  42. update ${tableName} set
  43. ${columnName} = IFNULL(${columnName}, 0) + #{num}
  44. where id = #{id};
  45. </update>
  46. <!-- 指定表的指定字段增加指定值,可以为负值 -->
  47. <update id="columnAddByIds">
  48. update ${tableName} set
  49. ${columnName} = ${columnName} + #{num}
  50. where id in
  51. <foreach collection="ids" item="id" open="(" separator="," close=")">
  52. #{id}
  53. </foreach>
  54. </update>
  55. <!-- 指定表的指定字段更新为指定值,根据指定id -->
  56. <update id="updateColumnById">
  57. update ${tableName} set
  58. ${columnName} = #{value}
  59. where id = #{id}
  60. </update>
  61. <!-- 指定表的指定字段更新为指定值,根据指定id列表 -->
  62. <update id="updateColumnByIds">
  63. update ${tableName} set
  64. ${columnName} = #{value}
  65. where id in
  66. <foreach collection="ids" item="id" open="(" separator="," close=")">
  67. #{id}
  68. </foreach>
  69. </update>
  70. <!-- 指定表的指定字段更新为指定值, 根据指定列的指定值 -->
  71. <update id="updateColumnBy">
  72. update ${tableName} set
  73. ${columnName} = #{columnValue}
  74. where ${whereName} = #{whereValue}
  75. </update>
  76. <!-- 指定表的指定字段SoMap集合更新为指定值,根据指定id -->
  77. <update id="updateBySoMapById">
  78. update ${tableName} set
  79. <foreach collection="soMap.entrySet()" item="value" index="key" separator=",">
  80. ${key} = #{value}
  81. </foreach>
  82. where id = #{id}
  83. </update>
  84. <!-- 指定表的指定字段SoMap集合更新为指定值,根据指定id -->
  85. <update id="updateBySoMapBy">
  86. update ${tableName} set
  87. <foreach collection="soMap.entrySet()" item="value" index="key" separator=",">
  88. ${key} = #{value}
  89. </foreach>
  90. where ${whereName} = #{whereValue}
  91. </update>
  92. <!-- ======================== 查询SQL相关 ======================== -->
  93. <!-- 获取指定表的指定字段值,根据id值 -->
  94. <select id="getColumnById" resultType="String">
  95. select ${columnName} from ${tableName}
  96. where id = #{id}
  97. </select>
  98. <!-- 获取指定表的指定字段值,并转化为long,根据id值 -->
  99. <select id="getColumnByIdToLong" resultType="long">
  100. select ${columnName} from ${tableName}
  101. where id = #{id}
  102. </select>
  103. <!-- 获取指定表的指定字段值,根据指定条件(whereName=whereValue) -->
  104. <select id="getColumnByWhere" resultType="String">
  105. select ${columnName} from ${tableName}
  106. where ${whereName} = #{whereValue}
  107. </select>
  108. <!-- 获取指定表的id字段,根据指定条件(whereName=whereValue) -->
  109. <select id="getIdByWhere" resultType="long">
  110. select id from ${tableName}
  111. where ${whereName} = #{whereValue}
  112. </select>
  113. <!-- 获取指定表的指定字段值列表,并转化为long, 根据指定条件(whereName=whereValue) -->
  114. <select id="getColumnListToLongByWhere" resultType="long">
  115. select ${columnName} from ${tableName}
  116. where ${whereName} = #{whereValue}
  117. </select>
  118. <!-- 获取指定表的count数据,根据指定条件(whereName=whereValue) -->
  119. <select id="getCountBy" resultType="long">
  120. select count(*) from ${tableName}
  121. where ${whereName} = #{whereValue}
  122. </select>
  123. <!-- ======================== 查询集合SQL相关 ======================== -->
  124. <!-- 获取指定表的全部字段全部数据 -->
  125. <select id="getListMap" resultType="somap">
  126. select * from ${tableName}
  127. </select>
  128. <!-- 获取指定表的全部字段全部数据转化为Map, 根据指定条件(whereName=whereValue) -->
  129. <select id="getListMapByWhere" resultType="somap">
  130. select * from ${tableName}
  131. where ${whereName} = #{whereValue}
  132. </select>
  133. <!-- 获取指定表的全部字段全部数据转化为Map, 根据指定条件(id=id) -->
  134. <select id="getListMapById" resultType="somap">
  135. select * from ${tableName}
  136. where id = #{id}
  137. </select>
  138. </mapper>