Java Code Examples for cn.hutool.core.bean.BeanUtil#copyProperties()

The following examples show how to use cn.hutool.core.bean.BeanUtil#copyProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NoBootTest.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testBeanUtil() {

    //10000 - 511
    //50000 - 719
    //100000 - 812
    //1000000 - 2303

    TimeInterval timer = DateUtil.timer();
    for (int i = 0; i <= 1000000; i++) {
        Org org = Org.builder()
                .label("string")
                .id(123L + i)
                .createTime(LocalDateTime.now())
                .build();
        Station station = Station.builder().id(1L + i).name("nihaoa").createTime(LocalDateTime.now()).orgId(new RemoteData(12L, org)).build();

        StationPageDTO stationPageDTO = new StationPageDTO();

        BeanUtil.copyProperties(station, stationPageDTO);
    }

    long interval = timer.interval();// 花费毫秒数
    long intervalMinute = timer.intervalMinute();// 花费分钟数
    StaticLog.info("本次程序执行 花费毫秒数: {} ,   花费分钟数:{} . ", interval, intervalMinute);
}
 
Example 2
Source File: MenuController.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取菜单信息
 *
 * @author fengshuonan
 * @Date 2018/12/23 5:53 PM
 */
@RequestMapping(value = "/getMenuInfo")
@ResponseBody
public ResponseData getMenuInfo(@RequestParam Long menuId) {
    if (ToolUtil.isEmpty(menuId)) {
        throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
    }

    Menu menu = this.menuService.getById(menuId);

    MenuDto menuDto = new MenuDto();
    BeanUtil.copyProperties(menu, menuDto);

    //设置pid和父级名称
    menuDto.setPid(ConstantFactory.me().getMenuIdByCode(menuDto.getPcode()));
    menuDto.setPcodeName(ConstantFactory.me().getMenuNameByCode(menuDto.getPcode()));

    return ResponseData.success(menuDto);
}
 
Example 3
Source File: HutoolController.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
@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> map = BeanUtil.beanToMap(brand);
    LOGGER.info("beanUtil bean to map:{}", map);
    //Map转Bean
    PmsBrand mapBrand = BeanUtil.mapToBean(map, PmsBrand.class, false);
    LOGGER.info("beanUtil map to bean:{}", mapBrand);
    //Bean属性拷贝
    PmsBrand copyBrand = new PmsBrand();
    BeanUtil.copyProperties(brand, copyBrand);
    LOGGER.info("beanUtil copy properties:{}", copyBrand);
    return CommonResult.success(null, "操作成功");
}
 
Example 4
Source File: IndexController.java    From pre with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 保存完信息然后跳转到绑定用户信息页面
 *
 * @param request
 * @param response
 * @throws IOException
 */
@GetMapping("/socialSignUp")
public void socialSignUp(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String uuid = UUID.randomUUID().toString();
    SocialUserInfo userInfo = new SocialUserInfo();
    Connection<?> connectionFromSession = providerSignInUtils.getConnectionFromSession(new ServletWebRequest(request));
    userInfo.setHeadImg(connectionFromSession.getImageUrl());
    userInfo.setNickname(connectionFromSession.getDisplayName());
    userInfo.setProviderId(connectionFromSession.getKey().getProviderId());
    userInfo.setProviderUserId(connectionFromSession.getKey().getProviderUserId());
    ConnectionData data = connectionFromSession.createData();
    PreConnectionData preConnectionData = new PreConnectionData();
    BeanUtil.copyProperties(data, preConnectionData);
    socialRedisHelper.saveConnectionData(uuid, preConnectionData);
    // 跳转到用户绑定页面
    response.sendRedirect(url + "/bind?key=" + uuid);
}
 
Example 5
Source File: UserController.java    From kvf-admin with MIT License 6 votes vote down vote up
@GetMapping(value = "edit")
public ModelAndView edit(Long id) {
    ModelAndView mv = new ModelAndView("sys/user_edit");
    UserEditDTO userEditDTO = new UserEditDTO();
    UserRoleGroupDTO userRoleGroupDTO = new UserRoleGroupDTO();
    if (id != null) {
        User user = userService.getById(id);
        Dept dept = deptService.getById(user.getDeptId());
        userRoleGroupDTO = userRoleService.getUserRoleGroupDTOByUserId(id);
        BeanUtil.copyProperties(user, userEditDTO);
        userEditDTO.setDeptName(dept == null ? "" : dept.getName());
    }
    userEditDTO.setUserRole(userRoleGroupDTO);
    mv.addObject("editInfo", userEditDTO);
    return mv;
}
 
