Update wrapper
# LambdaEsUpdateWrapper
This conditional constructor is mainly used to update the data when you need to update the fields and their values or the encapsulation of the query conditions
The encapsulation of the query conditions is the same as the methods provided in the LambdaEsQueryWrapper, the only difference is the set method
# set
set(String column, Object val)
set(boolean condition,String column,Object val)
1
2
2
- SQL SET field
- Example: set("name", "Lao Li Tou")
- Example: set("name", "")--->Database field value becomes empty string
- Example: set("name", null)--->Database field value becomes null
Use case:
/**
* LambdaEsUpdateWrapper Use Case - Update data based on conditions
*/
@Test
public void testUpdate() {
// case1: update by condition and entity object update
LambdaEsUpdateWrapper<Document> wrapper = new LambdaEsUpdateWrapper<>();
wrapper.eq(Document::getTitle, title1);
Document document = new Document();
document.setTitle("The Old King Next Door King");
document.setContent("push* technology too soft");
document.setCustomField("Ullabala in the magic fairy");
documentMapper.update(document, wrapper);
// case2 Another simple way to omit entities, the syntax is the same as MP
LambdaEsUpdateWrapper<Document> wrapper1 = new LambdaEsUpdateWrapper<>();
wrapper1.eq(Document::getTitle, title1);
wrapper1.set(Document::getContent, "push*technology too soft")
.set(Document::getCustomField, "ura bara in magic fairy");
documentMapper.update(null,wrapper1);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Help us improve this document (opens new window)
Last update: 2024/03/29