编辑
2024-04-23
学习记录
00

前提

mybatisPlus更新时,如果想让一个字段为空,实体类字段设置为null时,mybatisPlus默认会直接忽略这个字段的内容,就是不会把空值更新到数据库中,避免出现问题。

解决方法

修改MybatisPlus全局配置

application.yml文件修改配置,但是不推荐,每次使用实体类更新时都需要把所有字段的内容都填上,不然就会出现空值替换的问题

yml
mybatis-plus: global-config: #字段策略 0:"忽略判断",1:"非 NULL 判断",2:"非空判断" field-strategy: 0

使用条件构造器

java
LambdaUpdateWrapper<User> updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.set(User::getName,null); userMapper.updateById(null,updateWrapper)

实体类属性加注解

这个问题和全局配置一样,使用时需要非常的小心

//不忽略null @TableField(strategy = FieldStrategy.IGNORED) private Integer keyStroke; //键盘快捷键

手动编写更新sql

在mapper.xml,编写更新sql

UPDATE REC_TYPE_DICT SET key_stroke=? WHERE id=?
编辑
2024-04-12
学习记录
00

说明

在Oracle中,物化视图(Materialized View)是一种预计算并存储查询结果的数据库对象,常用于提高复杂查询的性能。物化视图与普通视图不同,它实际上存储了数据,因此可以快速响应查询请求。

以下是创建和使用物化视图的基本步骤:

创建物化视图:使用CREATE MATERIALIZED VIEW语句来创建物化视图,并指定要查询的表和列以及WHERE子句(如果需要)。

刷新物化视图:物化视图需要定期刷新以保持数据的准确性。可以使用DBMS_REFRESH包或DBMS_SNAPSHOT包来管理刷新过程。

使用物化视图:在SQL查询中像使用普通表一样使用物化视图。

删除物化视图:如果不再需要物化视图,可以使用DROP MATERIALIZED VIEW语句将其删除。

编辑
2024-04-07
学习记录
00

前提

有时候使用Ipage包裹对象后,需求有要求我们返回另外的内容,比如返回查询列表的同时,还需要返回当前的出院总人数

解决方式:

  • 返回对象改成Map或者在外面套一个新的对象,新对象属性有两个,一个是Ipage<t>,另外的就是出院总人数
  • 新增一个出院总人数的接口、前端调用原来的接口以及新的接口
  • 自定义一个Ipage,在自定义的分页对象里面,新增一个出院总人数的属性

先继承mybatis自带的Ipage

java
public interface IDisPage<T> extends IPage<T> { IPage<T> setDisCount(Integer count); //get方法很重要,缺少get方法,会忽略掉这个新增结果 Integer getDisCount(); }
编辑
2024-04-03
学习记录
00

内链接

内链接是获取两个表的交集

sql
select * from a join b on a.id=b.id select * from a inner join b on a.id=b.id --oracle中还可以实现 select * from a,b where a.id=b.id

左连接

左链接是获取两个表的交集,以及左边表所有的内容,不满足的记录会用null字段表示

sql
select * from a left join b on a.id=b.id select * from a left outer join b on a.id=b.id --oracle中还可以实现 select * from a,b where a.id(+)=b.id

右连接

右链接是获取两个表的交集,以及右边表所有的内容,不满足的记录会用null字段表示

sql
select * from a right join b on a.id=b.id select * from a right outer join b on a.id=b.id --oracle中还可以实现 select * from a,b where a.id=b.id(+)

全连接

全链接是获取两个表所有的记录

sql
select * from a full join b on a.id=b.id select * from a full outer join b on a.id=b.id --oracle中还可以实现 select * from a,b where a.id(+)=b.id(+)
编辑
2024-03-17
学习记录
00

简介

生产者-消费者问题是多线程环境中一个经典的同步问题。它描述了两个进程(这里是线程)——生产者和消费者,如何通过一个有限的缓冲区进行通信。生产者生成数据并将其放入缓冲区,而消费者则从缓冲区中取出数据并使用它。关键是要确保这两个进程不会同时对同一个数据项进行操作,这通常通过互斥锁实现。

wait和notityAll实现

java
public class ProducerConsumerExample { // 定义一个固定大小的缓冲区,用于存储生产者生成的数据项 private static final Object[] buffer = new Object[10]; // 计数器,用于追踪当前缓冲区中数据项的数量 private static int count = 0; public static void main(String[] args) { // 创建并启动生产者线程 Thread producerThread = new Thread(new Producer(), "ProducerThread"); // 创建并启动消费者线程 Thread consumerThread = new Thread(new Consumer(), "ConsumerThread"); producerThread.start(); consumerThread.start(); } static class Producer implements Runnable { @Override public void run() { while (true) { // 生产者持续运行 synchronized (buffer) { // 对缓冲区加锁以保证同步 // 如果缓冲区已满,则等待直到有空间可用 while (count == buffer.length) { try { System.out.println("Buffer is full, waiting..."); buffer.wait(); // Wait if the buffer is full } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } // 在缓冲区中放入一个新的数据项,并增加计数器 buffer[count++] = new Object(); // Produce an item buffer.notifyAll(); // 通知所有可能在等待的消费者线程 System.out.println("Produced one item. Buffer size: " + count); } try { Thread.sleep(100); // 模拟生产所需的时间 } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } static class Consumer implements Runnable { @Override public void run() { while (true) { // 消费者持续运行 synchronized (buffer) { // 对缓冲区加锁以保证同步 // 如果缓冲区为空,则等待直到有数据项可供消费 while (count == 0) { try { System.out.println("Buffer is empty, waiting..."); buffer.wait(); // Wait if the buffer is empty } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } // 从缓冲区取出一个数据项,并减少计数器 buffer[--count] = null; // Consume an item buffer.notifyAll(); // 通知所有可能在等待的生产者线程 System.out.println("Consumed one item. Buffer size: " + count); } try { Thread.sleep(150); // 模拟消费所需的时间 } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } }

这段代码首先定义了一个固定大小的缓冲区(buffer),以及一个计数器count用于追踪当前缓冲区中的项目数量。Producer类实现了Runnable接口,并在其run方法中模拟生产过程。当缓冲区满时,生产者将等待直到有可用空间。Consumer类也实现了Runnable接口,负责从缓冲区消费项目。如果缓冲区为空,消费者也将等待直到有项目可供消费。在生产和消费操作之后,都会调用notifyAll()方法通知另一个可能正在等待的线程