MyBatis-Plus入门教程及基本API使用案例

一、MyBatisPlus简介

1. 入门案例

问题导入

MyBatisPlus环境搭建的步骤?

1.1 SpringBoot整合MyBatisPlus入门程序

①:创建新模块,选择Spring初始化,并配置模块相关基础信息

MyBatis-Plus入门教程及基本API使用案例
②:选择当前模块需要使用的技术集(仅保留JDBC)

MyBatis-Plus入门教程及基本API使用案例
③:手动添加MyBatisPlus起步依赖

    com.baomidou
    mybatis-plus-boot-starter
    3.4.1

    com.alibaba
    druid
    1.1.16

注意事项1:由于mp并未被收录到idea的系统内置配置,无法直接选择加入

注意事项2:如果使用Druid数据源,需要导入对应坐标

④:制作实体类与表结构

(类名与表名对应,属性名与字段名对应)

create database if not exists mybatisplus_db character set utf8;
use mybatisplus_db;
CREATE TABLE user (
            id bigint(20) primary key auto_increment,
            name varchar(32) not null,
            password  varchar(32) not null,
            age int(3) not null ,
            tel varchar(32) not null
);
insert into user values(null,'tom','123456',12,'12345678910');
insert into user values(null,'jack','123456',8,'12345678910');
insert into user values(null,'jerry','123456',15,'12345678910');
insert into user values(null,'tom','123456',9,'12345678910');
insert into user values(null,'snake','123456',28,'12345678910');
insert into user values(null,'张益达','123456',22,'12345678910');
insert into user values(null,'张大炮','123456',16,'12345678910');
public class User {
    private Long id;
    private String name;
    private String password;
    private Integer age;
    private String tel;
    //自行添加getter、setter、toString()等方法
}
⑤:设置Jdbc参数( application.yml
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC
    username: root
    password: root
⑥:定义数据接口,继承 BaseMapper
package com.itheima.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.User;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserDao extends BaseMapper {
}

⑦:测试类中注入dao接口,测试功能
package com.itheima;

import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class Mybatisplus01QuickstartApplicationTests {

    @Autowired
    private UserDao userDao;

    @Test
    void testGetAll() {
        List userList = userDao.selectList(null);
        System.out.println(userList);
    }
}

2. MyBatisPlus概述

问题导入

通过入门案例制作,MyBatisPlus的优点有哪些?

2.1 MyBatis介绍

2.2 MyBatisPlus特性

  • 无侵入:只做增强不做改变,不会对现有工程产生影响
  • 强大的 CRUD 操作:内置通用 Mapper,少量配置即可实现单表CRUD 操作
  • 支持 Lambda:编写查询条件无需担心字段写错
  • 支持主键自动生成
  • 内置分页插件
  • ……

二、标准数据层开发

1. MyBatisPlus的CRUD操作

MyBatis-Plus入门教程及基本API使用案例
package com.itheima;

import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
class Mybatisplus01QuickstartApplicationTests {

    @Autowired
    private UserDao userDao;

    @Test
    void testSave() {
        User user = new User();
        user.setName("黑马程序员");
        user.setPassword("itheima");
        user.setAge(12);
        user.setTel("4006184000");
        userDao.insert(user);
    }

    @Test
    void testDelete() {
        userDao.deleteById(1401856123725713409L);
    }

    @Test
    void testUpdate() {
        User user = new User();
        user.setId(1L);
        user.setName("Tom888");
        user.setPassword("tom888");
        userDao.updateById(user);
    }

    @Test
    void testGetById() {
        User user = userDao.selectById(2L);
        System.out.println(user);
    }

    @Test
    void testGetAll() {
        List userList = userDao.selectList(null);
        System.out.println(userList);
    }
}

2. Lombok插件介绍

问题导入

有什么简单的办法可以自动生成实体类的GET、SET方法?

  • Lombok,一个Java类库,提供了一组注解,简化POJO实体类开发。

    org.projectlombok
    lombok
    1.18.12

  • 常用注解:@Data,为当前实体类在编译期设置对应的get/set方法,无参/无参构造方法,toString方法,hashCode方法,equals方法等
package com.itheima.domain;

import lombok.*;
/*
    1 生成getter和setter方法:@Getter、@Setter
      生成toString方法:@ToString
      生成equals和hashcode方法:@EqualsAndHashCode

    2 统一成以上所有:@Data

    3 生成空参构造: @NoArgsConstructor
      生成全参构造: @AllArgsConstructor

    4 lombok还给我们提供了builder的方式创建对象,好处就是可以链式编程。 @Builder【扩展】
 */
@Data
public class User {
    private Long id;
    private String name;
    private String password;
    private Integer age;
    private String tel;
}

3. MyBatisPlus分页功能

问题导入

思考一下Mybatis分页插件是如何用的?

3.1 分页功能接口

MyBatis-Plus入门教程及基本API使用案例

3.2 MyBatisPlus分页使用

①:设置分页拦截器作为Spring管理的bean

package com.itheima.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //1 创建MybatisPlusInterceptor拦截器对象
        MybatisPlusInterceptor mpInterceptor=new MybatisPlusInterceptor();
        //2 添加分页拦截器
        mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return mpInterceptor;
    }
}

