MenuMapper.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.MenuMapper">
  5. <sql id="field">
  6. id,name,url,p_id,order_by,type
  7. </sql>
  8. <!-- 查询菜单 -->
  9. <select id="getMenu" resultType="com.tld.model.Menu">
  10. select
  11. <include refid="field"/>
  12. from tld_menu
  13. <trim prefix="WHERE" prefixOverrides="and |or">
  14. <if test="pId != null and pId != ''">
  15. and p_id = #{pId}
  16. </if>
  17. and type = "PC"
  18. </trim>
  19. order by order_by
  20. </select>
  21. <!-- 查询列表 -->
  22. <select id="getPage" resultType="com.tld.model.Menu">
  23. select
  24. <include refid="field"/>
  25. from tld_menu
  26. <trim prefix="WHERE" prefixOverrides="and |or">
  27. <if test="pId != null and pId != ''">
  28. and p_id = #{pId}
  29. </if>
  30. <if test="name != null and name != ''">
  31. and name like CONCAT(CONCAT('%', #{name}), '%')
  32. </if>
  33. <if test="type != null and type != ''">
  34. and type = #{type}
  35. </if>
  36. <if test="id != null and id != ''">
  37. and id = #{id}
  38. </if>
  39. </trim>
  40. order by order_by
  41. </select>
  42. <!-- 新增菜单 -->
  43. <insert id="addMenu">
  44. insert into tld_menu(name,url,p_id,order_by,type) values(#{name},#{url},#{pId},#{orderBy},#{type})
  45. </insert>
  46. <!-- 修改菜单 -->
  47. <update id="updateMenu">
  48. update tld_menu
  49. <set>
  50. <trim suffixOverrides=",">
  51. <if test="name != null and name != ''">
  52. name = #{name},
  53. </if>
  54. <if test="url != null and url != ''">
  55. url = #{url},
  56. </if>
  57. <if test="pId != null and pId != ''">
  58. p_id = #{pId},
  59. </if>
  60. <if test="orderBy != null and orderBy != ''">
  61. order_by = #{orderBy},
  62. </if>
  63. <if test="type != null and type != ''">
  64. type = #{type},
  65. </if>
  66. </trim>
  67. </set>
  68. where id = #{id}
  69. </update>
  70. <!-- 删除菜单 -->
  71. <delete id="delMenu">
  72. delete from tld_menu where id = #{id}
  73. </delete>
  74. <!-- 根据角色查询菜单内容 -->
  75. <select id="getUserMenu" resultType="com.tld.model.Menu">
  76. SELECT a.id,
  77. a.name,
  78. a.url,
  79. a.p_id,
  80. c.menu
  81. FROM tld_menu a
  82. JOIN tld_user b ON b.id = #{userId}
  83. JOIN tld_role c ON b.role = c.id
  84. WHERE c.menu LIKE CONCAT('%', CONCAT(a.id, ','), '%')
  85. ORDER BY a.order_by
  86. </select>
  87. <!-- 根据角色查询菜单内容 -->
  88. <select id="getUserMenuPDA" resultType="com.tld.model.Menu">
  89. SELECT a.id,
  90. a.name,
  91. a.url,
  92. a.p_id,
  93. c.menu_pda
  94. FROM tld_menu a
  95. JOIN tld_user b ON b.id = #{userId}
  96. JOIN tld_role c ON b.role = c.id
  97. WHERE c.menu_pda LIKE CONCAT('%', CONCAT(a.id, ','), '%')
  98. ORDER BY a.order_by
  99. </select>
  100. </mapper>