标签:
package com.licy.projects.study.action.search;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.licy.projects.study.action.BaseAction;
import com.licy.projects.study.entity.ResourceEntity;
import com.licy.projects.study.service.search.SearchService;
/**
* 搜索资源类
* @ClassName: SearchAction
* @Description: TODO()
* @author A18ccms a18ccms_gmail_com
* @date 2015-8-5 下午3:52:41
*/
@Controller
@RequestMapping("/search")
public class SearchAction extends BaseAction{
@Resource(name="searchService")
private SearchService searchService;
private static final Logger LOG = Logger.getLogger(SearchAction.class);
/** 根据关键字ID查询资源列表 */
@RequestMapping("/queryResource")
public String queryResourceList(){
//查询入参
Map<String, Object> map = new HashMap<String,Object>();
//查询出参
List<ResourceEntity> list = new ArrayList<ResourceEntity>();
//搜索关键字
String keyword = this.getValue("keyword");
//栏目id
String column_id = this.getValue("column_id");
//每页大小,默认为5
String pageSize = "".equals(this.getValue("pageSize")) ? "5" : this.getValue("pageSize");
//当前页码,默认为1
String nowPage = "".equals(this.getValue("nowPage")) ? "1" : this.getValue("nowPage");
map.put("keyword", keyword);
map.put("column_id", column_id);
int start = (Integer.parseInt(nowPage)-1) * Integer.parseInt(pageSize);
map.put("pageSize", pageSize);
map.put("start", start);
LOG.info("info搜索关键字是 == " + keyword);
LOG.error("error搜索关键字是 == " + keyword);
List<Object> list1 = searchService.queryResourceList(map);
list = (List<ResourceEntity>) list1.get(0);
int totalSize = (Integer) list1.get(1);
request.setAttribute("keyword", keyword);
request.setAttribute("column_id", column_id);
request.setAttribute("pageSize", pageSize);
request.setAttribute("nowPage", nowPage);
request.setAttribute("totalSize", totalSize);
request.setAttribute("resourceList", list);
return "/study/search/searchResult";
}
/**
* 获取输入框的提示信息
* @Title: getResourceTips
* @author: 李长雨
* @date 2015-8-7 下午11:28:26
* @Description: TODO() void
* @throws
*/
@RequestMapping("/queryResourceTips")
public void queryResourceTips(){
String keyword = this.getValue("keyword").toLowerCase();
String column_id = this.getValue("column_id");
Map<String,Object> map = new HashMap<String,Object>();
map.put("keyword", keyword);
map.put("column_id", column_id);
List<ResourceEntity> list = searchService.queryResourceTips(map);
this.writeJsonData(list);
}
@RequestMapping("/saveSearchRecord")
public void saveSearchRecord(){
String id = this.getValue("id");
int search_count = Integer.parseInt(this.getValue("search_count"));
Map<String,Object> map = new HashMap<String,Object>();
map.put("id", id);
map.put("search_count", search_count+1);//给搜索次数加1,并存入数据库
int result = searchService.saveSearchRecord(map);
this.writeData(result);
}
/** 进入添加资源页面 */
@RequestMapping("/toAddResource")
public String toAddResource(){
return "/study/search/saveResource";
}
/**添加资源 */
@RequestMapping("/saveResource")
public void addResource(){
String save_column_id = this.getValue("save_column_id");
String save_resource_name = this.getValue("save_resource_name");
String save_resource_remark = this.getValue("save_resource_remark");
String save_resource_url = this.getValue("save_resource_url");
Map<String,Object> map = new HashMap<String,Object>();
map.put("column_id", save_column_id);
map.put("resource_name", save_resource_name);
map.put("resource_remark", save_resource_remark);
map.put("resource_url", save_resource_url);
int result = searchService.saveResource(map);
this.writeData(result);
}
public static void main(String[] args) {
PropertyConfigurator.configure( "D:/1__workspace/gong_si_space/sywg_space/licy/src/com/licy/config/log4j.properties" );
Logger logger = Logger.getLogger(SearchAction.class );
}
@RequestMapping("/testSave")
public void testSave(){
String content = this.getValue("content");
System.out.println("获取的内容是 == " + content);
}
}
标签:
原文地址:http://www.cnblogs.com/lichangyu/p/5093794.html