②:执行分页查询

//分页查询
@Test
void testSelectPage(){
    //1 创建IPage分页对象,设置分页参数
    IPage page=new Page<>(1,3);
    //2 执行分页查询
    userDao.selectPage(page,null);
    //3 获取分页结果
    System.out.println("当前页码值:"+page.getCurrent());
    System.out.println("每页显示数:"+page.getSize());
    System.out.println("总页数:"+page.getPages());
    System.out.println("总条数:"+page.getTotal());
    System.out.println("当前页数据:"+page.getRecords());
}

3.3 开启MyBatisPlus日志

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC
    username: root
    password: root
开启mp的日志(输出到控制台)
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

3.4 解决日志打印过多问题

3.4.1 取消初始化spring日志打印

MyBatis-Plus入门教程及基本API使用案例

做法:在resources下新建一个logback.xml文件,名称固定,内容如下:


关于logback参考播客:https://www.jianshu.com/p/75f9d11ae011

3.4.2 取消SpringBoot启动banner图标

MyBatis-Plus入门教程及基本API使用案例
spring:
  main:
    banner-mode: off # 关闭SpringBoot启动图标(banner)
3.4.3 取消MybatisPlus启动banner图标

MyBatis-Plus入门教程及基本API使用案例
mybatis-plus日志控制台输出
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    banner: off # 关闭mybatisplus启动图标

三、DQL编程控制

1. 条件查询方式

  • MyBatisPlus将书写复杂的SQL查询条件进行了封装,使用编程的形式完成查询条件的组合

MyBatis-Plus入门教程及基本API使用案例

1.1 条件查询

1.1.1 方式一:按条件查询
//方式一:按条件查询
QueryWrapper qw=new QueryWrapper<>();
qw.lt("age", 18);
List userList = userDao.selectList(qw);
System.out.println(userList);
1.1.2 方式二:lambda格式按条件查询
//方式二:lambda格式按条件查询
QueryWrapper qw = new QueryWrapper();
qw.lambda().lt(User::getAge, 10);
List userList = userDao.selectList(qw);
System.out.println(userList);
1.1.3 方式三:lambda格式按条件查询(推荐)
//方式三:lambda格式按条件查询
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
lqw.lt(User::getAge, 10);
List userList = userDao.selectList(lqw);
System.out.println(userList);

1.2 组合条件

1.2.1 并且关系(and)
//并且关系
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
//并且关系:10到30岁之间
lqw.lt(User::getAge, 30).gt(User::getAge, 10);
List userList = userDao.selectList(lqw);
System.out.println(userList);
1.2.2 或者关系(or)
//或者关系
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
//或者关系:小于10岁或者大于30岁
lqw.lt(User::getAge, 10).or().gt(User::getAge, 30);
List userList = userDao.selectList(lqw);
System.out.println(userList);

1.3 NULL值处理

问题导入

如下搜索场景,在多条件查询中,有条件的值为空应该怎么解决?

