searchjsp.java
来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 189 行
JAVA
189 行
/*
* Created on 2007-5-30
* Last modified on 2007-11-21
* 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.model.Topic;
import com.yeqiangwei.club.model.User;
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.club.view.model.UserView;
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 spage = 1;
private int searchType = 1;
private String keys = "";
private int totalRows = 0;
private long runtimed = 0;
public SearchJsp(HttpServletRequest request, HttpServletResponse response) {
super(request, response);
searchType = ParamUtils.getIntParameter(request,"t",1);
spage = ParamUtils.getIntParameter(request,"spage",1);
keys = ParamUtils.getStringParameter(request, "q", "").trim();
if(!Validator.isEmpty(keys)){
keys = this.keyFilter(keys);
keys = URL.urlDecoder(keys,"UTF-8");
keys = StringHelper.toUTF8(keys);
}
}
public String keyFilter(String keys){
keys = keys.replace("%","");
keys = keys.replace(">","");
keys = keys.replace("<","");
keys = keys.replace("&","");
return keys;
}
public List<UserView> userResults(int rows){
SearchProvider<User> searcher = SearchFactory.getInstance(SearchProvider.SEARCH_USER);
if(Validator.isEmpty(keys)){
return null;
}
SearchParameter param = new SearchParameter();
param.setPage(new Integer(spage));
param.setRows(new Integer(rows));
param.setHighlight(true);
param.setKeys(keys);
param.setSex(ParamUtils.getStringParameter(request,"sex","0"));
List<User> mlist = searcher.results(param);
List<UserView> list = new ArrayList<UserView>();
if(!Validator.isEmpty(mlist)){
for(int i=0; i<mlist.size(); i++){
User model = (User) mlist.get(i);
UserView view = new UserView();
BeanUtils.copyProperties(view, model);
list.add(view);
}
this.totalRows = searcher.getTotalrows();
this.runtimed = searcher.getRuntimed();
StringBuffer url = new StringBuffer();
url.append("search.jsp?q=");
url.append(URL.urlEncoder(keys,"UTF-8"));
url.append("&t=");
url.append(searchType);
url.append("&sex=");
url.append(param.getSex());
url.append("&spage=");
this.setPagination(OutPrint.pagination(spage, rows, this.totalRows, url.toString(),5));
return list;
}
else{
return null;
}
}
public List<TopicView> topicResults(int rows){
if(Validator.isEmpty(keys)){
return null;
}
SearchProvider<Topic> searcher = SearchFactory.getInstance(SearchProvider.SEARCH_TOPIC);
int forumId = ParamUtils.getIntParameter(request,"forumId");
SearchParameter param = new SearchParameter();
param.setKeys(keys);
param.setForumId(forumId);
param.setPage(new Integer(spage));
param.setRows(new Integer(rows));
param.setHighlight(true);
List<Topic> mlist = searcher.results(param);
List<TopicView> list = new ArrayList<TopicView>();
if(!Validator.isEmpty(mlist)){
for(int i=0; i<mlist.size(); i++){
Topic model = (Topic) mlist.get(i);
TopicView view = new TopicView();
BeanUtils.copyProperties(view, model);
view.setContent(model.getTContent().getContent());
list.add(view);
}
this.totalRows = searcher.getTotalrows();
this.runtimed = searcher.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("&spage=");
this.setPagination(OutPrint.pagination(spage, rows, this.totalRows, url.toString(),5));
return list;
}
else{
return null;
}
}
public int getSpage() {
return spage;
}
public void setSpage(int spage) {
this.spage = spage;
}
public String getPagination() {
return pagination;
}
public void setPagination(String pagination) {
this.pagination = pagination;
}
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;
}
public int getSearchType() {
return searchType;
}
public void setSearchType(int searchType) {
this.searchType = searchType;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?