• mybitis注解开发_curd操作


    package com.ssm.student.dao;
    
    import java.util.List;
    import java.util.Map;
    
    import org.apache.ibatis.annotations.Delete;
    import org.apache.ibatis.annotations.Insert;
    import org.apache.ibatis.annotations.Options;
    import org.apache.ibatis.annotations.Param;
    import org.apache.ibatis.annotations.ResultType;
    import org.apache.ibatis.annotations.Select;
    import org.apache.ibatis.annotations.Update;
    
    import com.ssm.student.entity.Student;
    
    /**
     * 学生模块业务层接口 
     * @author pengfei.xiong
     * @date 2017-8-13
     */ 
    public interface StudentDao {
        /**
         * 添加学生
         * @param student 学生实体对象
         * @throws Exception 异常
         */
        @Insert("insert into student(name,age) values(#{name},#{age})")
        public void insertStu(Student student)throws Exception;
        /**
         * 添加学生
         * @param student
         * @return 返回受影响的行数
         * @throws Exception
         */
        @Insert("insert into student(id,name,age) values(#{id},#{name},#{age})")
        @Options(useGeneratedKeys=true,keyColumn="id",keyProperty="id")  //返回主键,将主键值赋值到对象主键字段属性上
        public int insertStu2(Student student)throws Exception;
        /**
         * 返回学生集合列表
         * @return
         * @throws Exception
         */
        @Select("select id,name,age from student")
        @ResultType(Student.class)
        public List<Student> selectAll() throws Exception;
    
        public void addUser(Student student);
    
        @Select("select id,name,age from student")
        @ResultType(Map.class)
        public List<Map<String,Object>> selectAllMap() throws Exception;
        /**
         * 根据id查询学生信息
         * @param id
         * @return 返回学生对象
         * @throws Exception
         */
        @Select("select id,name,age from student where id=#{id}")
        @ResultType(Student.class)
        public Student selectById(int id) throws Exception;
    
        /**
         * 根据Name查询学生信息
         * @param id
         * @return 返回学生对象
         * @throws Exception
         */
        @Select("select id,name,age from student where name=#{name}")
        @ResultType(Student.class)
        public Student selectByName(String name) throws Exception;
        /**
         * 修改学生信息
         * @param student
         * @return
         * @throws Exception
         */
        @Update("update student set name=#{name},age=#{age} where id=#{id}")
        public int update(Student student) throws Exception;
        /**
         * 删除学生信息
         * @param student
         * @return
         * @throws Exception
         */
        @Delete("delete from student where id = #{ids}")
        public int delete(@Param("ids")int id) throws Exception;
    
    
    }
    

    demo地址:http://download.csdn.net/download/xpf_user/10130963

    勿忘初心 得过且过
  • 相关阅读:
    Collections与Arrays
    TreeMap
    HashMap
    单列集合的体系
    泛型的上下限
    09年最受关注的十大Visual Studio插件
    编码中的硬回车与软回车
    无法打开包括文件:'atlrx.h'的解决办法[原]
    【转】Notepad++,Eclipse和Visual Studio 2005常用快捷键对比
    【转】printf格式控制(你所不知道的printf妙用)
  • 原文地址:https://www.cnblogs.com/xpf1009/p/9227297.html
Copyright © 2020-2023  润新知