MyBatis-Plus入门教程及基本API使用案例
1.3.1 if语句控制条件追加
Integer minAge=10;  //将来有用户传递进来,此处简化成直接定义变量了
Integer maxAge=null;  //将来有用户传递进来,此处简化成直接定义变量了
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
if(minAge!=null){
    lqw.gt(User::getAge, minAge);
}
if(maxAge!=null){
    lqw.lt(User::getAge, maxAge);
}
List userList = userDao.selectList(lqw);
userList.forEach(System.out::println);
1.3.2 条件参数控制
Integer minAge=10;  //将来有用户传递进来,此处简化成直接定义变量了
Integer maxAge=null;  //将来有用户传递进来,此处简化成直接定义变量了
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
//参数1:如果表达式为true,那么查询才使用该条件
lqw.gt(minAge!=null,User::getAge, minAge);
lqw.lt(maxAge!=null,User::getAge, maxAge);
List userList = userDao.selectList(lqw);
userList.forEach(System.out::println);
1.3.3 条件参数控制(链式编程)
Integer minAge=10;  //将来有用户传递进来,此处简化成直接定义变量了
Integer maxAge=null;  //将来有用户传递进来,此处简化成直接定义变量了
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
//参数1:如果表达式为true,那么查询才使用该条件
lqw.gt(minAge!=null,User::getAge, minAge)
   .lt(maxAge!=null,User::getAge, maxAge);
List userList = userDao.selectList(lqw);
userList.forEach(System.out::println);

2. 查询投影-设置【查询字段、分组、分页】

2.1 查询结果包含模型类中部分属性

/*LambdaQueryWrapper lqw = new LambdaQueryWrapper();
lqw.select(User::getId, User::getName, User::getAge);*/
//或者
QueryWrapper lqw = new QueryWrapper();
lqw.select("id", "name", "age", "tel");
List userList = userDao.selectList(lqw);
System.out.println(userList);

2.2 查询结果包含模型类中未定义的属性

QueryWrapper lqw = new QueryWrapper();
lqw.select("count(*) as count, tel");
lqw.groupBy("tel");
List> userList = userDao.selectMaps(lqw);
System.out.println(userList);

3. 查询条件设定

问题导入

多条件查询有哪些组合?

  • 范围匹配(> 、 = 、between)
  • 模糊匹配(like)
  • 空判定(null)
  • 包含性匹配(in)
  • 分组(group)
  • 排序(order)
  • ……

3.1 查询条件

  • 用户登录(eq匹配)
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
//等同于=
lqw.eq(User::getName, "Jerry").eq(User::getPassword, "jerry");
User loginUser = userDao.selectOne(lqw);
System.out.println(loginUser);
  • 购物设定价格区间、户籍设定年龄区间(le ge匹配 或 between匹配)
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
//范围查询 lt le gt ge eq between
lqw.between(User::getAge, 10, 30);
List userList = userDao.selectList(lqw);
System.out.println(userList);
  • 查信息,搜索新闻(非全文检索版:like匹配)
LambdaQueryWrapper lqw = new LambdaQueryWrapper();
//模糊匹配 like
lqw.likeLeft(User::getName, "J");
List userList = userDao.selectList(lqw);
System.out.println(userList);
  • 统计报表(分组查询聚合函数)
QueryWrapper qw = new QueryWrapper();
qw.select("gender","count(*) as nums");
qw.groupBy("gender");
List> maps = userDao.selectMaps(qw);
System.out.println(maps);

3.2 查询API

3.3 练习:MyBatisPlus练习

题目:基于MyBatisPlus_Ex1模块,完成Top5功能的开发。

  • 说明: ①:Top5指根据销售量排序(提示:对销售量进行降序排序) ②:Top5是仅获取前5条数据(提示:使用分页功能控制数据显示数量)

4. 字段映射与表名映射

问题导入

思考表的字段和实体类的属性不对应,查询会怎么样?

4.1 问题一:表字段与编码属性设计不同步

  • 在模型类属性上方,使用 @TableField属性注解,通过 value属性,设置当前属性对应的数据库表中的字段关系。

MyBatis-Plus入门教程及基本API使用案例

4.2 问题二:编码中添加了数据库中未定义的属性

  • 在模型类属性上方,使用 @TableField注解,通过 exist属性,设置属性在数据库表字段中是否存在,默认为true。此属性无法与value合并使用。

MyBatis-Plus入门教程及基本API使用案例

4.3 问题三:采用默认查询开放了更多的字段查看权限

  • 在模型类属性上方,使用 @TableField注解,通过 select属性:设置该属性是否参与查询。此属性与select()映射配置不冲突。

MyBatis-Plus入门教程及基本API使用案例

