1、pom

在common项目的pom.xml(我们把每个微服务里公共的类和依赖放到common里)中添加

  1. <!-- mybatisPLUS-->
  2. <dependency>
  3. <groupId>com.baomidou</groupId>
  4. <artifactId>mybatis-plus-boot-starter</artifactId>
  5. <version>3.3.2</version>
  6. </dependency>
  7. <!--简化实体类,用@Data代替getset方法-->
  8. <dependency>
  9. <groupId>org.projectlombok</groupId>
  10. <artifactId>lombok</artifactId>
  11. <version>1.18.8</version>
  12. </dependency>
  13. <!-- httpcomponent包https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
  14. <dependency>
  15. <groupId>org.apache.httpcomponents</groupId>
  16. <artifactId>httpcore</artifactId>
  17. <version>4.4.13</version>
  18. </dependency>
  19. <dependency>
  20. <groupId>commons-lang</groupId>
  21. <artifactId>commons-lang</artifactId>
  22. <version>2.6</version>
  23. </dependency>

需要用到的模块在pom.xml中加入下面内容

  1. <dependency>
  2. <groupId>com.ht.mall</groupId>
  3. <artifactId>mall-common</artifactId>
  4. <version>0.0.1-SNAPSHOT</version>
  5. </dependency>

2、复制

renren-fast——utils 包下的Query和PageUtils、R、Constant复制到common项目的utils包下

把@RequiresPermissions这些注解掉,因为是shiro的

复制renren-fast中的xss包粘贴到common的目录下。

复制了exception文件夹,对应的位置关系自己观察一下就行

注释掉product项目下类中的//import org.apache.shiro.authz.annotation.RequiresPermissions;他是shiro的东西

注释renren-generator\src\main\resources\template/Controller中所有的
# @RequiresPermissions。
# import org.apache.shiro.authz.annotation.RequiresPermissions;

总之什么报错就去renren-fast里面找。

3、测试

测试与整合商品服务里的mybatisplus

在common的pom.xml中导入

  1. <!-- 数据库驱动 https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
  2. <dependency>
  3. <groupId>mysql</groupId>
  4. <artifactId>mysql-connector-java</artifactId>
  5. <version>8.0.17</version>
  6. </dependency>
  7. <!--tomcat里一般都带-->
  8. <dependency>
  9. <groupId>javax.servlet</groupId>
  10. <artifactId>servlet-api</artifactId>
  11. <version>2.5</version>
  12. <scope>provided</scope> # Tomcat有带,所以provided
  13. </dependency>

删掉common里xss/xssfiler和XssHttpServletRequestWrapper
在product项目的resources目录下新建application.yml

  1. spring:
  2. datasource:
  3. driver-class-name: com.mysql.cj.jdbc.Driver
  4. url: jdbc:mysql://192.168.1.103:3306/mall_pms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
  5. username: root
  6. password: root
  7. # MapperScan
  8. # sql映射文件位置
  9. mybatis-plus:
  10. mapper-locations: classpath:/mapper/**/*.xml
  11. global-config:
  12. db-config:
  13. id-type: auto

在主启动类上加上注解@MapperScan()

  1. @MapperScan("com.ht.mall.product.dao")
  2. @SpringBootApplication
  3. public class MallProductApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(MallProductApplication.class, args);
  6. }
  7. }

然后去测试,先通过下面方法给数据库添加内容

  1. @SpringBootTest
  2. class MallProductApplicationTests {
  3. @Autowired
  4. BrandService brandService;
  5. @Test
  6. void contextLoads() {
  7. BrandEntity brandEntity = new BrandEntity();
  8. brandEntity.setDescript("hello");
  9. brandEntity.setName("华为");
  10. brandService.save(brandEntity);
  11. System.out.println("保存成功");
  12. }
  13. }

image.png