0
点赞
收藏
分享

微信扫一扫

springboot整合Mybatis-Plus

狗啃月亮_Rachel 2022-02-23 阅读 62

1、导入依赖:

<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-boot-starter</artifactId>
			<version>3.4.3</version>
		</dependency>

2、使用:
在使用MyBatis的时候,我们需要手动写SQL语句,而使用MP之后,就不需要我们手动写了。

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.southwind.springboottest.entity.Book;
import org.apache.ibatis.annotations.Mapper;
//import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
//import java.util.List;

@Mapper
@Repository
public interface BookDao extends BaseMapper<Book> {
//    @Select("select * from book where id=#{1}")
//     Book getbyid(Integer id);
//
//
//    @Select("select * from book")
//    List<Book> getall();
}

通过源码我们可以发现,BaseMapper已经封装好了相应的方法。
在这里插入图片描述

举报

相关推荐

0 条评论