4.4 问题四:表名与编码开发设计不同步

  • 模型类上方,使用 @TableName注解,通过 value属性,设置当前类对应的数据库表名称。

MyBatis-Plus入门教程及基本API使用案例
@Data
@TableName("tbl_user")
public class User {
    /*
        id为Long类型,因为数据库中id为bigint类型,
        并且mybatis有自己的一套id生成方案,生成出来的id必须是Long类型
     */
    private Long id;
    private String name;
    @TableField(value = "pwd",select = false)
    private String password;
    private Integer age;
    private String tel;
    @TableField(exist = false) //表示online字段不参与CRUD操作
    private Boolean online;
}

四、DML编程控制

1. id生成策略控制(Insert)

问题导入

主键生成的策略有哪几种方式?

不同的表应用不同的id生成策略

  • 日志:自增(1,2,3,4,……)
  • 购物订单:特殊规则(FQ23948AK3843)
  • 外卖单:关联地区日期等信息(10 04 20200314 34 91)
  • 关系表:可省略id
  • ……

1.1 id生成策略控制(@TableId注解)

  • 名称:@TableId
  • 类型: 属性注解
  • 位置:模型类中用于表示主键的属性定义上方
  • 作用:设置当前类中主键属性的生成策略
    MyBatis-Plus入门教程及基本API使用案例

1.2 全局策略配置

mybatis-plus:
  global-config:
    db-config:
      id-type: assign_id
      table-prefix: tbl_
id生成策略全局配置

MyBatis-Plus入门教程及基本API使用案例
表名前缀全局配置

MyBatis-Plus入门教程及基本API使用案例

2. 多记录操作(批量Delete/Select)

问题导入

MyBatisPlus是否支持批量操作?

MyBatis-Plus入门教程及基本API使用案例

2.1 按照主键删除多条记录

//删除指定多条数据
List list = new ArrayList<>();
list.add(1402551342481838081L);
list.add(1402553134049501186L);
list.add(1402553619611430913L);

userDao.deleteBatchIds(list);

2.2 根据主键查询多条记录

//查询指定多条数据
List list = new ArrayList<>();
list.add(1L);
list.add(3L);
list.add(4L);
userDao.selectBatchIds(list);

3. 逻辑删除(Delete/Update)

问题导入

在实际环境中,如果想删除一条数据,是否会真的从数据库中删除该条数据?

  • 删除操作业务问题:业务数据从数据库中丢弃
  • 逻辑删除:为数据设置是否可用状态字段,删除时设置状态字段为不可用状态,数据保留在数据库中

MyBatis-Plus入门教程及基本API使用案例

3.1 逻辑删除案例

①:数据库表中添加逻辑删除标记字段

MyBatis-Plus入门教程及基本API使用案例
②:实体类中添加对应字段,并设定当前字段为逻辑删除标记字段
package com.itheima.domain;

import com.baomidou.mybatisplus.annotation.*;

import lombok.Data;

@Data
public class User {

    private Long id;

    //逻辑删除字段,标记当前记录是否被删除
    @TableLogic
    private Integer deleted;

}
③:配置逻辑删除字面值
mybatis-plus:
  global-config:
    db-config:
      table-prefix: tbl_
      # 逻辑删除字段名
      logic-delete-field: deleted
      # 逻辑删除字面值:未删除为0
      logic-not-delete-value: 0
      # 逻辑删除字面值:删除为1
      logic-delete-value: 1

逻辑删除本质:逻辑删除的本质其实是修改操作。如果加了逻辑删除字段,查询数据时也会自动带上逻辑删除字段。

MyBatis-Plus入门教程及基本API使用案例

4. 乐观锁(Update)

问题导入

乐观锁主张的思想是什么?

  • 业务并发现象带来的问题:秒杀

MyBatis-Plus入门教程及基本API使用案例

4.1 乐观锁案例

①:数据库表中添加锁标记字段

MyBatis-Plus入门教程及基本API使用案例
②:实体类中添加对应字段,并设定当前字段为逻辑删除标记字段
package com.itheima.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import lombok.Data;

@Data
public class User {

    private Long id;

    @Version
    private Integer version;
}

③:配置乐观锁拦截器实现锁机制对应的动态SQL语句拼装
package com.itheima.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MpConfig {
    @Bean
    public MybatisPlusInterceptor mpInterceptor() {
        //1.定义Mp拦截器
        MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();

        //2.添加乐观锁拦截器
        mpInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());

        return mpInterceptor;
    }
}

