<table class="easyui-datagrid" id="itemList" title="商品列表"
data-options="singleSelect:false,collapsible:true,pagination:true,url:'/rest/item',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:100">叶子类目</th>
<th data-options="field:'sellPoint',width:100">卖点</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>
这些是页面的请求;
后台代码:
//查询商品列表;
@RequestMapping(method=RequestMethod.GET)
public ResponseEntity queryItemList(
@RequestParam(value="page",defaultValue="1") Integer pageNum,
@RequestParam(value="rows", defaultValue="30") Integer pageSize){
//因为easyui数据表格需要两个数据去做分页显示
try {
EasyUIResult easy=itemService.queryOrderbyCreated(pageNum,pageSize);
if(easy == null){
ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}else {
ResponseEntity.ok(easy);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
业务层:
public EasyUIResult queryOrderbyCreated(Integer page, Integer rows) {
//将查询出来的数据封装到easyuiresult中去;
PageHelper.startPage(page,rows);
Example example=new Example(Item.class);
//调用商品的映射去向数据库发送查询
List<Item> selectByExample = this.itemMapper.selectByExample(example);
System.out.println(selectByExample.size());
PageInfo<Item> info = new PageInfo<Item>(selectByExample);
return new EasyUIResult(info.getTotal(), info.getList());
}
查询结果:
mapper查询的时候是有结果的:
Preparing: SELECT CID,ID,UPDATED,STATUS,PRICE,CREATED,IMAGE,BARCODE,SELL_POINT SELLPOINT,TITLE,NUM FROM tb_item limit ?,?
[DEBUG] ==> Parameters: 0(Integer), 30(Integer)
ItemMapper.selectByExample_PageHelper]-[DEBUG] <== Total: 4
2016-10-01 19:41:56,645 [http-bio-8081-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7c4159a6]
2016-10-01 19:41:56,645 [http-bio-8081-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7c4159a6]
2016-10-01 19:41:56,645 [http-bio-8081-exec-2] [org.mybatis.spring.SqlSessionUtils]-[DEBUG] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7c4159a6]
2016-10-01 19:41:56,645 [http-bio-8081-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Initiating transaction commit
2016-10-01 19:41:56,645 [http-bio-8081-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Committing JDBC transaction on Connection [ConnectionHandle{url=jdbc:mysql://127.0.0.1:3306/taotao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true, user=root, debugHandle=null, lastResetAgoInSec=0, lastUsedAgoInSec=0, creationTimeAgoInSec=0}]
2016-10-01 19:41:56,646 [http-bio-8081-exec-2] [org.springframework.jdbc.datasource.DataSourceUtils]-[DEBUG] Resetting read-only flag of JDBC Connection [ConnectionHandle{url=jdbc:mysql://127.0.0.1:3306/taotao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true, user=root, debugHandle=null, lastResetAgoInSec=0, lastUsedAgoInSec=0, creationTimeAgoInSec=0}]
2016-10-01 19:41:56,646 [http-bio-8081-exec-2] [org.springframework.jdbc.datasource.DataSourceTransactionManager]-[DEBUG] Releasing JDBC Connection [ConnectionHandle{url=jdbc:mysql://127.0.0.1:3306/taotao?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true, user=root, debugHandle=null, lastResetAgoInSec=0, lastUsedAgoInSec=0, creationTimeAgoInSec=0}] after transaction
2016-10-01 19:41:56,646 [http-bio-8081-exec-2] [org.springframework.jdbc.datasource.DataSourceUtils]-[DEBUG] Returning JDBC Connection to DataSource
2016-10-01 19:41:56,693 [http-bio-8081-exec-2] [org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain]-[DEBUG] Invoking ResponseBodyAdvice chain for body=null
2016-10-01 19:41:56,693 [http-bio-8081-exec-2] [org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain]-[DEBUG] After ResponseBodyAdvice chain body=null
2016-10-01 19:41:56,693 [http-bio-8081-exec-2] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Null ModelAndView returned to DispatcherServlet with name 'taotao-manage': assuming HandlerAdapter completed request handling
2016-10-01 19:41:56,693 [http-bio-8081-exec-2] [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Successfully completed request
NetworkError: 500 Internal Server Error