java小王博客

记录菜B的一点一滴,欢迎各位好汉前来叨扰!


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>博主qq:1756691861

mapper.xml写法

2020-6-9 卑微小王 SpringBoot

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ruoyi.project.admin.school.mapper.SchoolMapper">

   <resultMap type="com.ruoyi.project.admin.school.domain.GkSchool" id="schoolResult">
      <id property="id" column="id"/>
      <result property="areaId" column="area_id"/>
      <result property="eduLevel" column="edu_level"/>
      <result property="schoolType" column="school_type"/>
      <result property="is985" column="is_985"/>
      <result property="isFirstClass" column="is_first_class"/>
      <result property="is211" column="is_211" />
      <result property="nature" column="nature"/>
      <result property="title" column="title"/>
      <result property="thumb" column="thumb"/>
      <result property="weburl" column="weburl"/>
      <result property="tel" column="sex"/>
      <result property="address" column="address"/>
      <result property="descr" column="descr"/>
      <result property="content" column="content"/>
      <result property="status" column="status"/>
      <result property="createTime" column="create_time"/>
   </resultMap>



   <resultMap type="com.ruoyi.project.admin.school.domain.GkSchool" id="schoolspecial">
      <id property="id" column="id"/>
      <result property="areaId" column="area_id"/>
      <result property="eduLevel" column="edu_level"/>
      <result property="schoolType" column="school_type"/>
      <result property="is985" column="is_985"/>
      <result property="isFirstClass" column="is_first_class"/>
      <result property="is211" column="is_211" />
      <result property="nature" column="nature"/>
      <result property="title" column="title"/>
      <result property="thumb" column="thumb"/>
      <result property="weburl" column="weburl"/>
      <result property="tel" column="sex"/>
      <result property="address" column="address"/>
      <result property="descr" column="descr"/>
      <result property="content" column="content"/>
      <result property="status" column="status"/>
      <result property="createTime" column="create_time"/>
      <collection property="specialityList" ofType="com.ruoyi.project.admin.gkspeciality.domain.GkSpeciality">
         <id property="id" column="sp_id"/>
         <result property="eduLevel" column="sp_edu_level"/>
         <result property="title" column="sp_title"/>
         <result property="code" column="code"/>
         <result property="parentId" column="parent_id"/>
         <result property="descr" column="so_descr"/>
      </collection>
   </resultMap>

<select id="selectschoolList" resultMap="schoolResult">
      select sc.id, sc.area_id, sc.edu_level, sc.school_type, sc.is_985, sc.is_first_class, sc.is_211, sc.nature, sc.title, sc.thumb, sc.weburl, sc.tel, sc.address, sc.descr, sc.content, sc.status, sc.create_time,
         from gk_school as sc   <where>
        <if test=" areaId != null and areaId !='' " >
            AND  sc.area_id=#{areaId}
        </if>
      <if test="eduLevel==1">
         AND sc.edu_level=#{eduLevel}
      </if>
      <if test="eduLevel==2">
         AND sc.edu_level=#{eduLevel}
      </if>
        <if test="is985==1">
         AND sc.is_985=#{is985}
       </if>
       <if test="is985==2">
         AND sc.is_985=#{is985}
       </if>
        <if test="is211==1">
           AND sc.is_211=#{is211}
        </if>
       <if test="is211==2">
         AND sc.is_211=#{is211}
       </if>
       <if test="nature==1">
          AND sc.nature=#{nature}
       </if>
       <if test="nature==2">
          AND sc.nature=#{nature}
       </if>
       <if test=" schoolType !=null and schoolType != '' ">
          AND sc.school_type=#{schoolType}
       </if>
       <if test=" title != null and title !='' ">
         /*bind关键字将title绑定*/
      <bind name="title" value="'%'+title+'%'"/>
          AND sc.title like #{title}
       </if>
      </where>
      </select>

   <select id="schooltypelist" resultType="java.lang.String">
       select sc.school_type from gk_school as sc GROUP BY sc.school_type
   </select>
   <select id="school_speciality" resultMap="schoolspecial">
         select sc.id, sc.area_id, sc.edu_level, sc.school_type, sc.is_985, sc.is_first_class, sc.is_211, sc.nature, sc.title, sc.thumb, sc.weburl, sc.tel, sc.address, sc.descr, sc.content, sc.status, sc.create_time, sp.id "sp_id", sp.edu_level "sp_edu_level", sp.title "sp_title", sp.code, sp.parent_id, sp.descr "sp_descr"  from
         gk_school as sc   INNER JOIN
         gk_school_speciality as scp  ON sc.id=scp.school_id
         INNER JOIN
         gk_speciality as sp  ON scp.speciality_id=sp.id
         WHERE sc.id=#{id}
   </select>
</mapper> 

发表评论: