mybatis-plus的使用

使用环境:springboot的controller层或者service层中

优点:直接有mybatis-plus拼接sql快速的查询/修改数据库

实例:

1、添加依赖

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.3.1.tmp</version>
</dependency>

2、service接口继承IService

public interface IPlantService extends IService<实体类>

接口实现类同样

public class PlantServiceImpl extends ServiceImpl<xxxMapper, 实体类> implements IPlantService {

3、mapper继承BaseMapper

public interface PlantMapper extends BaseMapper<实体类>

4、controller层使用mybaitis-plus

使用queryWrapper查询

//实例化queryWapper对象
 QueryWrapper<MmsProduct> query = new QueryWrapper<>();
        查询条件
        query.eq("product_id", mmsProduct.getProductId());
        query.eq("channel_id",  mmsProduct.getChannelId());
        /** SQL语句查询条件为 product_id = mmsProduct.getProductId() and channel_id =     mmsProduct.getChannelId()
*/
        MmsProduct product = mmsProductService.getOne(query);
        if(product != null){
            return AjaxResult.error("该通道已经存在产品ID:"+mmsProduct.getProductId());
        }

修改数据

UpdateWrapper<SysOrgAccount> uw = new UpdateWrapper<>();
		uw.eq("id",sysOrgAccountLog.getOrgId());
		uw.set("balance",blanceAfter);
		sysOrgAccountService.update(uw);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值