package com.aaa.zxf.mapper;
import com.aaa.zxf.model.Book;
import org.apache.ibatis.annotations.*;
import org.mybatis.spring.annotation.MapperScan;
import java.util.List;
/**
* 1. mapper 层中 是接口,定义各种功能。 需要添加@Mapper 注解。
*
* 2. 使用select的注解,来查询数据库。
*
* 3. 解决javabean 和 数据库表中 列名不一致的问题
* 3.1 SQL语句,直接 查我们定义的实体类 select * from Book;
* 3.2 当使用注解的时候,实体类的属性和数据库的字段名 要完全一致!!!
*
* 这里用,起别名的方式。
* 数据库中的名字 book_name bookname
* book_date bookdate
* book_type booktype
*/
//@Mapper
//@MapperScan("com.aaa.zxf.service.BookService")
public interface BookMapper {
//查询所有图书的方法
@Select("select id, bookname,price,autor,bookdate, booktype from book")
ListselectAllBooks();
//根据id 删除图书
@Delete("delete from book where id=#{id}")
int deleteBook(Long id);
//根据id 获得当前的图书信息
@Select("select * from book where id=#{id}")
Book getOneBook(Long id);
//根据id 修改图书
@Update("update book set bookname=#{bookname}, price=#{price},autor=#{autor}, booktype=#{booktype} where id=#{id}")
int updateBook(Book book);
// 录入图书
@Insert("insert into book (bookname,price,autor,booktype) values (#{bookname},#{price},#{autor},#{booktype})")
int insertBook(Book book);
}