MyBatis的注解开发

注解

public interface PetsMapper {
	
	@Select(value="select id,name,birth_date birthDate,type_id typeId, owner_id ownerId from pets")
	public List<Pets> findAll();
	
	@Select("select id,name,birth_date birthDate,type_id typeId, owner_id ownerId from pets where id=#{id}")
	public Pets findById(int id);
	
	@Insert("insert into pets(name,birth_date,type_id,owner_id) values(#{name},#{birthDate},#{typeId},#{ownerId})")
	@SelectKey(keyColumn="id",keyProperty="id",resultType=Integer.class, before = false, statement = { "select last_insert_id()" })
	public int insert(Pets p);
	
	@Update(value="update pets set name=#{name},birth_date=#{birthDate} where id=#{id}")
	public int update(Pets p);
	
	@Delete("delete from pets where id=#{id}")
	public int delete(int id) ;
    
}

猜你喜欢

转载自blog.csdn.net/weixin_42496678/article/details/82907839