当前位置:网站首页>[records of different objects required by QIPA]
[records of different objects required by QIPA]
2022-06-22 21:22:00 【konmor】

Development is coolie , Recently, there is such a demand :
Log the modified data Those fields have been modified .


ok . I can't wring my arm ,** Of . Do it and you're done .
Demand analysis : No river .
Demand fulfillment : very (bu) difficult (gan).
To record Those have been modified You need to know the field values before and after modification Compare and record . namely The original data of the database Compare with the value passed by the front end .
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Field;
import java.util.*;
/**
* @param clazz Class types
* @param a Previous object
* @param b Object after value
* @param ignores Ignore objects that do not need to be compared
* @param <T>
* @return Different values key: attribute ,value Compare values before and after
* @throws IllegalAccessException
*/
public <T> Map<String, String> findNotEqualFields(Class<T> clazz, T a, T b, Set<String> ignores) throws IllegalAccessException {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
}
Map map = null;
for (Field field : fields) {
if (ignores != null && ignores.contains(field.getName())) {
continue;
}
if (!Objects.equals(field.get(a), field.get(b))) {
if (map == null) {
map = new HashMap();
map.put(" Modification time ",new Date());
}
map.put(field.getName(), StringUtils.join(" Before the change :", field.get(a), ",", " After modification :", field.get(b), ";"));
}
}
return map;
}Recently, there is another demand 【 Personnel and organization information synchronization 】【 Total 】
It is necessary to compare whether the objects are inconsistent , Inconsistent use update, Consistent data is not updated .

Demand analysis : No river .
Demand fulfillment :*******
Don't you know how to use The form of message sending notification , Modify those data Send a notice to the downstream . Then you can modify the data directionally .
Full data comparison Add and modify Such a wonderful flower needs It is entirely a mistake of upstream design .
Implementation scheme :
1. Compare those that are different Record different data And modify it
/**
* @param clazz
* @param a
* @param b
* @param ignores
* @param <T>
* @return
* @throws IllegalAccessException
*/
public <T> Boolean isAllEquals(Class<T> clazz, T a, T b, Set<String> ignores) throws IllegalAccessException {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
}
for (Field field : fields) {
if (ignores != null && ignores.contains(field.getName())) {
continue;
}
if (!Objects.equals(field.get(a), field.get(b))) {
return false;
}
}
return true;
}
边栏推荐
- 【文末送书】火遍全网的AI给老照片上色,这里有一份详细教程!
- Apple GCD source code
- Correspondence between int and char in C language
- 字节跳动提出轻量级高效新型网络MoCoViT,在分类、检测等CV任务上性能优于GhostNet、MobileNetV3!...
- 百家讲坛 黄帝内经(第一部)
- 2022年起重机械指挥考试模拟100题及模拟考试
- MySQL adds (appends) prefix and suffix to a column field
- 百家讲坛 武则天
- 扩展Ribbon支持基于元数据的版本管理
- Operation of simulation test platform for 2022 Shandong safety officer C certificate test
猜你喜欢

NFT,只可远观不可亵玩焉

The access succeeds but an exception is thrown: could not find acceptable representation
![[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!](/img/f0/4f237e7ab1bff9761b6092dd4ef3d9.png)
[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!

已解决:一個錶中可以有多個自增列嗎

Easyclick fixed status log window

Visualization of wine datasets in R language

R language airpassengers dataset visualization
![[142. circular linked list II]](/img/c1/f3a0b863286e9eeda0ae4021420912.png)
[142. circular linked list II]

Moke 6. Load balancing ribbon

采用网络远程访问树莓派。
随机推荐
2022危险化学品经营单位主要负责人上岗证题库及模拟考试
嵌入式开发基础之任务管理(线程管理)
MySql给某列字段添加(追加)前缀后缀
2022团体程序设计天梯赛L1
日本动漫作家和其部分作品
CVPR2022 | 海德堡大学《深度视觉相似性与度量学习》教程
Operation of simulation test platform for 2022 Shandong safety officer C certificate test
2022年起重机械指挥考试模拟100题及模拟考试
【138. 复制带随机指针的链表】
Pytorch's model saving, loading and continuing training
ByteDance proposes a lightweight and efficient new network mocovit, which has better performance than GhostNet and mobilenetv3 in CV tasks such as classification and detection
Huawei cloud releases Latin American Internet strategy
R language usarrests dataset visualization
Remote access to raspberry pie via the Internet.
513. find the value in the lower left corner of the tree / Sword finger offer II 091 Paint the house
R language universalbank CSV "data analysis
How swiftui simulates the animation effect of view illumination increase
[the penultimate node in the linked list]
[redis]Redis6的主从复制
访问成功但抛出异常:Could not find acceptable representation