Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Update syntax in Fluent Mybatis

Shulou Source: shulou.com Published: 2022-06-02 11:35:11 10月05日 Update

Editor to share with you how to use Update grammar in Fluent Mybatis. I hope you will get something after reading this article. Let's discuss it together.

Data preparation

Still use the previous data in the data inventory, as follows:

The simple way to write Update grammar

Fm's update shorthand allows you to directly use is () to assign values to table fields, or to use the isNull () method if you need to set the field to Null.

Interface layer code addition

/ * simple update syntax * * @ return * / Integer updateSimple ()

Implement class code addition

@ Overridepublic Integer updateSimple () {return testFluentMybatisMapper.updateBy (new TestFluentMybatisUpdate () .set .name () .is ("he Jiu") .set .age () .isNull () .end () .where .id () .eq (2) .end ();}

Control layer code addition

@ Autowired private IUpdateService updateService; @ ApiOperation (value = "simple grammar", notes = "simple grammar") @ RequestMapping (value = "/ simple", method = RequestMethod.GET) @ ResponseBodypublic Result updateSimple () {try {return Result.ok (updateService.updateSimple ());} catch (Exception exception) {return Result.error (ErrorCode.BASE_ERROR_CODE.getCode (), exception.getMessage (), null);}}

Verify it.

Code description

1. You can take a look at the specific sql of code execution, as follows:

2021-11-23 13 c.h.f.f.m.T.updateBy 41 DEBUG 20.277 20820-[nio-8090-exec-1] c.h.f.f.m.T.updateBy: = = > Preparing: UPDATE `test_fluent_ mybatis` SET `name` =?, `age` =? WHERE `id` =? 2021-11-23 13 nio-8090-exec-1 4115 20.464 DEBUG 20820-[nio-8090-exec-1] c.h.f.f.m.T.updateBy: = > Parameters: he Jiu (String), null 2 (Integer) 2021-11-23 13 nio-8090-exec-1 41VR 20.470 DEBUG 20820-[nio-8090-exec-1] c.h.f.f.m.T.updateBy: Preparing: UPDATE `test_fluent_ mybatis` SET `name` =?, `age` =? WHERE `id` =? 2021-11-23 13 nio-8090-exec-4 56 DEBUG 20820-[nio-8090-exec-4] c.h.f.f.m.T.updateBy: = > Parameters: String, 29 (Integer) 2 (Integer) 2021-11-23 13 nio-8090-exec-4 56 DEBUG 20820-[nio-8090-exec-4] c.h.f.f.m.T.updateBy: Preparing: UPDATE `test_fluent_ mybatis` SET `name` =?, `create_ time` =? WHERE `id` =? 2021-11-23 15 nio-8090-exec-6 21 nio-8090-exec-6 42.266 DEBUG 20820-[nio-8090-exec-6] c.h.f.f.m.T.updateBy: = > Parameters: String, null 2 (Integer) 2021-11-23 15 nio-8090-exec-6 21 nio-8090-exec-6 DEBUG 20820-[nio-8090-exec-6] c.h.f.f.m.T.updateBy: Preparing: UPDATE `test_fluent_ mybatis` SET `name` = concat (name,?) `age` = age+5 WHERE `id` =? 2021-11-23 1515 DEBUG 09.782 DEBUG 20820-- [nio-8090-exec-8] c.h.f.f.m.T.updateBy: = = > Parameters: _ male (String), 2 (Integer) 2021-11-23 15VR 31VR 09.787 DEBUG 20820-- [nio-8090-exec-8] c.h.f.f.m.T.updateBy:

Tags: Field code update syntax entity data method original word official interface control verification parameter statement function writing that is time article or Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Redmi Shulou Information Docker