④:使用乐观锁机制在修改前必须先获取到对应数据的verion方可正常进行
@Test
public void testUpdate() {
    /*User user = new User();
    user.setId(3L);
    user.setName("Jock666");
    user.setVersion(1);
    userDao.updateById(user);*/

    //1.先通过要修改的数据id将当前数据查询出来
    //User user = userDao.selectById(3L);
    //2.将要修改的属性逐一设置进去
    //user.setName("Jock888");
    //userDao.updateById(user);

    //1.先通过要修改的数据id将当前数据查询出来
    User user = userDao.selectById(3L);     //version=3
    User user2 = userDao.selectById(3L);    //version=3
    user2.setName("Jock aaa");
    userDao.updateById(user2);              //version=>4
    user.setName("Jock bbb");
    userDao.updateById(user);               //verion=3?条件还成立吗?
}

MyBatis-Plus入门教程及基本API使用案例

五、快速开发-代码生成器

问题导入

如果只给一张表的字段信息,能够推演出Domain、Dao层的代码?

1. MyBatisPlus提供模板

  • Mapper接口模板

MyBatis-Plus入门教程及基本API使用案例
  • 实体对象类模板

MyBatis-Plus入门教程及基本API使用案例

2. 工程搭建和基本代码编写

  • 第一步:创建SpringBoot工程,添加代码生成器相关依赖,其他依赖自行添加

    com.baomidou
    mybatis-plus-generator
    3.4.1

    org.apache.velocity
    velocity-engine-core
    2.3

  • 第二步:编写代码生成器类
package com.itheima;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;

public class Generator {
    public static void main(String[] args) {
        //1. 创建代码生成器对象,执行生成代码操作
        AutoGenerator autoGenerator = new AutoGenerator();

        //2. 数据源相关配置:读取数据库中的信息,根据数据库表结构生成代码
        DataSourceConfig dataSource = new DataSourceConfig();
        dataSource.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/mybatisplus_db?serverTimezone=UTC");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        autoGenerator.setDataSource(dataSource);

         //3. 执行生成操作
        autoGenerator.execute();
    }
}

3. 开发者自定义配置

  • 设置全局配置
//设置全局配置
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setOutputDir(System.getProperty("user.dir")+"/mybatisplus_04_generator/src/main/java");    //设置代码生成位置
globalConfig.setOpen(false);    //设置生成完毕后是否打开生成代码所在的目录
globalConfig.setAuthor("黑马程序员");    //设置作者
globalConfig.setFileOverride(true);     //设置是否覆盖原始生成的文件
globalConfig.setMapperName("%sDao");    //设置数据层接口名,%s为占位符,指代模块名称
globalConfig.setIdType(IdType.ASSIGN_ID);   //设置Id生成策略
autoGenerator.setGlobalConfig(globalConfig);
  • 设置包名相关配置
//设置包名相关配置
PackageConfig packageInfo = new PackageConfig();
packageInfo.setParent("com.aaa");   //设置生成的包名,与代码所在位置不冲突,二者叠加组成完整路径
packageInfo.setEntity("domain");    //设置实体类包名
packageInfo.setMapper("dao");   //设置数据层包名
autoGenerator.setPackageInfo(packageInfo);
  • 策略设置
//策略设置
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig.setInclude("tbl_user");  //设置当前参与生成的表名,参数为可变参数
strategyConfig.setTablePrefix("tbl_");  //设置数据库表的前缀名称,模块名 = 数据库表名 - 前缀名  例如: User = tbl_user - tbl_
strategyConfig.setRestControllerStyle(true);    //设置是否启用Rest风格
strategyConfig.setVersionFieldName("version");  //设置乐观锁字段名
strategyConfig.setLogicDeleteFieldName("deleted");  //设置逻辑删除字段名
strategyConfig.setEntityLombokModel(true);  //设置是否启用lombok
autoGenerator.setStrategy(strategyConfig);

