java easyui 分页_Spring mvc+easyui做列表展示及分页
Spring mvc有一个注解@ResponseBody可以自己将返回数据解析成json,不用在response.getWriter(),设置response的编码之类的。
1、首先在spring-mvc.xml中配置如下
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
application/json;charset=UTF-8
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
class="com.liyi.test.common.UTF8StringHttpMessageConverter" />
别忘了,在下面还有一个UTF8StringHttpMessageConcerter类需要引入
package com.liyi.test.common;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.FileCopyUtils;
public class UTF8StringHttpMessageConverter extends StringHttpMessageConverter {
private static final MediaType utf8 = new MediaType("text", "plain", Charset.forName("UTF-8"));
private boolean writeAcceptCharset = true;
@Override
protected MediaType getDefaultContentType(String dumy) {
return utf8;
}
protected List getAcceptedCharsets() {
return Arrays.asList(utf8.getCharSet());
}
protected void writeInternal(String s, HttpOutputMessage outputMessage) throws IOException {
if (this.writeAcceptCharset) {
outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
}
Charset charset = utf8.getCharSet();
FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), charset));
}
public boolean isWriteAcceptCharset() {
return writeAcceptCharset;
}
public void setWriteAcceptCharset(boolean writeAcceptCharset) {
this.writeAcceptCharset = writeAcceptCharset;
}
}
2、配置好了,就可以写展示列表的后台代码了,以下,有两个方法,一个是做页面跳转用的,一个是用于ajax请求数据的。
@RequestMapping("/toUserList")
public String redirctUserList(){
return "user/new_user_list";
}
@ResponseBody
@RequestMapping("/userList")
public String userList(@RequestParam Map conds){
//默认每页10条
int pageSize = 10;
//默认第一页 计算开始条数
int currentPage = 1;
//获取页面传来每页显示条数
String row = (String) conds.get("rows");
//获取页面传来当前页码
String page = (String) conds.get("page");
if(null!=row&&!"".equals(row)){
pageSize=Integer.valueOf(row);
}
if(null!=page&&!"".equals(page)){
currentPage= Integer.valueOf(page);
}
Map map = new HashMap();
//计算一共有多少条
int count = userService.getTotalPage();
map.put("pageCount",pageSize);
//计算从第几条开始
map.put("currentPage",new PageUtil().getCurrent(currentPage,pageSize));
List list = userService.findAll(map);
Map map1 = new HashMap();
map1.put("total", count);
map1.put("rows",list);
String json = JSON.toJSONString(map1, true);
System.out.println(json);
return json;
}
只需要把你需要返回的数据,用fastjson将对象转成json串传入到页面,页面直接就可以取到。其中要注意,easyui展示列表的json如下:
[
{
"total": 13,
"rows": [
{
"createTime": 1438678875000,
"id": 1,
"mobile": "123456",
"name": "liyi",
"pwd": "123456"
},
{
"createTime": 1438679219000,
"id": 2,
"mobile": "123456",
"name": "scc",
"pwd": "123456"
},
{
"createTime": 1438679264000,
"id": 3,
"mobile": "123456",
"name": "diudiu",
"pwd": "123456"
},
{
"createTime": 1438679338000,
"id": 4,
"mobile": "123456",
"name": "xiaopaigu",
"pwd": "123456"
},
{
"createTime": 1438680558000,
"id": 5,
"mobile": "123456",
"name": "iphone",
"pwd": "123456"
},
{
"createTime": 1438682344000,
"id": 6,
"mobile": "123456",
"name": "iphone1",
"pwd": "123456"
},
{
"createTime": 1438754235000,
"id": 7,
"mobile": "123456",
"name": "abc",
"pwd": "123456"
},
{
"createTime": 1438852983000,
"id": 8,
"mobile": "11",
"name": "11",
"pwd": "11"
},
{
"createTime": 1438914359000,
"id": 9,
"mobile": "123456",
"name": "123456",
"pwd": "456789"
},
{
"createTime": 1439530418000,
"id": 10,
"mobile": "123",
"name": "123",
"pwd": "123"
}
]
}
]
3、jsp页面首先引入easyui的js 以及css
$(function(){
$('#dg').datagrid({
url:'${app}/userController/userList.do',
columns:[[
{field:'name',title:'姓名',width:100 },
{field:'mobile',title:'手机号',width:100},
{field:'_operate',width:80,align:'center',formatter:function(value,rec){
return "编辑";
},title:'操作'}
]],
toolbar: [{
iconCls: 'icon-add',
handler: function(){alert('编辑按钮')}
},'-',{
iconCls: 'icon-help',
handler: function(){alert('帮助按钮')}
}],
fitColumns:true,
striped:true,
pagination:true,
rownumbers:true,
pageNumber:1,
pageSize:10,
pageList:[10,20,30,40,50]
});
})
4、分页你可以用firefox观察一下,他会传入到后台两个参数,一个是当前页page,一个是rows每页的数量,根据我上篇文章的分页工具即可。在找到上面的List展示方法就可以了。
java easyui 分页_Spring mvc+easyui做列表展示及分页相关推荐
- 孔浩java爱酷网_spring mvc学习
1.首先是环境的搭建 导入jar包,就把spring的所有jar导进去就好,再加上commons-logging.jar包导入 注意:这里仅仅导入还不行,还需要把jar包拖动到项目的lib目录中 2. ...
- java url 拦截_Spring mvc设置某些url不被interceptor拦截器拦截的方法
我们的Java类继承HandlerInterceptorAdapter类之后,实现里面的preHandle与postHandle方法,默认情况下所有的url都会被spring mvc拦截器所拦截,因为 ...
- 自定义分页 html,MVC 自定义HtmlHelper帮助类型之分页
方法一: 在项目中增加App_Code文件夹,新增一个MyHtmlper.cshtml视图文件 写入代码: @helper Pagger(int pageIndex, int pageCount) { ...
- 六、教师管理-列表查询、分页、搜索
一. 需求分析 教师管理主要针对充值教师进行管理,首先开发教师管理模块中的列表功能,包含条件查询.下拉框.日期功能. 数据列表.分页. 二. 教师数据列表 1 nodejs 添加数据列表接口,去nod ...
- (easyui datagrid+mvc+json)之asp.net分页查询
最近在做分页查询的功能,在网上也翻看了不少,但是自己的吸收能力就差了好多,而且当时最大的想法就是,怎么就没有我想要的那种,既是easyui的,又要用mvc的架构,还要能够实现底层的分页传值,用.net ...
- SSH企业案例_CRM客户管理系统(六):Easyui列表展示
文章目录 1.EasyUI EasyUI的概述 EasyUI的使用(入门) EasyUI布局 EasyUI分类 EasyUI选项卡 EasyUI数据表格(*****) EasyUI的窗口 1.Easy ...
- java 分页_Spring Boot + MyBatis 如何借助PageHelper插件实现分页效果
概述 上文中已经介绍了Spring和MyBatis的整合,在上文的基础上我们加入了PageHelper这个插件,来实现MyBatis列表查询的分页效果 PageHelper是啥 PageHelper是 ...
- java mvc 分页查询条件_java分页条件查询-GridManager.js表格插件+Pageable分页对象+mybatis pagehelper分页插件...
总览: 一. GridManager.js表格插件 直接上插件API:链接地址 感觉该插件简单好用,插件作者也是有问必答,nice 二. 添加依赖 后端: pom文件添加: 1.7.0.RELEASE ...
- (转)淘淘商城系列——MyBatis分页插件(PageHelper)的使用以及商品列表展示
http://blog.csdn.net/yerenyuan_pku/article/details/72774381 上文我们实现了展示后台页面的功能,而本文我们实现的主要功能是展示商品列表,大家要 ...
最新文章
- vc c语言图片处理,大佬们,小菜鸟想问一问用vc编译器做简易画图软件
- Zuul 2 : The Netflix Journey to Asynchronous, Non-Blocking Systems--转
- Ruby与Google 2009编程之夏
- gradle之gradlew最全指令攻略
- 【C语言简单说】二十一:双重指针基础 (完结)
- blender的汉化方法!
- 前端学习(3252):vs code中插件的使用
- java.util.concurrent.*下的常见类你了解多少?
- react 路径跳转组件不跳转_Taro 小程序开发大型实战(二):多页面跳转和 Taro UI 组件库...
- 卫生纸玫瑰花折法5步_手工教程:做一个漂亮的玫瑰花捧花,用折纸表达我喜欢你...
- autocad型源代码_autocad 二次开发的一些源码实例
- Eclipse启动时f出现ail to create Java Virtual Machine问题的解决
- 红月OD反汇编实时显示坐标,背景色可透明也可以不透明
- cmd 返回目录操作
- excel模板报表转PDF下载
- 【Tools】Photoshop CS6安装详解教程
- vuca 时代_人工智能通过Vuca的镜头窥视未来
- 算法设计与分析——排序算法:比较排序算法的下界
- 群晖emby服务端下载(弃坑,官网已经能顺畅访问)
- 《C++ 笔记》 Part5 C++ 资源大全中文版
热门文章
- javacc案例之统计字符
- 【Flink】No key set. This method should not be called outside of a keyed context.
- 95-241-102-源码-Flink语义-Flink的exectly-once系列之两阶段提交实现分析
- 60-100-340-使用-DataSource-hive相关-Flink加载hive数据源
- Spring : @Value注解
- 06-netty之http之文件服务器
- RabbitMQ和Kafka的显著差异(1)
- 云计算教程学习入门视频课件:常用数据库排名
- ajaxutil java,Ajax的工具类AjaxUtils,使用struts返回Json类型
- 【component: resolve => require([‘../pages/home.vue‘], resolve)-装载】