1.我们之前以前写好了对应的dubbo的代码,现在我们需要实现商品查询功能,那么我们只需要在对应的manage项目里面调用对应的dubbo就可以了。
2.我们在manage中新建一个service接口,取名叫TbItemService,因为是要显示在前台,所有方法类型仍然是EasyUIDataGrid,如下:
package com.ego.manage.service;
import com.ego.commons.pojo.EasyUIDataGrid;
public interface TbItemService {
/**
* 显示全部商品
* @param page
* @param rows
* @return
*/
EasyUIDataGrid show(int page,int rows);
}
3.接下来我们就需要创建这个接口的实现类了。我们直接调用之前写的dubbo的服务就可以了。如下:
package com.ego.manage.service.impl;
import org.springframework.stereotype.Service;
import com.alibaba.dubbo.config.annotation.Reference;
import com.ego.commons.pojo.EasyUIDataGrid;
import com.ego.dubbo.service.TbItemDubboService;
import com.ego.manage.service.TbItemService;
@Service
public class TbItemServiceImpl implements TbItemService{
@Reference
private TbItemDubboService tbItemDubboServiceImpl;
@Override
public EasyUIDataGrid show(int page, int rows) {
// TODO Auto-generated method stub
return tbItemDubboServiceImpl.show(page, rows);
}
}
4.接下来,我们只需要把对应的控制器写好就可以了。
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ego.commons.pojo.EasyUIDataGrid;
import com.ego.manage.service.TbItemService;
@Controller
public class TbItemController {
@Resource
private TbItemService tbItemServiceImpl;
@RequestMapping("item/list")
@ResponseBody
public EasyUIDataGrid show(int page,int rows) {
return tbItemServiceImpl.show(page, rows);
}
}
6.我们先要将dubbo中的Test类运行起来,然后在发布manage项目。最后的实现效果如下: