Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Pass a list in the sql and return a list

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

-incoming array-returns list-String [] sendPersonIdArr = sendPersonId.split (","); List list = staffInfoService.ListPhonesByIds (sendPersonIdArr) SELECT h.telphone from hr_staff_info h left JOIN sys_user u on h.STAFFINFO_ID=u.STAFF_ID where u.id in # {item}-input List---- and return List- public List FindByUserIdList (List userlist) throws Exception {return (List) dao.findForList ("UserMapper.findByUserIdList") Userlist) } select * from sys_user where id in # {item}-input a map- batch modification data-controller: Map map = new HashMap (); map.put ("notifyNum", notifyNum) Map.put ("userIdArr", userIdArr); userService.sendNotify (map) In sql: update user set notify_codes=if (notify_codes is null or notify_codes='',# {notifyNum}, CONCAT (notify_codes,',',# {notifyNum})) where id in # {item} Summary: ① has passed a String notifyNum and a String [] userIdArr All we have to do is match the names in sql. ② batch modification can also be made with in ③. When modifying, we can append a string directly to the original field value. When the original value is a number, we can update user set notify_codes=notify_codes+'2' where id='24' like this, assuming that the original value is 5, so now it is 7. When the original value is of type String, we can append it with CONCAT (notify_codes,',',# {notifyNum}). For example, if you add a ", 13" to "12" now, then the result is "12 notify_codes is null or notify_codes='',' 13" when ④ determines whether a field is empty or not, use if (return this value if the notify_codes is null or notify_codes='',' is empty or an empty string', return this value if not empty)

The second way: the whole statement loop (unverified by yourself)

Update test test=$ {item.test} + 1 where id = ${item.id}

In sql, we can pass in a list or an array and return a list.

Here we use In in sql and traversal in sql.

When we want to pass the String parameter to mapper.xml, we need to set the

ParameterType= "String"

At the same time, make sure that the parameter names in impl are the same as those in sql.

As follows:

@ Override public User findByUE (String userId) throws Exception {return (User) dao.findForObject ("UserMapper.findById", userId);} sql: u.id = # {userId}

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.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report