一:整合mybatis-plus
1.导入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
2.配置
1)配置数据源
导入数据库驱动
在common的pom文件中
<!--导入mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
1.删除comon中xss包下的XssFilter和XssHttpServletRequestWrapper文件
2.从renren-fast复制RRException到conmon项目utils路径下
2)配置驱动
在gulimail-product的resources的目录下创建application.yml文件
3)配置mybatis-plus
在gulimail-product启动类添加注解
@MapperScan("com.sysg.gulimail.product.dao")
告诉mybatis-plus,sql文件的映射位置
#数据源
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://127.0.0.1:3306/gulimail_pms
driver-class-name: com.mysql.jdbc.Driver
#mybatis-plus映射位置
#classpath*,表示扫描本微服务和其他微服务
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
#设置id主键自增
global-config:
db-config:
id-type: auto
4)测试是否配置成功
在gulimail-product的测试类中进行测试
package com.sysg.gulimail.product;
import com.sysg.gulimail.product.entity.BrandEntity;
import com.sysg.gulimail.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 GulimailProductApplicationTests {
@Autowired
private BrandService brandService;
@Test
void contextLoads() {
BrandEntity brandEntity = new BrandEntity();
brandEntity.setName("华为");
brandService.save(brandEntity);
System.out.println("保存成功。。。");
}
}
测试保存
测试更新
package com.sysg.gulimail.product;
import com.sysg.gulimail.product.entity.BrandEntity;
import com.sysg.gulimail.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 GulimailProductApplicationTests {
@Autowired
private BrandService brandService;
@Test
void contextLoads() {
BrandEntity brandEntity = new BrandEntity();
/*brandEntity.setName("华为");
brandService.save(brandEntity);
System.out.println("保存成功。。。");*/
brandEntity.setBrandId(1L);
brandEntity.setDescript("小米");
brandService.updateById(brandEntity);
}
}
测试成功,一切OK