前端代码
$('#kfMsgTable').bootstrapTable({
url:'../../../rzsj/selectByParams.action',
striped: true, //是否显示行间隔色
cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
pagination: true, //是否显示分页(*)
sortable: true, //是否启用排序
sortOrder: "asc", //排序方式
sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
pageNumber: 1, //初始化加载第一页,默认第一页,并记录
pageSize: 10, //每页的记录行数(*)
pageList: [10, 25, 50, 100], //可供选择的每页的行数(*)
search: false, //是否显示表格搜索
strictSearch: true,
showColumns: true, //是否显示所有的列(选择显示的列)
showRefresh: true, //是否显示刷新按钮
//得到查询的参数
queryParams : function (params) {
//这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
var temp = {
rows: params.limit, //页面大小
page: (params.offset / params.limit) + 1, //页码
start:(params.offset / params.limit)*params.limit,//从start开始查询
sort: params.sort, //排序列名
sortOrder: params.order, //排位命令(desc,asc)
name:$("#name").val(),
openid:$("#openid").val()
};
return temp;
},
columns:[
{field:'name',title:'姓名',align:'center',valign: 'middle'},
{field:'sfzhm',title:'身份证号码',align:'center',valign: 'middle'},
{field:'tel',title:'联系电话',align:'center',valign: 'middle'},
{field:'openid',title:'用户标识',align:'center',valign: 'middle'},
{field:'rzrq',title:'认证日期',align:'center',valign: 'middle',
formatter:function(value,row,index){
return UnixToDate(value,1);
}
},
{title:"操作",align:"center",valign:"middle",width:200,
formatter:function(value,row,index){
return "<button class='btn btn-primary' onclick='sendKfMsg("+JSON.stringify(row)+")'"+">发送客服消息</button>";
}
}
],
onLoadSuccess: function (data) {
console.log(data);
},
onLoadError: function () {
alert("数据加载失败!")
},
});
springmvc后台接收代码
package cn.njhq.wechat.controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.alibaba.fastjson.JSONObject;
import cn.njhq.wechat.pojo.TbRzsj;
import cn.njhq.wechat.service.RzsjService;
import cn.njhq.wechat.util.SendMessageUtil;
@RequestMapping("rzsj")
@Controller
public class RzsjController {
private Logger logger = Logger.getLogger(RzsjController.class);
@Autowired
private RzsjService rzsjService;
@RequestMapping("/selectByParams")
public void selectByParamse(HttpServletRequest request,HttpServletResponse response,@RequestParam Map<String, Object> params){
JSONObject jsonObject = new JSONObject();
if(params.size() == 0){
logger.info("传递的参数为空!,无法执行下一步");
jsonObject.put("info", "传递的参数为空!,无法执行下一步");
try {
SendMessageUtil.sendMessage(response, jsonObject);
} catch (IOException e) {
e.printStackTrace();
}
return;
}
logger.info(params.toString());
logger.info("********************************************************");
List<TbRzsj> rzsjs = rzsjService.selectByParamse(params);
jsonObject.put("success", true);
jsonObject.put("total", rzsjService.selectTotalByParams(params));
jsonObject.put("rows", rzsjs);
try {
SendMessageUtil.sendMessage(response, jsonObject);
} catch (IOException e) {
e.printStackTrace();
}
}
}
我将前端传递过来的数据封装成map集合,直接对集合操作,将map集合传入到mapper.xml文件中
我们再看看mybatis中mapper.xml文件
<!--多参数查询认证数据-->
<select id="selectByParams" parameterType="Map" resultMap="BaseResultMap">
select top ${rows} NAME as name,TEL as tel,OPENID as openid,RZRQ as rzrq,sfzhm from TB_RZSJ
where 1=1 and YHRZ_ID not in (select top ${start} YHRZ_ID from TB_RZSJ where 1=1
<if test="name != null and name != ''">
and dbo.fnGetPY(NAME) like '%'+#{name}+'%'
</if>
<if test="openid != null and openid != ''">
and OPENID=#{openid}
</if>)
<if test="name != null and name != ''">
and dbo.fnGetPY(NAME) like '%'+#{name}+'%'
</if>
<if test="openid != null and openid != ''">
and OPENID=#{openid}
</if>
</select>
<!--多参数查询认证数据记录数-->
<select id="selectTotalByParams" parameterType="Map" resultType="int">
select isnull(count(*),0) from TB_RZSJ
where 1=1
<if test="name != null and name != ''">
and dbo.fnGetPY(NAME) like '%'+#{name}+'%'
</if>
<if test="openid != null and openid != ''">
and OPENID=#{openid}
</if>
</select>
结束语
很简单的,都在代码上面了,如果有什么不懂的请留言,如果有错误的地方,请大神指点。