第十五章MyBatis注解开发

注解开发

  • 只能用于简单的sql语句
  • 使用注解开发可以不用xml

@insert()注解

@Insert("insert into car values(#{id},#{name})")
Integer insert();

@delete()注解

@Delete("delete from car where id=#{id}")
Integer delete(Long id );

@update()注解

@Update("update car set name=#{name} where id=#{id}")
Integer update(Car car);

@select()注解

@Select("select * from car where id=#{id}")
Car selectById(Long id);

@Select("select * from car")
List selectAll();

@Results/@Result注解

主要作用将数据库查询的字段映射到对象上

@Select("select * from car")
@Results({
        @Result(property = "id", column = "id"),
        @Result(property = "name", column = "name")
})
List selectAll();

你可能感兴趣的:(MyBatis,mybatis,windows)