product模块
1、引入common模块
生成的代码都要引入common模块,因为自定义的一些类都指定在了mall-common模块
2、配置文件
spring: datasource: username: root password: root url: jdbc:mysql://192.168.1.12:3306/mall_pms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: global-config: db-config: id-type: auto mapper-locations: classpath:/mapper/**/*.xml configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
application.properties
用来配置端口和服务名称
# 应用名称 spring.application.name=mall-product # 应用服务 WEB 访问端口 server.port=9999
3、启动类增加mappersan注解
这里强调下:
代码自动生成器生成的代码中,Mapper文件都加了@Mapper注解,所以我们不用加@MapperScan
如果你自己写的话,MapperScan是个更好的选择
@MapperScan("com.caq.mall.product.dao")
4、测试
package com.caq.mall; import com.caq.mall.product.entity.BrandEntity; import com.caq.mall.product.service.BrandService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class MallProductApplicationTests { @Autowired private BrandService brandService; @Test void contextLoads() { BrandEntity brandEntity = new BrandEntity(); brandEntity.setName("苹果"); brandService.save(brandEntity); } } JDBC Connection [HikariProxyConnection@1371953731 wrapping com.mysql.cj.jdbc.ConnectionImpl@740dcae3] will not be managed by Spring ==> Preparing: INSERT INTO pms_brand ( name ) VALUES ( ? ) ==> Parameters: 苹果(String) <== Updates: 1
5、上传代码到github
上传失败可搜索我的文章,今天刚更新的
Java初学者必看,这篇文章
coupon模块
1、修改代码生成器配置文件
mainPath=com.caq #\u5305\u540D package=com.caq.mall moduleName=coupon #\u4F5C\u8005 author=xiaocai #Email email=mildcaq@gmail.com #\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00) tablePrefix=sms_
yml文件
server: port: 80 # mysql spring: datasource: type: com.alibaba.druid.pool.DruidDataSource #MySQL配置 driverClassName: com.mysql.cj.jdbc.Driver url: jdbc:mysql://192.168.1.12:3306/mall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: root
2、重启服务,重新生成代码文件
3、拷贝代码,建立coupon配置文件
因为我们是通过SpringInit初始化的模块,所以每个模块都有自带的配置文件applicaiton.properties
改端口的话我们可以修改applicaiton.properties文件
spring: datasource: username: root password: root url: jdbc:mysql://192.168.1.12:3306/mall_sms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai driver-class-name: com.mysql.cj.jdbc.Driver mybatis-plus: mapper-locations: classpath:/mapper/**/*.xml global-config: db-config: id-type: auto
4、运行,测试
http://localhost:7000/coupon/coupon/list
{"msg":"success","code":0,"page":{"totalCount":0,"pageSize":10,"totalPage":0,"currPage":1,"list":[]}}
member模块
重复上述操作,改代码生成器配置文件,运行生成代码,拷贝代码到模块
拷贝后的代码,建立配置文件,改端口,运行
测试,没问题即可
order模块
重复上述操作,改代码生成器配置文件(模块名,数据库名),运行生成代码,拷贝代码到模块
重复上述操作,拷贝后的代码,建立配置文件,改端口,运行
ware模块
重复上述操作,改代码生成器配置文件(模块名,数据库名),运行生成代码,拷贝代码到模块
重复上述操作,拷贝后的代码,建立配置文件,改端口,运行
Bug记录
npm install失败
开启v2ray等你懂得的软件,没有的话通过
清理缓存:npm rebuild node-sass
npm uninstall node-sass
重新下载:npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
再次npm install 直到成功
还是失败?
删除node_moudle模块删除重新npm install
快速完成
导入项目后的pom问题
<relativePath></relativePath>这个作用是不依赖本地parent pom,直接从reposity拉取
不继承父类,相当于用自己的
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.6</version> <relativePath></relativePath> </parent> 在父pom文件,引入新加进来的模块 <modules> <module>mall-product</module> <module>mall-coupon</module> <module>mall-member</module> <module>mall-order</module> <module>mall-ware</module> <module>mall-common</module> <module>renren-fast</module> </modules>
插件下载失败
其中docker的插件版本选择1.2.2可下载
有以下几种方式调试:
- 设置多maven地址
- 设置maven自动导入,删除本地这个包让他重新下载
- 每次更改都要刷新、重启IDEA
- 删除项目,重新克隆到本地