第二天-后端代码编写
各个工程之间的依赖为:
-----所有工程依赖于parent---------------------------
------dao依赖于pojo------------------------------------
------service依赖于interface、dao-----------------
------interface依赖于pojo----------------------------
-----manager-web依赖于interface----------------
=====然后编写接口interface后端代码====
在/pinyougou-sellergoods-interface/src/main/java中创建包com.pinyougou.sellergoods.service
在包里面创建接口BrandService.java:
package com.pinyougou.sellergoods.service;
import java.util.List;
import com.pinyougou.pojo.TbBrand;
public interface BrandService {
public List<TbBrand> findAll();
}
=====然后编写service后端代码====
在/pinyougou-sellergoods-service/src/main/java中创建包com.pinyougou.sellergoods.service.impl
创建类BrandServiceImpl.java 记得引入依赖接口
package com.pinyougou.sellergoods.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import com.pinyougou.mapper.TbBrandMapper;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;
@Service
public class BrandServiceImpl implements BrandService {
@Autowired
private TbBrandMapper brandMapper;
@Override
public List<TbBrand> findAll() {
return brandMapper.selectByExample(null);
}
}
=====然后编写manager-web后端代码====
依赖于pinyougou-sellergoods-interface
在/pinyougou-manager-web/src/main/java中创建包com.pinyougou.manager.controller
创建类BrandController.java内容为:
package com.pinyougou.manager.controller;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;
@RestController
@RequestMapping("/brand")
public class BrandController {
@Reference
private BrandService brandService;
@RequestMapping("/findAll")
public List<TbBrand> findAll(){
return brandService.findAll();
}
}
=========编写完成=======测试