微服务(七)—— 收货地址模块(backend-shipping)

上一篇: 微服务(六)—— 注册中心模块(backend-server).

一、创建项目

首先创建一个SpringBoot项目,具体创建过程和 微服务(三)—— 用户模块(backend-user).一样。

二、项目结构

1.目录结构

在这里插入图片描述
和用户模块、产品模块一样,传统的Controller层、Service层、Dao层,数据库表对应的实体类是通过 MyBatis插件 逆向生成,详见微服务(三)—— MyBatis逆向工程模块(backend-generator).,所以Dao层是Mapper接口,和 resources/mappers/ShippingMapper.xml 生成一一映射的关系。

2.具体类介绍

(1) 首先看给前端提供接口的类ShippingController

package com.aiun.shipping.controller;

/**
 * 收货地址
 * @author lenovo
 */
@Api(tags = "收获地址相关接口")
@RestController
@RequestMapping("/shipping/")
public class ShippingController {
    @Autowired
    private IShippingService iShippingService;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    /**
     * 增加收货地址
     * @param request 请求
     * @param shipping 地址信息
     * @return 返回结果
     */
    @PostMapping("add")
    @ApiOperation(value = "增加收货地址")
    public ServerResponse add(HttpServletRequest request, Shipping shipping) {
        ServerResponse hasLogin = loginHasExpired(request);
        if (hasLogin.isSuccess()) {
            User user = (User) hasLogin.getData();
            return iShippingService.add(user.getId(), shipping);
        }
        return hasLogin;
    }

    /**
     * 删除收货地址
     * @param request 请求
     * @param shippingId 地址 id
     * @return 返回结果
     */
    @DeleteMapping("del")
    @ApiOperation(value = "删除收货地址")
    public ServerResponse del(HttpServletRequest request, Integer shippingId) {
        ServerResponse hasLogin = loginHasExpired(request);
        if (hasLogin.isSuccess()) {
            User user = (User) hasLogin.getData();
            return iShippingService.del(user.getId(), shippingId);
        }
        return hasLogin;
    }

    /**
     * 更新收货地址
     * @param request 请求
     * @param shipping 地址信息
     * @return 返回结果
     */
    @PostMapping("update")
    @ApiOperation(value = "更新收货地址")
    public ServerResponse update(HttpServletRequest request, Shipping shipping) {
        ServerResponse hasLogin = loginHasExpired(request);
        if (hasLogin.isSuccess()) {
            User user = (User) hasLogin.getData();
            return iShippingService.update(user.getId(), shipping);
        }
        return hasLogin;
    }

    /**
     * 查询收货地址
     * @param request 请求
     * @param shippingId 地址 id
     * @return 地址信息
     */
    @PostMapping("select")
    @ApiOperation(value = "查询收货地址")
    public ServerResponse<Shipping> select(HttpServletRequest request, Integer shippingId) {
        ServerResponse hasLogin = loginHasExpired(request);
        if (hasLogin.isSuccess()) {
            User user = (User) hasLogin.getData();
            return iShippingService.select(user.getId(), shippingId);
        }
        return hasLogin;
    }

    /**
     * 查询某用户的所有收货地址,并分页
     * @param pageNum 当前页
     * @param pageSize 页大小
     * @param request 请求
     * @return
     */
    @PostMapping("list")
    @ApiOperation(value = "查询某用户的所有收货地址,并分页")
    public ServerResponse<PageInfo> list(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                         HttpServletRequest request) {
        ServerResponse hasLogin = loginHasExpired(request);
        if (hasLogin.isSuccess()) {
            User user = (User) hasLogin.getData();
            return iShippingService.list(user.getId(), pageNum, pageSize);
        }
        return hasLogin;
    }

    /**
     * 对外提供的服务
     * 根据ID查询Shipping数据
     * @param id 产品 id
     * @return 产品信息类
     */
    @GetMapping("{id}")
    public Shipping findById(@PathVariable(name="id") Integer id) {
        return iShippingService.findById(id);
    }

