renren-generator 生成增删改查代码
git clone https://gitee.com/renrenio/renren-generator.git
修改resource中application.yml
sql连接 修改Ip表名
账户密码
generator.yml
配置包名等信息
idea默认gbk编码,出现乱码,setting搜native-to-ascii conversion
生成代码拷到对应的模块,
发现生成的代码依赖一些公共模块,
创建gulimall-common模块。
每个微服务依赖common,
common依赖mybatis
生成的模板在 resources/template中修改
common
整合mybaits plus
1.导入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
2.配置
1) 配置数据源:
2.1.1导入数据库驱动
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
xss中报错:导入servelet
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
2.1.2在application.yml配置数据源相关信息
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.13:3306/gulimall_pms
driver-class-name: com.mysql.jdbc.Driver
2.2 配置mybatis plus
com.quinlan.gulimall.product.GulimallProductApplication中
1)使用MapperScan()
MapperScan("com.quinlan.gulimall.product.dao")
2)application.yml中告诉mybatis plus 隐射
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
global-config:
db-config:
id-type: auto
单元测试:
@Autowired
BrandService brandService;
测试CURD
BrandEntity brandEntity = new BrandEntity();
brandEntity.setName("华为");
brandService.save(brandEntity);
System.out.println("保存成功");
brandEntity.setBrandId(1L);
brandEntity.setDescript("华为");
brandService.updateById(brandEntity);
List<BrandEntity> list = brandService.list(new QueryWrapper<BrandEntity>().eq("brand_id", 1));
list.forEach((item)->{
System.out.println(item);
});
生成所有微服务的代码