首页 > 其他分享 >Mybatis-Plus常见操作

Mybatis-Plus常见操作

时间:2023-09-19 14:57:23浏览次数:41  
标签:queryWrapper name 常见 Plus sysUser Mybatis role id MybatisSysUser

package com.ideas.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;
import com.ideas.system.entity.MybatisSysUser;
import com.ideas.system.entity.Apple;
import com.ideas.system.entity.DropDownList;
import com.ideas.system.entity.User;
import com.ideas.system.mapper.MybatisPlusOptionMapper;
import com.ideas.system.service.MybatisPlusOptionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
public class MybatisPlusOptionServiceImpl extends ServiceImpl<MybatisPlusOptionMapper, MybatisSysUser> implements MybatisPlusOptionService {
    @Override
    public void mybatisPlusOption() {
        // AR模式
        MybatisSysUser mybatisSysUser = MybatisSysUser.builder().build();
        mybatisSysUser.selectById(1L);
        mybatisSysUser.selectById();
        mybatisSysUser.selectList(new LambdaQueryWrapper<>());
        LambdaQueryWrapper<MybatisSysUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.last("limit 1");
        mybatisSysUser.selectOne(lambdaQueryWrapper);
        mybatisSysUser.selectAll();
        mybatisSysUser.selectPage(new Page<MybatisSysUser>(), new LambdaQueryWrapper<>());
        mybatisSysUser.selectCount(new LambdaQueryWrapper<>());
        mybatisSysUser.insert();
        mybatisSysUser.insertOrUpdate();
        mybatisSysUser.deleteById();
        mybatisSysUser.deleteById(1L);
        mybatisSysUser.delete(new LambdaQueryWrapper<>());
        mybatisSysUser.updateById();
        mybatisSysUser.update(new LambdaUpdateWrapper<>());


        Long id = 1L;
        // 根据主键查询一条数据
        MybatisSysUser sysUser = baseMapper.selectById(id);
        log.info("根据主键查询一条数据-sysUser={}", JSON.toJSONString(sysUser));

        LambdaQueryWrapper<MybatisSysUser> queryWrapper = new LambdaQueryWrapper<>();
        // 等于,eq(true, "name", "zhangsan")  ==>  name='zhangsan'
        queryWrapper.eq(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName, sysUser.getUserName());
        // 不等于,ne(true, "name", "zhangsan")  ==>  name <> 'zhangsan'
        queryWrapper.ne(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName, sysUser.getUserName());

        // 模糊,like(true, "name", "zhangsan")  ==>  name like '%zhangsan%'
        queryWrapper.like(StringUtils.isNotBlank(sysUser.getPhonenumber()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());
        // 模糊,likeLeft(true, "name", "zhangsan")  ==>  name like '%zhangsan'
        queryWrapper.likeLeft(StringUtils.isNotBlank(sysUser.getPhonenumber()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());
        // 模糊,likeRight(true, "name", "zhangsan")  ==>  name like 'zhangsan%'
        queryWrapper.likeRight(StringUtils.isNotBlank(sysUser.getPhonenumber()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());
        // 模糊,notLike(true, "name", "zhangsan")  ==>  name not like '%zhangsan%'
        queryWrapper.notLike(StringUtils.isNotBlank(sysUser.getPhonenumber()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());

        // 小于,lt(true, "age", 19)  ==>  age < 19
        queryWrapper.lt(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());
        // 小于等于,le(true, "age", 19)  ==>  age <= 19
        queryWrapper.le(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());
        // 大于,gt(true, "age", 19)  ==>  age > 19
        queryWrapper.gt(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());
        // 大于等于,ge(true, "age", 19)  ==>  age >= 19
        queryWrapper.ge(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber());

        // 两者之间,between(true, "age", 19, 30)  ==>  age between 19 and 30
        queryWrapper.between(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber(), sysUser.getPhonenumber());
        // 非两者之间,notBetween(true, "age", 19, 30)  ==>  age not between 19 and 30
        queryWrapper.notBetween(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getPhonenumber, sysUser.getPhonenumber(), sysUser.getPhonenumber());

        // 字段 IS NULL,isNull(true, "name")  ==>  name is null
        queryWrapper.isNull(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName);
        // 字段 IS NOT NULL,isNotNull(true, "name")  ==>  name is not null
        queryWrapper.isNotNull(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName);

        // 字段 IN,in(true, "name", "zhangsan", "lisi")  ==>  name in('zhangsan', 'lisi')
        queryWrapper.in(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName, sysUser.getUserName(), sysUser.getPhonenumber());
        queryWrapper.in(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName, Lists.newArrayList("zhangsna", "list"));
        // 字段 NOT IN,notIn(true, "name", "zhangsan", "lisi")  ==>  name not in('zhangsan', 'lisi')
        queryWrapper.notIn(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName, sysUser.getUserName(), sysUser.getPhonenumber());
        queryWrapper.notIn(StringUtils.isNotBlank(sysUser.getUserName()), MybatisSysUser::getUserName, Lists.newArrayList("zhangsna", "list"));
        // 字段 inSql,inSql(true, "roleId", "select role_id from sys_role where role_name like '%三'")  ==>  roleId in(select role_id from sys_role where role_name like '%三')
        queryWrapper.inSql(sysUser.getRoleIds().length > 0, MybatisSysUser::getRoleId, "select role_id from sys_role where role_name like '%三'");
        // 字段 notInSql,notInSql(true, "roleId", "select role_id from sys_role where role_name like '%三'")  ==>  roleId not in(select role_id from sys_role where role_name like '%三')
        queryWrapper.notInSql(sysUser.getRoleIds().length > 0, MybatisSysUser::getRoleId, "select role_id from sys_role where role_name like '%三'");

        // 字段 exists,exists(true, "select role_id from sys_role where role_name = 'zhangsan'")  ==>  roleId exists(select role_id from sys_role where role_name = 'zhangsan')
        queryWrapper.exists(sysUser.getRoleIds().length > 0, "select role_id from sys_role where role_name = 'zhangsan'");
        // 字段 notExists,notExists(true, "select role_id from sys_role where role_name = 'zhangsan'")  ==>  roleId not exists(select role_id from sys_role where role_name = 'zhangsan')
        queryWrapper.notExists(sysUser.getRoleIds().length > 0, "select role_id from sys_role where role_name = 'zhangsan'");

        // 字段 groupBy,groupBy(true, "roleId", "userName")  ==>  group by roleId, userName
        queryWrapper.groupBy(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getRoleId, MybatisSysUser::getUserName);

        // 字段 order by,orderByAsc(true, "roleId", "userName")  ==>  gorder by roleId ASC, userName ASC
        queryWrapper.orderByAsc(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getRoleId, MybatisSysUser::getUserName);
        // 字段 order by,orderByDesc(true, "roleId", "userName")  ==>  gorder by roleId DESC, userName DESC
        queryWrapper.orderByDesc(Objects.nonNull(sysUser.getRoleId()), MybatisSysUser::getRoleId, MybatisSysUser::getUserName);
        queryWrapper.orderByDesc(MybatisSysUser::getRoleId).orderByAsc(MybatisSysUser::getUserName);
        // 字段 order by 自定排序规则,所有字段同一排序规则,orderBy(true, false,"roleId", "userName")  ==>  order by roleId DESC, userName DESC
        // 字段 order by 自定排序规则,所有字段同一排序规则,orderBy(true, true,"roleId", "userName")  ==>  order by roleId ASC, userName ASC
        queryWrapper.orderBy(Objects.nonNull(sysUser.getRoleId()), Boolean.FALSE, MybatisSysUser::getRoleId, MybatisSysUser::getUserName);

        // 字段 having,having(true, "sum(age) > {0}", 11)  ==>  having sum(age) > 11
        queryWrapper.having(Objects.nonNull(sysUser.getRoleId()), "sum(age) > {0}", 11);

        // 无视优化规则,直接拼接到sql最后面,只能调用一次,多次调用以最后一次为准,有sql注入风险,
        queryWrapper.last("limit 1");

        // ************************** TODO 以下几个待确定sql **************************
        // 拼接or,注意:主动调用or表示紧接着下一个方法不是and连接!(不调用or则默认使用and连接)
        queryWrapper.or();
        queryWrapper.or(Objects.nonNull(sysUser.getRoleId()));
        // and嵌套,
        queryWrapper.and(Objects.nonNull(sysUser.getRoleId()), (Consumer<LambdaQueryWrapper<MybatisSysUser>>) queryWrapper);
        // 拼接sql,apply("date_format(dateColumn,'%Y-%m-%d') = '2008-08-08'")
        // apply("date_format(dateColumn,'%Y-%m-%d') = {0}", LocalDate.now())
        queryWrapper.apply(Objects.nonNull(sysUser.getRoleId()), "date_format(dateColumn,'%Y-%m-%d') >= {0}", LocalDate.now());
        // 正常嵌套,不带and和or
        queryWrapper.nested(Objects.nonNull(sysUser.getRoleId()), (Consumer<LambdaQueryWrapper<MybatisSysUser>>) queryWrapper);

        List<MybatisSysUser> mybatisSysUserList = baseMapper.selectList(queryWrapper);
    }

    public static void main(String[] args) {
        List<Apple> appleList = Lists.newArrayList();
        appleList.add(new Apple(1, "苹果1", new BigDecimal("3.25"), 10));
        appleList.add(new Apple(1, "苹果2", new BigDecimal("1.35"), 20));
        appleList.add(new Apple(2, "香蕉", new BigDecimal("2.89"), 30));
        appleList.add(new Apple(3, "荔枝", new BigDecimal("9.99"), 40));

        // 1、分组 List里面的对象元素,以某个属性来分组,例如,以id分组,将id相同的放在一起:
        Map<Integer, List<Apple>> groupBy = appleList.stream().collect(Collectors.groupingBy(Apple::getId));
        System.out.println("groupBy:" + JSON.toJSONString(groupBy));
        // groupBy:{1:[{"id":1,"money":3.25,"name":"苹果1","num":10},{"id":1,"money":1.35,"name":"苹果2","num":20}],2:[{"id":2,"money":2.89,"name":"香蕉","num":30}],3:[{"id":3,"money":9.99,"name":"荔枝","num":40}]}

        // 分组且排序
        Map<Integer, List<Apple>> groupingByMap = appleList
                .stream()
                .collect(Collectors.groupingBy(Apple::getNum))
                .entrySet()
                .stream()
                .sorted(Map.Entry.comparingByKey())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));


        /**
         * 2. id为key,apple对象为value,可以这么做:
         * List -> Map
         * 需要注意的是:
         * toMap 如果集合对象有重复的key,会报错Duplicate key ....
         * apple1,apple12的id都为1。
         * 可以用 (k1,k2)->k1 来设置,如果有重复的key,则保留key1,舍弃key2
         */
        // 2.1. 重复key时指定要留的key的顺序
        Map<Integer, Apple> appleMap = appleList.stream().collect(Collectors.toMap(Apple::getId, apple -> apple, (k1, k2) -> k1));
        System.out.println("appleMap:" + JSON.toJSONString(appleMap));
        // appleMap:{1:{"id":1,"money":3.25,"name":"苹果1","num":10},2:{"id":2,"money":2.89,"name":"香蕉","num":30},3:{"id":3,"money":9.99,"name":"荔枝","num":40}}
        // 重复key的情况下 简单的使用后者覆盖前者的
        Map<Integer, Apple> collect2 = appleList.stream().collect(Collectors.toMap(Apple::getNum, Function.identity(), (key1, key2) -> key2));
        System.out.println("collect2:" + JSON.toJSONString(collect2));
        // collect2:{20:{"id":1,"money":1.35,"name":"苹果2","num":20},40:{"id":3,"money":9.99,"name":"荔枝","num":40},10:{"id":1,"money":3.25,"name":"苹果1","num":10},30:{"id":2,"money":2.89,"name":"香蕉","num":30}}
        // 指定map的具体实现
        LinkedHashMap<Integer, Apple> collect3 = appleList.stream().collect(Collectors.toMap(Apple::getNum, Function.identity(), (key1, key2) -> key2, LinkedHashMap::new));
        System.out.println("collect3:" + JSON.toJSONString(collect3));
        // collect3:{10:{"id":1,"money":3.25,"name":"苹果1","num":10},20:{"id":1,"money":1.35,"name":"苹果2","num":20},30:{"id":2,"money":2.89,"name":"香蕉","num":30},40:{"id":3,"money":9.99,"name":"荔枝","num":40}}
        // 当key不冲突时
        // List<Apple> to Map<Integer, String> num = key,name = value
        Map<Integer, String> collect4 = appleList.stream().collect(Collectors.toMap(Apple::getNum, Apple::getName));
        List<Map<String, String>> columnRoleList = Lists.newArrayList();
        Map<String, String> collect4_1 = columnRoleList.stream().collect(Collectors.toMap(column->column.get("column_name"), column->column.get("role_ids"), (k1, k2) -> k1));
        List<Map<String, String>> multiSourceDefaultList = columnRoleList.stream().filter(a -> StringUtils.isNotBlank(a.get("data_value")) && StringUtils.isNotBlank(a.get("data_value"))).collect(Collectors.toList());
        System.out.println("collect4:" + JSON.toJSONString(collect4));
        // collect4:{20:"苹果2",40:"荔枝",10:"苹果1",30:"香蕉"}
        // num = key,Apple = value
        // num = key,Apple = value 比较优雅的写法是这样的
        Map<Integer, Apple> collect6 = appleList.stream().collect(Collectors.toMap(Apple::getNum, Function.identity()));
        Map<String, Integer> collect8 = appleList.stream().collect(Collectors.toMap(Apple::getName, Apple::getId));
        System.out.println("collect6:" + JSON.toJSONString(collect6));
        // collect6:{20:{"id":1,"money":1.35,"name":"苹果2","num":20},40:{"id":3,"money":9.99,"name":"荔枝","num":40},10:{"id":1,"money":3.25,"name":"苹果1","num":10},30:{"id":2,"money":2.89,"name":"香蕉","num":30}}

        //3、过滤Filter 从集合中过滤出来符合条件的元素:
        List<Apple> filterList = appleList.stream().filter(a -> a.getName().equals("香蕉")).collect(Collectors.toList());
        System.out.println("filterList:" + JSON.toJSONString(filterList));
        // filterList:[{"id":2,"money":2.89,"name":"香蕉","num":30}]

        // 4.求和 将集合中的数据按照某个属性求和:
        BigDecimal totalMoney = appleList.stream().map(Apple::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println("totalMoney:" + JSON.toJSONString(totalMoney));
        // totalMoney:17.48

        // 5.统计list数量/list to list 指定属性
        // 方法一
        List<Integer> collect1 = appleList.stream().map(apple -> apple.getId()).collect(Collectors.toList());
        // 方法二
        List<Integer> collect = appleList.stream().map(Apple::getId).collect(Collectors.toList());
        System.out.println("collect1.size():" + collect1.size() + " --- collect.size():" + collect.size());

        // 6. List<A> 转 List<B>
        List<DropDownList> collect7 = appleList.stream().map(x -> DropDownList.builder().value(x.getId().toString()).text(x.getName()).build()).collect(Collectors.toList());

        // 7.转成set
        Set<Integer> ageSet = appleList.stream().map(Apple::getNum).collect(Collectors.toSet()); // [20, 10]

        // 8.字符串分隔符连接
        String joinName = appleList.stream().map(Apple::getName).collect(Collectors.joining(",", "(", ")")); // (aa,bb,cc)

        // 9.学生总数
        Long count = appleList.stream().collect(Collectors.counting()); // 3

        // 10.最大年龄 (最小的minBy同理)
        Integer maxAge = appleList.stream().map(Apple::getNum).collect(Collectors.maxBy(Integer::compare)).get(); // 20
        // 11.最小值
        Integer minAge = appleList.stream().map(Apple::getNum).collect(Collectors.minBy(Integer::compare)).get(); // 20
        // 12.求和
        Integer sumAge = appleList.stream().collect(Collectors.summingInt(Apple::getNum)); // 40
        // 13.平均年龄
        Double averageAge = appleList.stream().collect(Collectors.averagingDouble(Apple::getNum)); // 13.333333333333334
        // 14.分成两部分,一部分大于10岁,一部分小于等于10岁
        Map<Boolean, List<Apple>> partMap = appleList.stream().collect(Collectors.partitioningBy(v -> v.getNum() > 10));


        // map操作
        Map<String, Object> entryMap = Maps.newHashMap();
        Map<String, Map.Entry<String, Object>> collectMaps = entryMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e));

        Table<String, String, String> imageTextTable = HashBasedTable.create();
        imageTextTable.put("text_1", "1111", "2222");
        imageTextTable.put("text_1", "3333", "4444");
        imageTextTable.put("text_2", "5555", "6666");
        imageTextTable.put("text_2", "7777", "8888");

        //rowKey或columnKey的集合
        Set<String> rowKeys = imageTextTable.rowKeySet();
        Set<String> columnKeys = imageTextTable.columnKeySet();
        //value集合
        Collection<String> values = imageTextTable.values();
        log.info("rowKeys={},columnKeys={},values={}", rowKeys, columnKeys, values);
        // rowKeys=[text_1, text_2],columnKeys=[1111, 3333, 5555, 7777],values=[2222, 4444, 6666, 8888]

        Set<Table.Cell<String, String, String>> cells = imageTextTable.cellSet();
        for (Table.Cell<String, String, String> cell : cells) {
            String RowKey = cell.getRowKey();
            String ColumnKey = cell.getColumnKey();
            String Value = cell.getValue();

            log.info("RowKey={},ColumnKey={},Value={}", RowKey, ColumnKey, Value);
            // RowKey=text_1,ColumnKey=1111,Value=2222
            // RowKey=text_1,ColumnKey=3333,Value=4444
        }
        System.out.println("*************************");
        for (String key : rowKeys) {
            Set<Map.Entry<String, String>> rows = imageTextTable.row(key).entrySet();
            for (Map.Entry<String, String> row : rows) {
                log.info("row.getKey()={},row.getValue()={}", row.getKey(), row.getValue());
                // row.getKey()=1111,row.getValue()=2222
            }
            log.info("rows={}", JSON.toJSONString(rows));
            // rows=[{"1111":"2222"},{"3333":"4444"}]
        }
    }

    //public static void main(String[] args) {
    //    // TODO jdk8 之前的排序
    //    System.out.println("============jdk8 之前的排序");
    //    List<User> list = initList();
    //    Collections.sort(list, new Comparator<User>() {
    //        @Override
    //        public int compare(User o1, User o2) {
    //            return o1.getAge().compareTo(o2.getAge());
    //        }
    //    });
    //    list.forEach(System.out::println);

    //    // TODO jdk8 lambda 排序-升序
    //    System.out.println("============jdk8 lambda排序,升序排序 --> 从小到大");
    //    list = initList();
    //    list.sort((u1, u2) -> u1.getAge().compareTo(u2.getAge()));   //不带参  带参: list.sort((User u1, User u2) -> u1.getAge().compareTo(u2.getAge()));
    //    list.forEach(System.out::println);

    //    // TODO jdk8 升序排序
    //    System.out.println("============jdk8 升序排序 --> 从小到大,Comparator提供的静态方法");
    //    list = initList();
    //    Collections.sort(list, Comparator.comparing(User::getAge));
    //    list.forEach(System.out::println);

    //    // TODO jdk8 降序排序
    //    System.out.println("============jdk8 降序排序 --> 从大到小,Comparator提供的静态方法");
    //    list = initList();
    //    Collections.sort(list, Comparator.comparing(User::getAge).reversed());
    //    list.forEach(System.out::println);
    //    System.out.println();

    //    // TODO jdk8 组合排序
    //    System.out.println("============jdk8 组合排序,Comparator提供的静态方法,先按年纪排序,年纪相同的按名称排序");
    //    list = initList();
    //    Collections.sort(list, Comparator.comparing(User::getAge).thenComparing(User::getName));
    //    list.forEach(System.out::println);
    //}

    /**
     * TODO  初始化List数据
     *
     * @return java.util.List<com.ws.ldy.common.utils.JDK8ListSort.User>
     * @author ws
     * @mail [email protected]
     * @date 2020/5/10 0010 22:49
     */
    private static List<User> initList() {
        List<User> list = new ArrayList<>();
        list.add(new User("lisa", 23));
        list.add(new User("tom", 11));
        list.add(new User("john", 16));
        list.add(new User("jennis", 26));
        list.add(new User("tin", 26));
        list.add(new User("army", 26));
        list.add(new User("mack", 19));
        list.add(new User("jobs", 65));
        return list;
    }
}

 

标签:queryWrapper,name,常见,Plus,sysUser,Mybatis,role,id,MybatisSysUser
From: https://www.cnblogs.com/JimmyThomas/p/17714626.html

相关文章

