DepartmentMapper.xml 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.tld.mapper.DepartmentMapper">
  5. <sql id="field">
  6. id,code,name,create_time
  7. </sql>
  8. <!-- 查询部门 -->
  9. <select id="getDepartment" resultType="com.tld.model.Department">
  10. select
  11. <include refid="field"/>
  12. from tld_department
  13. <trim prefix="WHERE" prefixOverrides="and |or">
  14. <if test="code != null and code != ''">
  15. and code like CONCAT(CONCAT('%', #{code}), '%')
  16. </if>
  17. <if test="name != null and name != ''">
  18. and name like CONCAT(CONCAT('%', #{name}), '%')
  19. </if>
  20. <if test="id != null and id != ''">
  21. and id = #{id}
  22. </if>
  23. </trim>
  24. </select>
  25. <!-- 新增部门 -->
  26. <insert id="addDepartment">
  27. <selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
  28. select LAST_INSERT_ID()
  29. </selectKey>
  30. insert into tld_department(name,create_time) values(#{name},DATE_FORMAT(NOW(), '%Y-%m-%d'))
  31. </insert>
  32. <!-- 修改部门 -->
  33. <update id="updateDepartment">
  34. update tld_department
  35. <set>
  36. <trim suffixOverrides=",">
  37. <if test="code != null">
  38. code = #{code},
  39. </if>
  40. <if test="name != null">
  41. name = #{name},
  42. </if>
  43. </trim>
  44. </set>
  45. where id = #{id}
  46. </update>
  47. <!-- 删除角色 -->
  48. <delete id="delDepartment">
  49. delete from tld_department where id = #{id}
  50. </delete>
  51. <!-- 查询导出内容 -->
  52. <select id="export" resultType="java.util.LinkedHashMap">
  53. select
  54. code,name,create_time
  55. from tld_department
  56. <trim prefix="WHERE" prefixOverrides="and |or">
  57. <if test="code != null and code != ''">
  58. and code = #{code}
  59. </if>
  60. <if test="name != null and name != ''">
  61. and name like CONCAT(CONCAT('%', #{name}), '%')
  62. </if>
  63. </trim>
  64. </select>
  65. </mapper>