zoukankan      html  css  js  c++  java
  • 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

    勿忘初心 得过且过
  • 相关阅读:
    小程序数据库 用正则查询字符串字段/数组字段
    一键禁用Windows多余?服务
    Switch 10.1.0 无法启动软件请在home菜单中再试一次 解决方法
    算法记录
    LeetCode——面试题 10.01. 合并排序的数组
    LeetCode——98. 验证二叉搜索树
    LeetCode——55. 跳跃游戏
    LeetCode——92. 反转链表 II
    LeetCode——206. 反转链表
    LeetCode——225. 用队列实现栈
  • 原文地址:https://www.cnblogs.com/xpf1009/p/9227297.html
Copyright © 2011-2022 走看看