Example 6
Source File: NoBootTest.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Test
    public void testBeanUtilToBean() {
        Menu menu = Menu.builder()
                .id(123L)
                .label("menu")
                .group("group")
                .createTime(LocalDateTime.MAX)
                .icon("aicon")
                .build();

//        VueRouter vueRouter = BeanUtil.toBean(menu, VueRouter.class);

        Map<String, String> map = new HashedMap();
        map.put("name", "path");
//        VueRouter vueRouter = BeanUtil.toBean(VueRouter.class, new ValueProvider<String>(){
//            @Override
//            public Object value(String key, Type valueType) {
//                return "1";
//            }
//
//            @Override
//            public boolean containsKey(String key) {
//                return true;
//            }
//        }, CopyOptions.create().setFieldMapping(map));

        VueRouter vueRouter = new VueRouter();
        BeanUtil.copyProperties(menu, vueRouter, CopyOptions.create().setFieldMapping(map));


        System.out.println(vueRouter);
    }
 
Example 7
Source File: RestMenuService.java    From Guns with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 根据请求的父级菜单编号设置pcode和层级
 *
 * @author fengshuonan
 * @Date 2018/12/23 5:54 PM
 */
public RestMenu menuSetPcode(MenuDto menuParam) {

    RestMenu resultMenu = new RestMenu();
    BeanUtil.copyProperties(menuParam, resultMenu);

    if (ToolUtil.isEmpty(menuParam.getPid()) || menuParam.getPid().equals(0L)) {
        resultMenu.setPcode("0");
        resultMenu.setPcodes("[0],");
        resultMenu.setLevels(1);
    } else {
        Long pid = menuParam.getPid();
        RestMenu pMenu = this.getById(pid);
        Integer pLevels = pMenu.getLevels();
        resultMenu.setPcode(pMenu.getCode());

        //如果编号和父编号一致会导致无限递归
        if (menuParam.getCode().equals(menuParam.getPcode())) {
            throw new ServiceException(BizExceptionEnum.MENU_PCODE_COINCIDENCE);
        }

        resultMenu.setLevels(pLevels + 1);
        resultMenu.setPcodes(pMenu.getPcodes() + "[" + pMenu.getCode() + "],");
    }

    return resultMenu;
}
 
Example 8
Source File: YxSystemUserLevel.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(YxSystemUserLevel source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 9
Source File: YxSystemUserTask.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(YxSystemUserTask source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 10
Source File: AlipayConfig.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(AlipayConfig source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 11
Source File: YxStoreCouponIssueUser.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(YxStoreCouponIssueUser source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 12
Source File: LocalStorage.java    From eladmin with Apache License 2.0 4 votes vote down vote up
public void copy(LocalStorage source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 13
Source File: EmailConfig.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(EmailConfig source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 14
Source File: LocalStorage.java    From sk-admin with Apache License 2.0 4 votes vote down vote up
public void copy(LocalStorage source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 15
Source File: YxStoreCart.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(YxStoreCart source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 16
Source File: User.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(User source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 17
Source File: YxStoreCombination.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(YxStoreCombination source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 18
Source File: BlockTxDetailInfoDAO.java    From WeBASE-Collect-Bee with Apache License 2.0 4 votes vote down vote up
public void save(BlockTxDetailInfoBO bo) {
    BlockTxDetailInfo blockTxDetailInfo = new BlockTxDetailInfo();
    BeanUtil.copyProperties(bo, blockTxDetailInfo, true);
    blockTxDetailInfoRepository.save(blockTxDetailInfo);
}
 
Example 19
Source File: ServerDeploy.java    From eladmin with Apache License 2.0 4 votes vote down vote up
public void copy(ServerDeploy source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
 
Example 20
Source File: YxSystemConfig.java    From yshopmall with Apache License 2.0 4 votes vote down vote up
public void copy(YxSystemConfig source){
    BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}