springboot update数据_springboot 使用select\delete\update注解来查询数据库。

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);

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值