MenuMapper.xml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  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. </trim>
  18. </select>
  19. <!-- 查询列表 -->
  20. <select id="getPage" resultType="com.tld.model.Menu">
  21. select
  22. <include refid="field"/>
  23. from tld_menu
  24. <trim prefix="WHERE" prefixOverrides="and |or">
  25. <if test="pId != null and pId != ''">
  26. and p_id = #{pId}
  27. </if>
  28. <if test="name != null and name != ''">
  29. and name = #{name}
  30. </if>
  31. </trim>
  32. </select>
  33. <!-- 新增菜单 -->
  34. <insert id="addMenu">
  35. insert into tld_menu(name,url,p_id) values(#{name},#{url},#{pId})
  36. </insert>
  37. <!-- 修改菜单 -->
  38. <update id="updateMenu">
  39. update tld_menu
  40. <set>
  41. <trim suffixOverrides=",">
  42. <if test="name != null and name != ''">
  43. name = #{name},
  44. </if>
  45. <if test="url != null and url != ''">
  46. url = #{url},
  47. </if>
  48. <if test="pId != null and pId != ''">
  49. p_id = #{pId},
  50. </if>
  51. </trim>
  52. </set>
  53. where id = #{id}
  54. </update>
  55. <!-- 删除菜单 -->
  56. <delete id="delMenu">
  57. delete from tld_menu where id = #{id}
  58. </delete>
  59. <!-- 根据角色查询菜单内容 -->
  60. <select id="getUserMenu" resultType="com.tld.model.Menu">
  61. SELECT
  62. a.id,
  63. a.name,
  64. a.url,
  65. a.p_id,
  66. a.id_code
  67. FROM
  68. tld_menu a
  69. join tld_user b on b.id = #{userId}
  70. join tld_role c on b.role = c.id
  71. WHERE
  72. c.menu LIKE CONCAT('%',CONCAT(a.id, ','),'%')
  73. </select>
  74. </mapper>