    /**
     * 判断用户登录是否过期
     * @param request 请求
     * @return 结果
     */
    private ServerResponse<User> loginHasExpired(HttpServletRequest request) {
        String key = request.getHeader(UserConst.AUTHORITY);
        ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
        String value = valueOperations.get(key);
        if (StringUtils.isEmpty(value)) {
            return ServerResponse.createByErrorMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
        }
        User user = JsonUtils.jsonStr2Object(value, User.class);
        if (!key.equals(user.getUsername())) {
            return ServerResponse.createByErrorMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
        }
        valueOperations.set(key, value, 1, TimeUnit.HOURS);
        return ServerResponse.createBySuccess(user);
    }
}

这个类里向前端提供后端数据的增、删、改、查接口,初次之外还用Redis做了一个用户登录状态的验证
(2)看Controller的调用层Service的实现类ShippingServiceImpl

package com.aiun.shipping.service.impl;
/**
 * @author lenovo
 */
@Service("iShippingService")
public class ShippingServiceImpl implements IShippingService {
    @Autowired
    private ShippingMapper shippingMapper;

    @Override
    public ServerResponse add(Integer userId, Shipping shipping) {
        shipping.setUserId(userId);
        int rowCount = shippingMapper.insert(shipping);
        if (rowCount > 0) {
            Map resultMap = Maps.newHashMap();
            resultMap.put("shippingId", shipping.getId());
            return ServerResponse.createBySuccess("新建地址成功!", resultMap);
        }
        return ServerResponse.createByErrorMessage("新建地址失败!");
    }

    @Override
    public ServerResponse<String> del(Integer userId, Integer shippingId) {
        int result = shippingMapper.deleteByShippingIdUserId(userId, shippingId);
        if (result > 0) {
            return ServerResponse.createBySuccess("删除地址成功!");
        }
        return ServerResponse.createByErrorMessage("删除地址失败!");
    }

    @Override
    public ServerResponse update(Integer userId, Shipping shipping) {
        shipping.setUserId(userId);
        int rowCount = shippingMapper.updateByShipping(shipping);
        if (rowCount > 0) {
            return ServerResponse.createBySuccess("更新地址成功!");
        }
        return ServerResponse.createByErrorMessage("更新地址失败!");
    }

    @Override
    public ServerResponse<Shipping> select(Integer userId, Integer shippingId) {
        Shipping shipping = shippingMapper.selectByShippingIdUserId(userId, shippingId);
        if (shipping == null) {
            return ServerResponse.createByErrorMessage("收货地址未查询到");
        }
        return ServerResponse.createBySuccess("查询地址成功", shipping);
    }

    @Override
    public ServerResponse<PageInfo> list(Integer userId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Shipping> shippingList = shippingMapper.selectByUserId(userId);
        PageInfo pageInfo = new PageInfo(shippingList);

        return ServerResponse.createBySuccess(pageInfo);
    }

    @Override
    public Shipping findById(Integer id) {
        return shippingMapper.selectByPrimaryKey(id);
    }
}

Service的实现类是主要业务逻辑的实现。收货地址的业务逻辑比较简单就不做过多的介绍了。
(3)DAO层
Dao 层是通过 MyBatis Generator插件根据数据库表逆向生成的Mapper接口和对应的Mapper.xml文件,实现数据库的访问。关于MyBatis Generator的使用看微服务(三)—— MyBatis逆向工程模块(backend-generator).

下面是Mapper接口

package com.aiun.shipping.mapper;
/**
 * 地址映射接口
 * @author lenovo
 */
@Mapper
@Repository
public interface ShippingMapper {
    /**
     * 通过主键删除地址
     * @param id 主键
     * @return 影响行数
     */
    int deleteByPrimaryKey(Integer id);

    /**
     *  插入地址
     * @param record 地址信息
     * @return 影响行数
     */
    int insert(@Param("record") Shipping record);

    /**
     * 有选择的插入地址
     * @param record 地址信息
     * @return 影响行数
     */
    int insertSelective(@Param("record") Shipping record);

    /**
     * 通过主键查询地址
     * @param id 主键
     * @return 返回地址信息
     */
    Shipping selectByPrimaryKey(Integer id);

    /**
     * 通过主键有选择的更新地址信息
     * @param record 地址信息
     * @return 影响行数
     */
    int updateByPrimaryKeySelective(@Param("record") Shipping record);

