📄 searchjsp.java
字号:
/*
* Created on 2007-5-30
* Last modified on 2007-5-30
* Powered by GamVan.com
*/
package com.yeqiangwei.club.view.jsp;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.yeqiangwei.club.service.model.TopicModel;
import com.yeqiangwei.club.service.search.SearchFactory;
import com.yeqiangwei.club.service.search.SearchParameter;
import com.yeqiangwei.club.service.search.SearchProvider;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.view.model.TopicView;
import com.yeqiangwei.html.OutPrint;
import com.yeqiangwei.net.URL;
import com.yeqiangwei.util.ParamUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.Validator;
public class SearchJsp extends BaseJsp{
private String pagination;
private int page = 1;
private String keys = "";
private int totalRows = 0;
private long runtimed = 0;
private SearchProvider searchProvider;
public SearchJsp(HttpServletRequest request, HttpServletResponse response) {
super(request, response);
}
public List<TopicView> resutls(int rows){
keys = ParamUtils.getStringParameter(request, "q", "").trim();
if(Validator.isEmpty(keys)){
return null;
}else{
keys = keys.replace("%","");
keys = keys.replace(">","");
keys = keys.replace("<","");
keys = keys.replace("&","");
}
keys = URL.urlDecoder(keys,"UTF-8");
keys = StringHelper.toUTF8(keys);
page = ParamUtils.getIntParameter(request,"page",1);
int forumId = ParamUtils.getIntParameter(request,"forumId");
SearchParameter param = new SearchParameter();
param.setKeys(keys);
param.setForumId(forumId);
param.setPage(new Integer(page));
param.setRows(new Integer(rows));
List mlist = getSearchProvider().results(param);
List<TopicView> list = new ArrayList<TopicView>();
if(!Validator.isEmpty(mlist)){
for(int i=0; i<mlist.size(); i++){
TopicModel model = (TopicModel) mlist.get(i);
TopicView view = new TopicView();
BeanUtils.copyProperties(view, model);
view.setContent(model.getContentModel().getContent());
list.add(view);
}
this.totalRows = this.getSearchProvider().getTotalrows();
this.runtimed = this.getSearchProvider().getRuntimed();
StringBuffer url = new StringBuffer();
url.append("search.jsp?q=");
url.append(URL.urlEncoder(keys,"UTF-8"));
if(forumId>0){
url.append("&forumId=");
url.append(forumId);
}
url.append("&page=");
this.setPagination(OutPrint.pagination(page, rows, this.totalRows, url.toString(),5));
return list;
}
else{
return null;
}
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public String getPagination() {
return pagination;
}
public void setPagination(String pagination) {
this.pagination = pagination;
}
private SearchProvider getSearchProvider(){
if(Validator.isEmpty(searchProvider)){
return searchProvider = SearchFactory.getInstance(SearchProvider.SEARCH_TOPIC);
}else{
return searchProvider;
}
}
public String getKeys() {
return keys;
}
public void setKeys(String keys) {
this.keys = keys;
}
public long getRuntimed() {
return runtimed;
}
public void setRuntimed(long runtimed) {
this.runtimed = runtimed;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -