注解实现增删改查

来源:互联网 发布:油画笔 知乎 编辑:程序博客网 时间:2024/05/21 09:27
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
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 com.java1234.model.Student;


public interface StudentMapper {

    @Insert("insert into t_student values(null,#{name},#{age})")
    public int insertStudent(Student student);

    @Update("update t_student set name=#{name},age=#{age} where id=#{id}")
    public int updateStudent(Student student);

    @Delete("delete from t_student where id=#{id}")
    public int deleteStudent(int id);

    @Select("select * from t_student where id=#{id}")
    public Student getStudentById(Integer id);

    @Select("select * from t_student")
    @Results(
            {
                @Result(id=true,column="id",property="id"),
                @Result(column="name",property="name"),
                @Result(column="age",property="age")
            }
    )
    public List<Student> findStudents();

}
0 0
原创粉丝点击