    /**
     * 通过主键更新地址信息
     * @param record 地址信息
     * @return 影响行数
     */
    int updateByPrimaryKey(@Param("record") Shipping record);

    /**
     * 通过地址 id 和用户 id 删除地址
     * @param userId 用户 id
     * @param shippingId 地址 id
     * @return 影响行数
     */
    int deleteByShippingIdUserId(@Param("userId") Integer userId, @Param("shippingId") Integer shippingId);

    /**
     * 更新地址信息
     * @param record 地址信息
     * @return 影响行数
     */
    int updateByShipping(@Param("record") Shipping record);

    /**
     *  通过地址 id 和用户 id 查询地址
     * @param userId 用户 id
     * @param shippingId 地址 id
     * @return 返回地址信息
     */
    Shipping selectByShippingIdUserId(@Param("userId") Integer userId, @Param("shippingId") Integer shippingId);

    /**
     * 通过用户 id 查询地址列表
     * @param userId 用户 id
     * @return 地址列表
     */
    List<Shipping> selectByUserId(@Param("userId") Integer userId);
}

该接口属于DAO层,所以需要加Spring的@Repository注解,还需要加@Mapper注解。
下面看一下对应的Mapper.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.aiun.shipping.mapper.ShippingMapper" >
  <resultMap id="BaseResultMap" type="com.aiun.shipping.pojo.Shipping" >
    <constructor >
      <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" />
      <arg column="user_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
      <arg column="receiver_name" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="receiver_phone" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="receiver_mobile" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="receiver_province" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="receiver_city" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="receiver_district" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="receiver_address" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="receiver_zip" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="create_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />
      <arg column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />
    </constructor>
  </resultMap>
  <sql id="Base_Column_List" >
    id, user_id, receiver_name, receiver_phone, receiver_mobile, receiver_province, receiver_city, 
    receiver_district, receiver_address, receiver_zip, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from trade_shipping
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from trade_shipping
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.aiun.shipping.pojo.Shipping" useGeneratedKeys="true" keyProperty="id">
    insert into trade_shipping (id, user_id, receiver_name,
      receiver_phone, receiver_mobile, receiver_province, 
      receiver_city, receiver_district, receiver_address, 
      receiver_zip, create_time, update_time
      )
    values (#{record.id,jdbcType=INTEGER}, #{record.userId,jdbcType=INTEGER}, #{record.receiverName,jdbcType=VARCHAR},
      #{record.receiverPhone,jdbcType=VARCHAR}, #{record.receiverMobile,jdbcType=VARCHAR}, #{record.receiverProvince,jdbcType=VARCHAR},
      #{record.receiverCity,jdbcType=VARCHAR}, #{record.receiverDistrict,jdbcType=VARCHAR}, #{record.receiverAddress,jdbcType=VARCHAR},
      #{record.receiverZip,jdbcType=VARCHAR}, now(), now()
      )
  </insert>
  <insert id="insertSelective" parameterType="com.aiun.shipping.pojo.Shipping" >
    insert into trade_shipping
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="record.id != null" >
        id,
      </if>
      <if test="record.userId != null" >
        user_id,
      </if>
      <if test="record.receiverName != null" >
        receiver_name,
      </if>
      <if test="record.receiverPhone != null" >
        receiver_phone,
      </if>
      <if test="record.receiverMobile != null" >
        receiver_mobile,
      </if>
      <if test="record.receiverProvince != null" >
        receiver_province,
      </if>
      <if test="record.receiverCity != null" >
        receiver_city,
      </if>
      <if test="record.receiverDistrict != null" >
        receiver_district,
      </if>
      <if test="record.receiverAddress != null" >
        receiver_address,
      </if>
      <if test="record.receiverZip != null" >
        receiver_zip,
      </if>
      <if test="record.createTime != null" >
        create_time,
      </if>
      <if test="record.updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="record.id != null" >
        #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.userId != null" >
        #{record.userId,jdbcType=INTEGER},
      </if>
      <if test="record.receiverName != null" >
        #{record.receiverName,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverPhone != null" >
        #{record.receiverPhone,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverMobile != null" >
        #{record.receiverMobile,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverProvince != null" >
        #{record.receiverProvince,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverCity != null" >
        #{record.receiverCity,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverDistrict != null" >
        #{record.receiverDistrict,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverAddress != null" >
        #{record.receiverAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverZip != null" >
        #{record.receiverZip,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null" >
        #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null" >
        now(),
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.aiun.shipping.pojo.Shipping" >
    update trade_shipping
    <set >
      <if test="record.userId != null" >
        user_id = #{record.userId,jdbcType=INTEGER},
      </if>
      <if test="record.receiverName != null" >
        receiver_name = #{record.receiverName,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverPhone != null" >
        receiver_phone = #{record.receiverPhone,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverMobile != null" >
        receiver_mobile = #{record.receiverMobile,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverProvince != null" >
        receiver_province = #{record.receiverProvince,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverCity != null" >
        receiver_city = #{record.receiverCity,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverDistrict != null" >
        receiver_district = #{record.receiverDistrict,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverAddress != null" >
        receiver_address = #{record.receiverAddress,jdbcType=VARCHAR},
      </if>
      <if test="record.receiverZip != null" >
        receiver_zip = #{record.receiverZip,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null" >
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateTime != null" >
        update_time = now(),
      </if>
    </set>
    where id = #{record.id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.aiun.shipping.pojo.Shipping" >
    update trade_shipping
    set user_id = #{record.userId,jdbcType=INTEGER},
      receiver_name = #{record.receiverName,jdbcType=VARCHAR},
      receiver_phone = #{record.receiverPhone,jdbcType=VARCHAR},
      receiver_mobile = #{record.receiverMobile,jdbcType=VARCHAR},
      receiver_province = #{record.receiverProvince,jdbcType=VARCHAR},
      receiver_city = #{record.receiverCity,jdbcType=VARCHAR},
      receiver_district = #{record.receiverDistrict,jdbcType=VARCHAR},
      receiver_address = #{record.receiverAddress,jdbcType=VARCHAR},
      receiver_zip = #{record.receiverZip,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = now()
    where id = #{record.id,jdbcType=INTEGER}
  </update>
  <delete id="deleteByShippingIdUserId" parameterType="map">
    delete from trade_shipping
    where id = #{shippingId}
    and user_id = #{userId}
  </delete>
  <update id="updateByShipping" parameterType="com.aiun.shipping.pojo.Shipping">
    update trade_shipping
    set receiver_name = #{record.receiverName,jdbcType=VARCHAR},
      receiver_phone = #{record.receiverPhone,jdbcType=VARCHAR},
      receiver_mobile = #{record.receiverMobile,jdbcType=VARCHAR},
      receiver_province = #{record.receiverProvince,jdbcType=VARCHAR},
      receiver_city = #{record.receiverCity,jdbcType=VARCHAR},
      receiver_district = #{record.receiverDistrict,jdbcType=VARCHAR},
      receiver_address = #{record.receiverAddress,jdbcType=VARCHAR},
      receiver_zip = #{record.receiverZip,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      update_time = now()
    where id = #{record.id,jdbcType=INTEGER}
    and user_id = #{record.userId,jdbcType=INTEGER}
  </update>
  <select id="selectByShippingIdUserId" resultMap="BaseResultMap" parameterType="map">
    select
    <include refid="Base_Column_List"/>
     from trade_shipping
     where id = #{shippingId}
     and user_id = #{userId}
  </select>
  <select id="selectByUserId" resultMap="BaseResultMap" parameterType="int">
    select
    <include refid="Base_Column_List"/>
     from trade_shipping
     where user_id = #{userId}
  </select>
