mybatis dynamic sql statement

The method is passed the list parameter, and the list is the object
void save(List<DepartmentCustom> department);

<insert id="save" parameterType="java.util.List">
    
      insert into tb_department (enterprise_uid, name,
      parent_id, description) values
      <if test="list!=null">
		<foreach collection="list" item="item" separator="," >
		    (#{item.enterpriseUid},#{item.name},#{item.parentId},#{item.description})
		</foreach>
	  </if>
  </insert>


Self-Associated Query

<!-- For the parent-child relationship of the menu, the defined tree structure ResultMap -->  
   <resultMap  id="menuResultMap"  type="com.awcloud.user.pojo.custom.MenuCustom">    
        <id column="id" property="id" jdbcType="BIGINT" />  
        <result column="name" property="name" jdbcType="VARCHAR" />  
        <result column="menu_code" property="menuCode" jdbcType="VARCHAR" />  
        <result column="parent_id" property="parentId" jdbcType="BIGINT" />  
        <result column="url" property="url" jdbcType="VARCHAR" />  
        <result column="order" property="order" jdbcType="INTEGER" />  
        <result column="type" property="type" jdbcType="INTEGER" />  
        <result column="icon" property="icon" jdbcType="VARCHAR" />  
        <result column="description" property="description" jdbcType="VARCHAR" />  
        <result column="enabled" property="enabled" jdbcType="BIT" />  
            
            
        <!-- Query submenu -->    
        <collection property="children" column="id" select="getChildrenMenus" />    
            
    </resultMap>    
        
  
       <!-- Query all submenus of a specific menu, return menuResultMap -->  
    <select id="getChildrenMenus" parameterType="int" resultMap="menuResultMap">    
        select * from tb_menu where parent_id = #{id}    
    </select>   
      <!-- Query all top-level menus with submenus collections, return menuResultMap -->  
    <select id="getTopLevelMenusWithChildren" resultMap="menuResultMap" >    
        select * from tb_menu   where type=1 and (parent_id IS NULL or parent_id=0)  
    </select
>  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326929495&siteId=291194637