easyui+ssm 带分页表格

来源:互联网 发布:拦沙坝计算软件 编辑:程序博客网 时间:2024/06/06 05:00

序:

       框架:ssm+easyui

         项目构建:maven

         分页工具:pageHelper

 

第一步 引入easyui

<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.4.1/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="css/taotao.css" />
<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>

第二步 在jsp文件中,创建table


<table class="easyui-datagrid" id="itemList" title="商品列表"
       data-options="singleSelect:false,collapsible:true,pagination:true,url:'/item/list',method:'get',pageSize:30,toolbar:toolbar">
    <thead>
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            <th data-options="field:'id',width:60">商品ID</th>
            <th data-options="field:'title',width:200">商品标题</th>
            <th data-options="field:'cid',width:50">叶子类目</th>
            <th data-options="field:'sellPoint',width:240">卖点</th>
            <th data-options="field:'price',width:70,align:'right',formatter:TAOTAO.formatPrice">价格</th>
            <th data-options="field:'num',width:70,align:'right'">库存数量</th>
            <th data-options="field:'barcode',width:100">条形码</th>
            <th data-options="field:'status',width:60,align:'center',formatter:TAOTAO.formatItemStatus">状态</th>
            <th data-options="field:'created',width:130,align:'center',formatter:TAOTAO.formatDateTime">创建日期</th>
            <th data-options="field:'updated',width:130,align:'center',formatter:TAOTAO.formatDateTime">更新日期</th>
        </tr>
    </thead>
</table>


解释: data-options中

          singleSelect:false 为鼠标点击该行,该行不会被自动勾选(如果有复选框的话)

          collapsible:true 能够收缩

          pagination:true 翻页

          url:'/item/list'  后台访问地址

          method:'get'  访问方式

          pageSize:30 默认每页30条记录数

          toolbar:toolbar 工具


第二步 编写pojo类(属性名称与表格内的name名称一致)


item实体类


public class Item implements Serializable{
   

    private Long id;

    private String title;

    private String sellPoint;

    private Long price;

    private Integer num;

    private String barcode;

    private String image;

    private Long cid;

    private Byte status;

    private Date created;

    private Date updated;


          get/set方法(略)

}


PageVo类


public class PageVo implements Serializable{

    private Integer page;    //当前页
    private Integer rows; //当前页的记录数

}


包装vo类(这个类是最终返回给页面的)



public class EasyUIResult implements Serializable{
    private long total;        //总记录数
    private List<?> rows;//二维数组 装载数据

}


第三步 编写controller层

@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;
    
    @RequestMapping("/item/list")
    @ResponseBody
    public EasyUIResult findEasyUiResult(PageVo pv){
        EasyUIResult easyUiResults = itemService.findEasyUiResult(pv);
        return easyUiResults;
    }
}


第四步 编写service层


public interface ItemService {

    EasyUIResult findEasyUiResult(PageVo pv);

}



第五步 编写serviceImpl实现层 这也是分页处理


@Service
@Transactional
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ItemMapper itemMapper;
    
    @Override
    public EasyUIResult  findEasyUiResult(PageVo pv) {
        
        PageHelper.startPage(pv.getPage(),pv.getRows());
        
        List<Item> list = itemMapper.findEasyUiResult();
        
        //取分页信息
        PageInfo<Item> pageInfo = new PageInfo<>(list);
        
        //创建返回结果对象
        EasyUIResult result = new EasyUIResult();
        
        result.setRows(list);
        result.setTotal(pageInfo.getTotal());
        
        return result;
        
    }

}


第六步  mapper层


public interface ItemMapper {

    public List<Item> findEasyUiResult();
        
}

第七步  mapper映射xml文件


<mapper namespace="mapper文件的全限定名">
 
    <select id="findEasyUiResult" resultType="item实体类的全限定名">
        select 需要查询的属性名 from item
    </select>
</mapper>


(完结)


原创粉丝点击