📄 helpsearchcontroller.java
字号:
package net.java.workeffort.webapp.action;import java.util.ArrayList;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.java.workeffort.service.domain.PageResult;import net.java.workeffort.webapp.support.ApplicationSearcher;import net.java.workeffort.webapp.support.HelpSearchQuery;import org.springframework.validation.BindException;import org.springframework.web.servlet.ModelAndView;/** * Controller for searching the application help (Uses Lucene behind the * scenes). * @author Antony Joseph */public class HelpSearchController extends BaseFormController { public HelpSearchController() { setCommandClass(HelpSearchQuery.class); setSuccessView(".helpSearchPageResult"); } /** * Makes the following attributes available in the request scope for the * jsps to render the result appropriately: 'resultList' - The query result, * 'pageSize' - The page size, 'rowCount' - The total row count of the * initial query. * @param request the request * @param response the response * @param command the query parameters * @param errors the bind exception * @return the model and view */ protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { ApplicationSearcher appSearcher = new ApplicationSearcher( getWebApplicationContext()); List resultList = appSearcher.search((HelpSearchQuery) command); // due to limitations of the datagrid, massage the data here. int bodyLength = 0; String url = ""; List list = new ArrayList(); for (int i = 0; i < resultList.size(); i++) { Map map = (Map) resultList.get(i); StringBuffer buffer = new StringBuffer(); buffer.append("<a href=\"./"); // massage the path relative to application. if (map.get("path") != null) url = ((String) map.get("path")).replace('\\', '/'); if (url.indexOf("/help") > -1) { buffer.append(url.substring(url.indexOf("/help"))); } buffer.append("\" target=\"_new\">"); buffer.append(map.get("title")); buffer.append("</a><br />"); if (map.get("body") != null) { if (((String) map.get("body")).length() > 300) bodyLength = 300; else bodyLength = ((String) map.get("body")).length(); buffer.append(((String) map.get("body")).substring(0, bodyLength)); } buffer.append("...<br /><br />"); list.add(buffer.toString()); } // set result attributes so that the Jsps can find it. request.setAttribute("resultList", list); return new ModelAndView(getSuccessView()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -