使用Mybatis-Plus快速进行增删改查

pom.xml引入jar

	 <!-- mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>
         <!--mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.6</version>
        </dependency>

#application.properties配置文件中设置MybatisPlus的mapper文件扫描

mybatis-plus.mapper-locations=classpath*:扫描包下的路径/*Mapper.xml
//我的路径是
mybatis-plus.mapper-locations=classpath*:com/zgf/springboot03loggin/mapper/xml/*Mapper.xml

mapper层的接口继承BaseMapper泛型类传递一个需要执行增删改查的实体类,

@Mapper
public interface IPhoneMapper extends BaseMapper<实体类>{

}

entity类代码

//自动封装实体类数据
@Data
//标识使用的数据库表
@TableName("book")
public class BookEntity {
    //自动映射数据库主键
    @TableId(type = IdType.AUTO)
    private int id;
    //@TableField("数据库列名")
    private String name;
    private String author;
    private int tid;
    private double Bmoney;
}

Service层

public interface IBookService extends IService<BookEntity> {
}

service的实现层

public class IBookServiceImpl extends ServiceImpl<IBookMapper, BookEntity> implements IBookService {
}

Controller层

```java
@Controller
public class BookController {
    @Resource(name = "iBookServiceImpl")
    IBookService iBookService;
    @RequestMapping("/select")
    @ResponseBody
    public String select(){
        return JSON.toJSONString(iBookService.list());
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值