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

  • 相关阅读:
    c语言中的rewind函数,Win CE 不支持,可用fseek函数替换
    接口隔离原则(转)
    接口设计的 11 种原则 (转)
    设计模式六大原则/接口设计六大原则 之 组合/聚集复用原则(转)
    C++ 求幂的运算符是什么?
    设计模式六大原则/接口设计六大原则 之 迪米特法则(转)
    解决mysql出现“the table is full”的问题
    tomcat远程调试设置
    这些习惯很伤肾 要警觉
    从ie临时文件夹一次复制多个文件
  • 原文地址:https://www.cnblogs.com/yuyu666/p/12650656.html
Copyright © 2011-2022 走看看