赞
踩
源码地址:https://gitee.com/baohaipeng/gulimall
本文目标
在gulimall根目录下新建pom文件,打包方式为pom,并将各个微服务聚合起来,结构如下
如果你的idea右侧没有出现Maven窗口,右键点击gulimall工程,点击Add Framework Support,选择Maven,确认即可展示。
完整pom文件如下
<?xml version="1.0" encoding="UTF-8"?>4.0.0com.bhp.gulimall gulimall 0.0.1-SNAPSHOTgulimall聚合服务pomgulimall-coupongulimall-productgulimall-ordergulimall-membergulimall-ware
聚合服务完整.gitignore
target/pom.xml.tagpom.xml.releaseBackuppom.xml.versionsBackuppom.xml.nextrelease.propertiesdependency-reduced-pom.xmlbuildNumber.properties.mvn/timing.properties.mvn/wrapper/maven-wrapper.jar**/mvnw**/mvnw.cmd**/.mvn**/*.iml**/target/.idea
子模块的忽略配置直接删掉即可
子模块微服务的HELP.md文件根据自己的需要选择删除还是保存,我直接删了。
点击右上角提交按钮,可以从左侧看到现在所有的不需要的东西已经排除掉了,选中所有代码,填写提交备注,点击下方的提交并推送按钮
确认无误后点击push进行推送
如图,推送基本代码结构成功
在mysql分别新建下边的数据库,字符集和排序规则如下图设置
sql文件已经放到项目根目录下的sql文件夹内
将renren-fast-vue克隆到本地:https://gitee.com/renrenio/renren-fast-vue.git
聚合服务pom文件内右键、Maven、Reload Project重新导入依赖
启动RenrenAplication,成功后如下界面
npm install
npm run dev
账号:admin,密码admin,输入验证码,登录正常
将renren-fast和renren-fast-vue的代码同步提交到自己的码云仓库,完善项目目录
随便打开一个文件,发现一堆报错,很多错误是由于缺少部分依赖造成的,下边会进行统一处理
com.baomidou mybatis-plus-boot-starter 3.3.2
org.projectlombok lombok 1.18.16
org.apache.httpcomponents httpcore 4.4.13
commons-lang commons-lang 2.6
mysql mysql-connector-java 8.0.22
<?xml version="1.0" encoding="UTF-8"?> gulimall com.bhp.gulimall0.0.1-SNAPSHOT4.0.0 gulimall-common 谷粒商城公共模块org.apache.maven.plugins maven-compiler-plugin 77mysql mysql-connector-java 8.0.22com.baomidou mybatis-plus-boot-starter 3.3.2org.projectlombok lombok 1.18.16org.apache.httpcomponents httpcore 4.4.13commons-lang commons-lang 2.6io.renren renren-fast 3.0.0compile
此时,商品服务模块生成的代码依然会报错,由于需要修改的地方比较多,下面调整代码生成器模板,对代码进行重新生成并替换。
package ${package}.${moduleName}.controller;import java.util.Arrays;import java.util.Map;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import ${package}.${moduleName}.entity.${className}Entity;import ${package}.${moduleName}.service.${className}Service;import ${mainPath}.common.utils.PageUtils;import ${mainPath}.common.utils.R;/** * ${comments} * * @author ${author} * @email ${email} * @date ${datetime} */@RestController@RequestMapping("${moduleName}/${pathName}")public class ${className}Controller { @Autowired private ${className}Service ${classname}Service; /** * 列表 */ @RequestMapping("/list")## @RequiresPermissions("${moduleName}:${pathName}:list") public R list(@RequestParam Map params){ PageUtils page = ${classname}Service.queryPage(params); return R.ok().put("page", page); } /** * 信息 */ @RequestMapping("/info/{${pk.attrname}}")## @RequiresPermissions("${moduleName}:${pathName}:info") public R info(@PathVariable("${pk.attrname}") ${pk.attrType} ${pk.attrname}){${className}Entity ${classname} = ${classname}Service.getById(${pk.attrname}); return R.ok().put("${classname}", ${classname}); } /** * 保存 */ @RequestMapping("/save")## @RequiresPermissions("${moduleName}:${pathName}:save") public R save(@RequestBody ${className}Entity ${classname}){${classname}Service.save(${classname}); return R.ok(); } /** * 修改 */ @RequestMapping("/update")## @RequiresPermissions("${moduleName}:${pathName}:update") public R update(@RequestBody ${className}Entity ${classname}){${classname}Service.updateById(${classname}); return R.ok(); } /** * 删除 */ @RequestMapping("/delete")## @RequiresPermissions("${moduleName}:${pathName}:delete") public R delete(@RequestBody ${pk.attrType}[] ${pk.attrname}s){${classname}Service.removeByIds(Arrays.asList(${pk.attrname}s)); return R.ok(); }}
目前,商品微服务模块的业务代码都自动生成并且没有异常了,下面需要完善配置,让该模块正常联通数据库。
spring: datasource: driver-class-name: com.mysql.jdbc.Driver username: root password: root url: jdbc:mysql://127.0.0.1:3306/gulimall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
@MapperScan("com.bhp.gulimall.product.dao")
mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto
package com.bhp.gulimall.product;import com.bhp.gulimall.product.entity.BrandEntity;import com.bhp.gulimall.product.service.BrandService;import org.junit.jupiter.api.Test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;@SpringBootTestclass GulimallProductApplicationTests {@AutowiredBrandService brandService;@Testvoid contextLoads() {BrandEntity brandEntity = new BrandEntity();brandEntity.setName("汉阳造");brandEntity.setDescript("耗子尾汁");brandService.save(brandEntity);System.out.println(brandEntity.toString());}}
控制台打印成功,数据也入库成功,商品微服务模块搭建完成
至此,优惠券服务模块代码生成完毕
过程略,代码已上传至我的远程仓库:https://gitee.com/baohaipeng/gulimall
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。