  • linux 常见命令
    linux查看进程树:pstree-aup查看当前用户的所有进程:psu查看所有进程的详细信息:psaux根据进程名查找进程:ps-C进程名平均一个进程多少M:ps--no-headers-o"rss,cmd"-Cphp-fpm|ps--no-headers-o"rss,cmd"-Cphp-fpm|awk'{sum+=$1}END{printf("%d%s\n",s......
  • 常见的空中速率有哪些及对无线通信系统的影响
    常见的空中速率有哪些及对无线通信系统的影响空中速率是指无线通信系统中数据在空气中传输的速度,它对无线传输有以下影响:传输速度:空中速率越高,数据在空气中的传输速度就越快,从而可以增加传输数据量,提高传输效率。传输距离:空中速率越高,数据在空气中的传输距离就越短。这是因为高空中......
  • 常见的空中速率有哪些及对无线通信系统的影响
    常见的空中速率有哪些及对无线通信系统的影响空中速率是指无线通信系统中数据在空气中传输的速度,它对无线传输有以下影响:传输速度:空中速率越高,数据在空气中的传输速度就越快,从而可以增加传输数据量,提高传输效率。传输距离:空中速率越高,数据在空气中的传输距离就越短。这是因为高......
  • mybatis
    1.mybatis入门1.mybatis入门SqlSessionFactoryBuilder:读取配置信息,创建SqlSessionFactory.建造者模式,方法级别生命周期SqlSessionFactoryL创建SqlSession,工厂单例模式,存在于程序的整个生命周期SqlSession:代表一次数据库连接,一般通过调用Mapper访问数据库,也可以直接......
  • MyBatis中 Mapper.xml 文件
     resources目录下新建文件夹mapper(个人习惯全路径与Mapper类对应) <?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTDMapper3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd......
  • elementplus django drf 如何做到确认单据禁止删除
    elementplusdjangodrf如何做到确认单据禁止删除  要在Django和DjangoRestFramework(DRF)中实现禁止删除确认单据的功能,你可以通过以下步骤来完成:创建模型:首先,你需要在Django中创建一个模型来表示确认单据。这个模型应该包含与确认单据相关的所有信......
  • 【原创】BGP常见的邻居错误代码
                                                        BGP建立邻居的常见错误代码 在BGP建立邻居的过程当中,若邻居建立有问题,则会在BGP的Notification报文中出现常......
  • 常见的Java中SQL注解的用法
    @Select:用于查询操作,标注在方法上,指定相应的SQL查询语句。@Select("SELECT*FROMtable_nameWHEREcondition")List<Entity>getEntities();@Insert:用于插入操作,标注在方法上,指定相应的SQL插入语句@Insert("INSERTINTOtable_name(column1,column2)VALUES(#{value1}......
  • mybatisPlus更新时字段为空时不更新问题
    **需求**:当数据库字段为数字类型时,更新该个字段的时候,如果前端传来的值为null或者"",此时mybatisPlus的更新方法会自动忽略该字段;这种情况下可以在实体类该字段上加@TableField(updateStrategy=FieldStrategy.IGNORED),忽略为空不更新的策略,此时再更新就会把库中的值更......
  • Java中的常见异常
    Java语言中包含了许多内置异常,这些异常可以分为两大类:检查型异常(CheckedExceptions)和非检查型异常(UncheckedExceptions)。检查型异常是在编译时必须被处理的异常,如IOException、ClassNotFoundException等。非检查型异常是运行时异常,如NullPointerException、ArrayIndexOutOfBounds......