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.导入依赖

    1. <dependency>
    2. <groupId>com.baomidou</groupId>
    3. <artifactId>mybatis-plus-boot-starter</artifactId>
    4. <version>3.2.0</version>
    5. </dependency>

    2.配置
    1) 配置数据源:
    2.1.1导入数据库驱动

    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>

    xss中报错:导入servelet

    1. <dependency>
    2. <groupId>javax.servlet</groupId>
    3. <artifactId>servlet-api</artifactId>
    4. <version>2.5</version>
    5. <scope>provided</scope>
    6. </dependency>

    2.1.2在application.yml配置数据源相关信息

    1. spring:
    2. datasource:
    3. username: root
    4. password: root
    5. url: jdbc:mysql://192.168.56.13:3306/gulimall_pms
    6. driver-class-name: com.mysql.jdbc.Driver

    2.2 配置mybatis plus
    com.quinlan.gulimall.product.GulimallProductApplication中
    1)使用MapperScan()

    1. MapperScan("com.quinlan.gulimall.product.dao")

    2)application.yml中告诉mybatis plus 隐射

    1. mybatis-plus:
    2. mapper-locations: classpath*:/mapper/**/*.xml
    3. global-config:
    4. db-config:
    5. id-type: auto

    单元测试:

    1. @Autowired
    2. BrandService brandService;

    测试CURD

    1. BrandEntity brandEntity = new BrandEntity();
    2. brandEntity.setName("华为");
    3. brandService.save(brandEntity);
    4. System.out.println("保存成功");
    1. brandEntity.setBrandId(1L);
    2. brandEntity.setDescript("华为");
    3. brandService.updateById(brandEntity);
    1. List<BrandEntity> list = brandService.list(new QueryWrapper<BrandEntity>().eq("brand_id", 1));
    2. list.forEach((item)->{
    3. System.out.println(item);
    4. });

    生成所有微服务的代码