zl程序教程

您现在的位置是:首页 >  其他

当前栏目

ssm使用全注解实现增删改查案例——IDeptMapper

案例 实现 注解 SSM 增删 改查 使用
2023-09-14 08:57:40 时间
package org.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.entity.Dept;

public interface IDeptMapper {
    /**
     * 
    * @Description: 该方法的主要作用:删除部门信息
    * @Title: deleteByPrimaryKey
    * @param  @param id
    * @param  @return 设定文件  
    * @return  返回类型:int   
    * @throws
     */
    @Delete("delete from dept where id = #{id}")
    int deleteByPrimaryKey(Integer id);

    /**
     * 
    * @Description: 该方法的主要作用:添加部门信息
    * @Title: insert
    * @param  @param record
    * @param  @return 设定文件  
    * @return  返回类型:int   
    * @throws
     */
    @Insert("insert into dept (id, name, loc )" +
            " values (#{id,jdbcType=INTEGER}, " +
            "#{name,jdbcType=VARCHAR}, " +
            "#{loc,jdbcType=VARCHAR})")
    int insert(Dept record);

    /**
     * 
    * @Description: 该方法的主要作用:根据编号查询信息
    * @Title: selectByPrimaryKey
    * @param  @param id
    * @param  @return 设定文件  
    * @return  返回类型:Dept   
    * @throws
     */
    @Select("select * from dept where id  = #{id}")
    @Results({
        @Result(id=true,property="id",column="id"),
        @Result(property="name",column="name"),
        @Result(property="loc",column="loc"),
        @Result(property="empList",column="id",javaType=List.class,
        many=@Many(select="org.dao.IEmpMapper.findEmpByDept"))
    })
    Dept selectByPrimaryKey(Integer id);

    /**
     * 
    * @Description: 该方法的主要作用:修改信息
    * @Title: updateByPrimaryKey
    * @param  @param record
    * @param  @return 设定文件  
    * @return  返回类型:int   
    * @throws
     */
    @Update("update dept " +
            "set name = #{name,jdbcType=VARCHAR}, " +
            " loc = #{loc,jdbcType=VARCHAR} " +
            "where id = #{id,jdbcType=INTEGER}")
    int updateByPrimaryKey(Dept record);

    /**
     * 
    * @Description: 该方法的主要作用:查询全部
    * @Title: findDeptAll
    * @param  @return 设定文件  
    * @return  返回类型:List<Dept>   
    * @throws
     */
    @Select("select * from dept")
    List<Dept> findDeptAll();
}