mybatis-plus学习笔记

1.持久层接口—BaseMapper

创建的接口继承自BaseMapper<T>,那么基本的操作就都有了。
insert 、deleteById、updateById、selectById。

package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.Employee;

public interface EmployeeMapper extends BaseMapper<Employee> {
   
}

测试:

@SpringBootTest
class SpringbootMybatisplus1ApplicationTests {
   
    @Autowired
    private EmployeeMapper employeeMapper;
@Test
    void findAllEmps() {
   
        List<Employee> employees = employeeMapper.selectList(null);
        employees.forEach(System.out::println);
    }
    @Test
    void testInsert1(){
   
        Employee e1 = new Employee(1L,"蒋瑞","男",20,"[email protected]");
        int num = employeeMapper.insert(e1);
        System.out.println("返回值:"+num);
    }
    @Test
    void testInsert(){
   
        Employee e1 = new Employee(2L,"张继雨","男",20,"[email protected]");
        int num = employeeMapper.insert(e1);
        System.out.println("返回值:"+num);
    }
    @Test
    void testDeleteById(){
   
        int num = employeeMapper.deleteById(2L);
        System.out.println("返回值:"+num);
    }
    //按照指定的条件删除对象:名字叫蒋瑞,并且性别是男的
    @Test
    void testDeleteByMap(){
   
        Map<String,Object> map = new HashMap<>();
        map.put("emp_name","蒋瑞");
        map.put("emp_gender","男");
        int num = employeeMapper.deleteByMap(map);
        System.out.println("返回值:"+num);
    }
    @Test
    void testdeleteBatchIds(){
   
        List<Long> ids = new ArrayList<>();
        ids.add(1L);
        ids.add(2L);
        int num = employeeMapper.deleteBatchIds(ids);
        System.out.println("返回值:"+num);
    }
    @Test
    void updateById(){
   
        Employee e1 = new Employee(2L,"张雨雨",null,20,"[email protected]");
        int num = employeeMapper.updateById(e1);
        System.out.println("返回值:"+num);
    }
    @Test
    void selectById(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值