Original: https://www.cnblogs.com/lcha-coding/p/16366441.html
Author: 染沁
Title: MyBatis-Plus入门教程及基本API使用案例

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/620902/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 最新Spring Boot 跨域配置,亲测好用

    背景: 网上有很多跨域配置,但都存在各种各样问题;经过改良和测试后,最终形成一个稳定配置版本,我的Spring Boot版本是2.5.1 问题: 前后端分离后,进行联调,发现浏览器…

    数据库 2023年6月6日
    0110
  • 得体的注释,让我总能想起TA

    作为一个技术TL,在排查生产问题时,我经常要周转于各个工程里。系统和服务多起来后,要我了解每一段代码具体的来龙去脉逐渐几乎不可能了。 例如,今天,我要查一下调用某个三方接口所配置的…

    数据库 2023年6月9日
    0173
  • 工程师成长阶段感悟

    从 2013 年陆续开始做软件研发工作, 去过不少公司, 做过一些类型项目, 桌面开发, web 开发, 手游开发, 端游开发, 棋牌, 视频云服务, 电商. 刚毕业那会在国企, …

    数据库 2023年6月9日
    0102
  • Tomcat端口占用

    进入命令行命令:netstat -ano作用:查看所有端口占用 命令:netstat -aon|findstr 端口号port作用:查看端口号port占用情况 命令:taskkil…

    数据库 2023年6月11日
    067
  • 用 WebClient 代替 RestTemplate

    RestTemplate是用于执行 HTTP 请求的同步客户端,通过底层 HTTP 客户端库(例如 JDK HttpURLConnection、Apache HttpCompone…

    数据库 2023年6月14日
    071
  • 磁盘空间满,如何处理?

    作为运维人员,磁盘空间报警是最寻常遇到的情况,那么遇到空间如何处理呢?这里介绍一下处理办法及处理思路。 操作系统:centos系统 、Ubuntu 1 定位目录 收到空间报警信息,…

    数据库 2023年6月14日
    086
  • MySQL主从同步

    1. 主从同步的定义 主从同步使得数据可以从一个数据库服务器复制到其他服务器上,在复制数据时,一个服务器充当主服务器(master),其余的服务器充当从服务器(slave)。因为复…

    数据库 2023年6月14日
    071
  • Exception Handling Considered Harmful

    Do, or do not. There is no try. — Yoda, The Empire Strikes Back(George Lucas) Recent progr…

    数据库 2023年6月9日
    093
  • HackerRank第一趴–Basic Select

    ID number NAME VARCHAR2(17) COUNTRYCODE VARCHAR2(3) DISTRICT VARCHAR2(20) POPULATION numbe…

    数据库 2023年6月16日
    097
  • 2018年最新JAVA面试题总结之数据库(3)

    转自于:https://zhuanlan.zhihu.com/p/39804394 1、MySQL的delete与truncate区别? 回答:delete语句执行删除的过程是每次…

    数据库 2023年6月16日
    091
  • 关于EF分页查询报错(Count must have a non-negative value.)的解决方案

    具体的异常信息如下,一开始没有写日志只看到错误信息:Count must have a non-negative value.,从表面意思可以看出来是Count值出现了负数,所以报…

    数据库 2023年6月9日
    091
  • centos 自己常用命令

    tar 1. 使用tar压缩文件 tar -zcvf test.tar.gz ./test/ 该命令表示压缩当前文件夹下的文件夹test,压缩后缀名为test.tar.gz 如果不…

    数据库 2023年6月11日
    082
  • Mybatis SqlNode源码解析

    1.ForEachSqlNode mybatis的foreach标签可以将列表、数组中的元素拼接起来,中间可以指定分隔符separator <select id="…

    数据库 2023年6月16日
    080
  • 汇编语言学习记录一

    0x00——什么是汇编语言? 汇编语言:早期实现程序员和机器进行交互的汇编指令集。 汇编指令,通过编译器,转换成机器码,从而使 机器 理解其指令。 0x01——汇编语言的组成 汇编…

    数据库 2023年6月11日
    083
  • 吃饱年代

    Original: https://www.cnblogs.com/life2refuel/p/15211899.htmlAuthor: 喜欢兰花山丘Title: 吃饱年代

    数据库 2023年6月9日
    0114
  • 绕过国内域名备案

    情景:现有域名jsw.top,云服务器1台均在阿里云下。域名jsw.top、www.jsw.top CNAME解析到阿里云OSS的记录值(阿里云OSS会要求备案,导致无法使用),而…

    数据库 2023年6月14日
    092
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球