业务方法如下:
1public Document getAutoSuggestStr(String queryCode,String queryValue,int pageSize) {
2 Element root = new Element("ea.net");
3 Document doc = new Document(root);
4 int nMaxCount = pageSize;
5
6 int nCount = 0;
7 List namelist = jdbcTemplate.queryForList(xmlService.get(
8 queryCode, queryValue));
9
10 for (Iterator it = namelist.iterator(); it.hasNext(); ) {
11 ListOrderedMap listOrderdMap = (ListOrderedMap) it.next();
12
13 Element ele = new Element("object");
14 StringBuffer sb = new StringBuffer();
15 if (listOrderdMap != null && !listOrderdMap.isEmpty()) {
16 Set set = listOrderdMap.keySet();
17 for (Object key : set) {
18 String value = (String) listOrderdMap.get(key);
19 if (StringUtils.isNotBlank(value)) {
20 ele.setAttribute((String)key, value);
21 sb.append("[").append(value).append("]");
22 }
23 }
24 }
25 ele.setAttribute("fullcontent", sb.toString());
26 root.addContent(ele);
27
28 nCount++;
29 if (nCount >= nMaxCount)
30 break;
31 }
32 return doc;
33 }主要是从后台数据库进行数据查询并组装成xml格式
这样就达到了使用xml方式完成自动提示功能,今天先总结到这里,以后陆续更新
文章来源于领测软件测试网 https://www.ltesting.net/