一:后台java拼凑前台传入的id
<span style="font-size:18px;">String eventtype = request.getParameter("eventtype") == null ? "全部" : request.getParameter("eventtype");</span>
<span style="font-size:18px;"></span><pre name="code" class="java"> StringBuilder selsectEventtypeSb = new StringBuilder();if (!eventtype.equals("全部") & !eventtype.equals("")) {String selsectEventtype = eventtype.replace(";", " ");String regex = "\\S*"; //除空格符外复选框id的获取Pattern p = pile(regex);Matcher m = p.matcher(selsectEventtype);StringBuilder sb = new StringBuilder(); //封装字符串,idselsectEventtypeSb.append("(");while (m.find()) {if (!"".equals(m.group())) {selsectEventtypeSb.append("'").append(m.group()).append("',");}}selsectEventtypeSb.replace(selsectEventtypeSb.length() - 1, selsectEventtypeSb.length(), "");selsectEventtypeSb.append(")");HashMap selsectSinInMonitorMap = new HashMap();selsectSinInMonitorMap.put("selsectEventtypeSb", selsectEventtypeSb);} else {selsectEventtypeSb = null;}
结果:('12','34','12','78')
mybaits语句:
eventType in ${eventType}
二:后台解析字符串如("张三";"李四";"王五"),分别解析出,进行数据库查询id,拼凑需要的数据库value
/*** @param id * @param authority 多个名字*/public void linkInfo(String id, String authority) {String selsectEventtype = authority.replace(";", " ");String regex = "\\S*"; //除空格符外复选框id的获取 Pattern p = pile(regex);Matcher m = p.matcher(selsectEventtype);HashMap map = new HashMap();while (m.find()) {StringBuilder sb = new StringBuilder();if (!"".equals(m.group())) {map.put("name", m.group());String monotorPointID = dao.queryIdByAuthority(map);sb.append("('").append(UUID.randomUUID().toString()).append("','").append(id).append("','").append(monotorPointID).append("','").append("allPay").append("'),");sb.replace(sb.length() - 1, sb.length(), "");map.put("info", sb);dao.insertPersonPointPower(map);}}}
<update id="insertPersonPointPower" parameterType="Map" > INSERT into dwms_t_personpointpower(id,personID,monitorPointID,periodID)VALUES ${info}</update>
如果觉得《解析字符串张三 李四 王五 分别取出值》对你有帮助,请点赞、收藏,并留下你的观点哦!