Mybatis使用注解进行增删改查

// 增
public
interface StudentMapper{ @Insert("insert into student (stud_id, name, email, addr_id, phone)values(#{studId},#{name},#{email},#{address.addrId},#{phone})") int insertStudent(Student student); } public interface StudentMapper{ @Insert("insert into student (name,email,addr_id,phone)values(#{name},#{email},#{address.addrId},#{phone})") @Options(useGeneratedKeys=true,keyProperty="studId") int insertStudent(Student student); } public interface StudentMapper{ @Insert("insert into student (name,email,addr_id,phone)values(#{name},#{email},#{address.addrId},#{phone})") @SelectKey(statement="select stud_id_seq.nextval from dual",keyProperty="studId",resultType=int.calss,before=true) int insertStudent(Student student); }
// 改 @Update(
"update students set name=#{name},email=#{email}") int updateStudent(Student student);
// 删 @Delete(
"delete form students where stud_id=#{studId}") int deleteStudent(int studId)
// 查 @Select(
"select name,email,phone from students where stud_id=#{studId}") Student findStudentById(Integer studId);

推荐使用xml文件进行配置,方面后续修改容易

转载于:https://www.cnblogs.com/wangzh1guo/p/9998985.html

你可能感兴趣的:(Mybatis使用注解进行增删改查)