In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to achieve batch modification of mybatis xml analysis, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
Mybatis batch modification-xml
Mybatis batch query, batch add not to talk about, today look at batch modification.
Go straight to the code.
The code in the xml file is as follows:
Update pat_doc_pat_info set sex= when # {item.patientId} then # {item.sex}, address= when # {item.patientId} then # {item.address}, birth_time= when # {item.patientId} then # {item.birthTime}, remark= when # {item.patientId} then # {item.remark}, modified_time = now () Belong_hospital = 1 where delete_flag = 1 and doctor_id = when # {item.patientId} then # {item.doctor_id} and patient_id in # {item.patientId}
The code in the mapper class is as follows:
Int batchUpdate (List list)
The test class method is as follows:
@ Autowiredprivate PatDocPatInfoMapper patDocPatInfoMapper;@Testpublic void testMapperMethod () {List updateMappingList = new ArrayList (); PICAPPatientModel model1 = new PICAPPatientModel (); model1.setPatientId (12334); model1.setDoctor_id (5466927); model1.setSex (2); model1.setAddress ("Shanghai Putuo District xxxx"); model1.setBirthTime (new Date ()); model1.setRemark ("ha ha"); PICAPPatientModel model2 = new PICAPPatientModel (); model2.setPatientId (5923302); model2.setDoctor_id (5466927); model2.setSex (1) Model2.setAddress ("1008 Jinshajiang Road, xxxx, Putuo District, Shanghai"); model2.setBirthTime (new Date ()); model2.setRemark ("ha ha adsfsa"); updateMappingList.add (model1); updateMappingList.add (model2); patDocPatInfoMapper.batchUpdate (updateMappingList);} mybatis xml batch update value
I have already saved the names in the table, but I want to add the desired content after these names. For example, if there is one in the table called Qiantang River, I want to change it to Qiantang River system, and all of them are changed in this way, adding the word "water system". This is easy to do. If you use Java to implement, you should first query all the contents and store them in list, then traverse the list and put them into the object, splicing them with Set entity classes, and then Update.
Public Result uuu () {List list = mdWaterSystemService.findAll (); for (MdWaterSystem mdWaterSystem: list) {mdWaterSystem.setWaterName (mdWaterSystem.getWaterName () + "Water system"); mdWaterSystemService.updates (mdWaterSystem);} return ResponseMsgUtil.success (list);}
Although this can be achieved, it can be written directly in SQL without using code.
Update md_water_system set water_name = CONCAT (IFNULL (water_name,''), IFNULL ('water system','))
Use the CONCAT function to add what you want to add to the existing content.
If you don't want it again, you can replace it with SQL
Update md_water_system set water_name = REPLACE (water_name, 'water system','')
The REPLACE function is a replacement function. You can write the contents of the field to be replaced.
The above content is the analysis of how to implement batch modification of xml by mybatis. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.