mybitis注解开发_curd操作

本文介绍了一个学生模块业务层接口的设计实现,包括学生信息的增删改查操作,使用MyBatis进行数据库交互,提供了多种插入、更新、查询学生的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.youkuaiyun.com/download/xpf_user/10130963

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值