oracle 查询结果转成json_电商项目总结(3)商品的查询

1.使用EasyUI分页插件实现数据的查询

声明分页插件

<configuration>

	<settings>
		<!-- 指定mybatis的日志记录方式,需要添加log4j的依赖 -->
		<!-- 需要在src/main/resources下添加log4j.properties -->
		<setting name="logImpl" value="LOG4J" />
	</settings>

	<typeAliases>
		<!-- 将指定包下的所有的实体bean的别名取为类名首字母小写 -->
		<package name="com.sxt.ego.rpc.pojo" />
	</typeAliases>

	<!-- 配置分页插件 -->
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageHelper">
			<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库 -->
			<property name="dialect" value="mysql" />
		</plugin>
	</plugins>

</configuration>

2.封装EasyUI结果集

1.结果集的封装和EasyUI分页插件需要的数据是对应的

public class PageResult<T> implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4089569594626456542L;
	
	private List<T> rows;//封装的查询数据
	private Long total;//封装总条数

2.easyUi数据请求

<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:100">叶子类目</th>
            <th data-options="field:'sellPoint',width:100">卖点</th>
            <th data-options="field:'price',width:70,align:'right',formatter:EGO.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:EGO.formatItemStatus">状态</th>
            <th data-options="field:'created',width:130,align:'center',formatter:EGO.formatDateTime">创建日期</th>
            <th data-options="field:'updated',width:130,align:'center',formatter:EGO.formatDateTime">更新日期</th>
        </tr>
    </thead>
</table>

3.服务端开发

1.商品服务接口

接口:

注意page和rows数据为消费端传递过来的分页条件

page:开始

rows:显示的条数

public PageResult selectIteam(Integer page,Integer rows);

实现类:

使用逆向工程生成的方法

Example:逆向工程生成的文件为Example结尾的是动态sql生成的方法主要针对单表的操作

public PageResult selectIteam(Integer page, Integer rows) {
		//1.执行分页的炒作
		Page ps = PageHelper.startPage(page, rows);
		/**
		 * 这个的是逆向工程生成的文件传入个对应的对象即可
		 */
		TbItemExample example = new TbItemExample();
		List<TbItem> list = tbItemMapper.selectByExample(example);
		//2.数据的填充
		PageResult<TbItem> result = new PageResult<TbItem>();
		result.setRows(list);
		/**
		 * 总数可在PageHelper:datagrid中取出来即可
		 */
		result.setTotal(ps.getTotal());
		//3.返回数据
		return result;
	}

4.发布服务接口到dubbo的注册中心

<!-- 给当前的应用起个名字 -->
	<dubbo:application name="ego-service" />
	<!-- 配置注册中心 1.address:注册中心IP地址,注意zookeeper是一个集群,如果是集群则需要将所有的zookeeper的IP和端口都注册 
		每个使用逗号分割 2.protocol:注册中心的类型 -->
	<dubbo:registry
		address="192.168.177.132:2181,192.168.177.132:2183,192.168.177.132:2183"
		protocol="zookeeper"></dubbo:registry>
	<!-- 配置协议和 端口 -->
	<dubbo:protocol name="dubbo" port="20880"></dubbo:protocol>
	<!-- 发布到注册中心的服务接口接口的实现类创建已经交给类Spring所以这里可以直接引用 -->
	<dubbo:service
		interface="com.sxt.ego.rpc.service.ItemService" ref="itemServiceImpl"></dubbo:service>

5.消费端开发

消费端接口

参数服务端的参数一致接收前端页面传递的信息

	/**
	 * 查询全部的商品信息
	 * @param page 前台页面传入的分页数据
	 * @param rows
	 * @return
	 */
	public  PageResult<TbItem> selectTbitemList(Integer page,Integer rows);

实现类

直接调用远程代理对象即可

	/**
	 * 商品的查询
	 */
	@Override
	public PageResult<TbItem> selectTbitemList(Integer page, Integer rows) {
		return this.itemService.selectIteam(page, rows);
	}

控制器开发

注意返回的类型为Json格式需要Jackson的支持

在查询的时候给给分页查询进行条件的默认初始化

	/**
	 * 全部商品的请求
	 * @return
	 */
	@RequestMapping(value = "/list",produces=MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8",method=RequestMethod.GET)
	@ResponseBody
	public PageResult<TbItem> selectTbitemList(@RequestParam(defaultValue="1") Integer page,@RequestParam(defaultValue="30") Integer rows){
		return this.managerItemService.selectTbitemList(page, rows);
	}
	

效果图

153acb8fb27ae55af599e93143c39ccb.png

下面的这这些数据根据返回的结果会算

82ed54d65bf0072983755b85a9f6af1a.png

EasyUIdatagrid每次操作都会进行求的发送

cf91e05051abe7d162180e2c63491217.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值