In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.