查询操作时,最好不要用get方式提交搜索参数,会出现莫名的乱码问题,应该使用post方式,并且进行编码
如下:
- //查询
- $("#searchButton").click(function(){
- var searchAnswerValue = encodeURIComponent($("#searchAnswer").val());
- var searchQuestionValue = encodeURIComponent($("#searchQuestion").val());
- var postJson = {searchQuestion:searchQuestionValue,searchAnswer:searchAnswerValue};
- //传入查询条件参数
- $("#jqgridTable").jqGrid("setGridParam",{postData:postJson});
- //每次提出新的查询都转到第一页
- $("#jqgridTable").jqGrid("setGridParam",{page:1});
- //提交post并刷新表格
- $("#jqgridTable").jqGrid("setGridParam",{url:searchUrl}).trigger("reloadGrid");
- });
后台进行解码然后执行查询,如下:
- @Override
- public String search() {
- /**
- * 第一步,获取查询参数,并设置到queryPage
- */
- QueryPage queryPage = pageActionParameter.getQueryPage();
- //添加查询条件
- if(StringUtils.isNotEmpty(searchAnswer)) {
- try {
- searchAnswer = URLDecoder.decode(searchAnswer,"utf-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- System.out.println("==========the searchAnswer : " + searchAnswer);
- queryPage.addLikeSearch("answer", searchAnswer);
- }
- if(StringUtils.isNotEmpty(searchQuestion)) {
- try {
- searchQuestion = URLDecoder.decode(searchQuestion,"utf-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- System.out.println("==========the searchQuestion : " + searchQuestion);
- queryPage.addLikeSearch("info", searchQuestion);
- }
- /**
- * 第二步,执行查询,并设置结果
- */
- List<ResultLog> resultLogList = resultLogBiz.getResultLogListByPage(queryPage);
- /**
- * 设置pageResult
- */
- pageActionParameter.buildPageResult(resultLogList);
- /**
- * 第三步,返回
- */
- return AJAX_RETURN_TYPE;
- }