第六节 使用HuTool工具处理Bean

亮子 2023-11-25 14:46:02 20264 0 0 0
 @ApiOperation("BeanUtil使用,JavaBean的工具类")
    @GetMapping("/beanUtil")
    public CommonResult beanUtil(){
        PmsBrand brand = new PmsBrand();
        brand.setId(1L);
        brand.setName("小米");
        brand.setShowStatus(0);
        //Bean转Map
        Map<String, Object> mapBread = BeanUtil.beanToMap(brand);
        LOGGER.info("beanUtil map to bean:{}",mapBread);
        //Bean属性拷贝
        PmsBrand copyBrand = new PmsBrand();
        BeanUtils.copyProperties(brand,copyBrand);
        LOGGER.info("beanUtil copy properties:{}",copyBrand);
        return CommonResult.success(null,"操作成功!");
    }