配置数据源连接
1.导入mysql的连接驱动到common模块
<!-- 数据库驱动 https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<!--tomcat里一般都带-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
2.在renren-fast中common的xss的HTMLFilter拷过来
3.在app.yml中配置数据源的连接
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/gulimall-pms
driver-class-name: com.mysql.jdbc.Driver
# MapperScan
# sql映射文件位置
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
3.启动器上添加注解
@MapperScan(“com.xfwang.gulimall.coupon.dao”)
测试
@SpringBootTest
class GulimallCouponApplicationTests {
@Autowired
private CouponServiceImpl couponService;
@Test
void contextLoads() {
CouponEntity couponEntity =new CouponEntity();
couponEntity.setUseType(2);
couponService.save(couponEntity);
}
}