MyBatis注解使用示例如下:
@Select("select * from student")
public List<Student> selectAll();
@Select("select * from student where id =#{0}")
public Student selectOne(int id);
@Insert("insert into student values(default,#{name},#{phone})")
public int insert(Student stu);
@Update("update student set name =#{name},phone=#{phone} where id=#{id}")
public int update(Student stu);
@Delete("delete from student where id =#{0}")
public int delete(int id);
使用MyBatis注解的优点:
书写操作的时候比较的简单
缺点:
A、如果当我们数据库的字段名和实体的属性名不一致的话,没有办法处理
B、进行多表查询的时候比较麻烦
C、无法实现sql语句的动态拼接
MyBatis 注解的使用场景:
单表简单操作的时候使用比较方便