首页 > 其他 > 详细

第二天-后端代码编写

时间:2019-04-05 20:37:59      阅读:242      评论:0      收藏:0      [点我收藏+]

各个工程之间的依赖为:

-----所有工程依赖于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();
}

}

=========编写完成=======测试

第二天-后端代码编写

原文:https://www.cnblogs.com/java-saber/p/10659662.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!