赞
踩
1、jsp端建立搜索框
<form role="form" action="/websearch/search" method="post" id="lucenesearchFormId" class="navbar-form navbar-left hidden-xs hidden-sm" role="search"> <div class="form-group"> <input type="text" name="keyword" id="keyword" class="form-control input-sm" placeholder="查询公开维修案例"> <input type="hidden" id="pageNumId" name="pagenum"> </div> <button type="submit" class="btn btn-default btn-sm">检索</button> </form>
2、controller端代码
@RequestMapping(value = "/search", method = RequestMethod.POST) public String Search(String keyword,Model model) { System.out.println(keyword); List<Document> documentList = documentService.getDocumentByLikeTitle(keyword); // Document document=documentService.getDocumentById(doc_ID); model.addAttribute("document", documentList); return "/comment/search"; }
3、service层创建getDocumentByLikeTitle()方法
List<Document> getDocumentByLikeTitle(String keyword);
4、dao事务管理层制定hql数据库查询操作,这里使用模糊查询方式(有待提升查询效率)
public List<Document> getDocumentByLikeTitle(String keyword){ String hql="from Document d where d.title like ? or d.doc_Abstract like ?"; Query query=currentSession().createQuery(hql); query.setString(0,"%"+keyword+"%"); query.setString(1,"%"+keyword+"%"); return (List<Document>) query.list(); }
5、前端显示查询结果
<c:forEach items="${document}" var="d"> <tr> <td>${d.doc_ID}</td> <td>${d.title}</td> <td>${d.doc_Abstract}</td> <td> <c:if test="${d.doc_CarType=='00'}">未选择车型</c:if> <c:if test="${d.doc_CarType=='0'}">HL10000</c:if> <c:if test="${d.doc_CarType=='1'}">HL23000</c:if> <c:if test="${d.doc_CarType=='2'}">HL32110</c:if> </td> <td> <a href="<c:url value="/know/edit" />?doc_ID=${d.doc_ID}">显示</a> <a href="<c:url value="/know/editknow" />?doc_ID=${d.doc_ID}">编辑</a> <a href="<c:url value="/know/deleteDocumentById" />?doc_ID=${d.doc_ID}" οnclick="return confirm('你确定要删除吗?')">删除</a> </td> </tr> </c:forEach>
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。