zoukankan      html  css  js  c++  java
  • service的开发实现

    1.分析页面

    2.因为taotao-common被其他子工程共享依赖,所以在这里新建展示数据的POJO类EasyUIDataGridResult如下:

    3.POJO类序列化

    4.创建接口ItemService 

    ItemService.java 

    package com.taotao.service;
    
    import com.taotao.common.pojo.EasyUIDataGridResult;
    
    /**
     * 商品相关的处理的service
     * @title ItemService.java
     * <p>description</p>
     * @author
     * @version 1.0
     */
    public interface ItemService {
    	
    	/**
    	 *  根据当前的页码和每页 的行数进行分页查询
    	 * @param page
    	 * @param rows
    	 * @return
    	 */
    	public EasyUIDataGridResult getItemList(Integer page,Integer rows);
    }
    

      

    5.新建实现类ItemServiceImpl

    ItemServiceImpl.java

    package com.taotao.service.impl;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import com.taotao.common.pojo.EasyUIDataGridResult;
    import com.taotao.mapper.TbItemMapper;
    import com.taotao.pojo.TbItem;
    import com.taotao.pojo.TbItemExample;
    import com.taotao.service.ItemService;
    
    @Service
    public class ItemServiceImpl implements ItemService {
    
    	@Autowired
    	private TbItemMapper mapper;
    
    	@Override
    	public EasyUIDataGridResult getItemList(Integer page, Integer rows) {
    		// 1.设置分页的信息 使用pagehelper
    		if (page == null)
    			page = 1;
    		if (rows == null)
    			rows = 30;
    		PageHelper.startPage(page, rows);
    		// 2.注入mapper
    		// 3.创建example 对象 不需要设置查询条件
    		TbItemExample example = new TbItemExample();
    		// 4.根据mapper调用查询所有数据的方法
    		List<TbItem> list = mapper.selectByExample(example);
    		// 5.获取分页的信息
    		PageInfo<TbItem> info = new PageInfo<>(list);
    		// 6.封装到EasyUIDataGridResult
    		EasyUIDataGridResult result = new EasyUIDataGridResult();
    		result.setTotal((int) info.getTotal());
    		result.setRows(info.getList());
    		// 7.返回
    		return result;
    	}
    
    }
    

      

    6. 修改applicationContext-service.xml

  • 相关阅读:
    Swift 3 中的访问控制 open public internal fileprivate private
    swift3.0 创建一个app引导页面
    cocoapods安装及常用命令
    swift 多线程及GCD
    swift 键盘属性与事件
    [bzoj2588] Count on a tree
    [JSOI2007] 文本生成器
    18.09.22模拟赛T2 历史
    [USACO18OPEN] Talent Show
    [国家集训队] 整数的lqp拆分
  • 原文地址:https://www.cnblogs.com/yuyu666/p/12650656.html
Copyright © 2011-2022 走看看