</mapper>

这里介绍一个好用的IDEA插件,MyBatis plugin,可以实现Mapper接口和Mapper.xml的跳转,已经语法的检测等。
数据库建表

CREATE TABLE `trade_shipping` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL COMMENT '用户id',
  `receiver_name` varchar(20) DEFAULT NULL COMMENT '收货姓名',
  `receiver_phone` varchar(20) DEFAULT NULL COMMENT '收货固定电话',
  `receiver_mobile` varchar(20) DEFAULT NULL COMMENT '收货移动电话',
  `receiver_province` varchar(20) DEFAULT NULL COMMENT '省份',
  `receiver_city` varchar(20) DEFAULT NULL COMMENT '城市',
  `receiver_district` varchar(20) DEFAULT NULL COMMENT '区/县',
  `receiver_address` varchar(200) DEFAULT NULL COMMENT '详细地址',
  `receiver_zip` varchar(6) DEFAULT NULL COMMENT '邮编',
  `create_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

3.配置文件

接下来看一下配置文件application.yml

# Spring
spring:
 # 服务应用名称
 application:
  name: backend-shipping
  # 数据源
 datasource:
  driver-class-name: com.mysql.cj.jdbc.Driver
  url: jdbc:mysql://localhost:3306/trade?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
  username: root
  password: root
  # 指定druid 连接池以及druid 连接池配置
  type: com.alibaba.druid.pool.DruidDataSource
  druid:
   initial-size: 1          # 初始连接数
   max-active: 20           # 最大连接数
   max-idle: 20             # 最大空闲
   min-idle: 1              # 最小空闲
   max-wait: 60000          # 最长等待时间

server:
 port: 8085                  # 项目访问端口
 servlet:
  context-path: /backend-shipping    # 项目访问路径

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
  instance:
    hostname: localhost

# MyBatis
mybatis:
 # 配置 MyBatis 数据返回类型别名(默认别名是类名)
 type-aliases-package: com.aiun.shipping.pojo
 # 配置 MyBatis Mapper 映射文件
 mapper-locations: classpath:/mappers/*.xml

# MyBatis SQL 打印(方法接口所在的包,不是 Mapper.xml 所在的包)
#logging:
 #level:
 # com.aiun.order.mappers: debug
 ## pagehelper
 pagehelper:
   helperDialect: sqlite #postgresql
   reasonable: true
   supportMethodsArguments: true
   params: countSql
   count: countSql
   returnPageInfo: check

 # 记录日志
 logging:
   config: classpath:logback-spring.xml

该模块需要注册到Eureka注册中心,还需要配置pageHelper分页,以及记录日志等。

4.POM文件

下面看一下Maven项目的POM文件
首先要添加父依赖

<parent>
    <groupId>com.aiun</groupId>
    <artifactId>BackendManageSystem</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

还需要添加公共类的依赖

<!--backend common 依赖-->
<dependency>
    <groupId>com.aiun</groupId>
    <artifactId>backend-common</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

因为会用到用户实体类,所以加了一个user的依赖

<!-- user api 依赖 -->
<dependency>
    <groupId>com.aiun</groupId>
    <artifactId>backend-service-user-api</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

下面是完整的pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.aiun</groupId>
        <artifactId>BackendManageSystem</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>com.aiun</groupId>
    <artifactId>backend-shipping</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>backend-shipping</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!--backend common 依赖-->
        <dependency>
            <groupId>com.aiun</groupId>
            <artifactId>backend-common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- user api 依赖 -->
        <dependency>
            <groupId>com.aiun</groupId>
            <artifactId>backend-service-user-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!--config client 依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-client</artifactId>
        </dependency>
        <!--spring boot web 依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- mybatis 依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
        <!-- pagehelper 分页依赖 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
        </dependency>
        <!--mysql 依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!--druid 连接池依赖-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>
        <!-- eureka client 依赖 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!-- lombok 依赖 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!-- swagger 依赖-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

5.启动项目

下面是该模块的启动类:

package com.aiun.shipping;
/**
 * 收货地址启动类
 * @author lenovo
 */
@EnableSwagger2
@SpringBootApplication
@EnableEurekaClient
public class ShippingApplication {

    public static void main(String[] args) {
        SpringApplication.run(ShippingApplication.class, args);
    }

}

需要有支持Swagger和支持Eureka client的注解
然后需要先启动Eureka注册中心,然后再启动用户模块,需要用户登录,最后再启动该项目。
使用Talend API Tester插件测试
在这里插入图片描述
可以看到访问成功!!!
到这里收货地址模块就完成了。
注:项目已上传GitHub:https://github.com/AiunCode/BackendManageSystem.

下一篇:微服务(八)—— 订单模块(backend-order).

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值