Example usage for org.springframework.beans BeanUtils copyProperties

List of usage examples for org.springframework.beans BeanUtils copyProperties

Introduction

In this page you can find the example usage for org.springframework.beans BeanUtils copyProperties.

Prototype

private static void copyProperties(Object source, Object target, @Nullable Class<?> editable,
        @Nullable String... ignoreProperties) throws BeansException 

Source Link

Document

Copy the property values of the given source bean into the given target bean.

Usage

From source file:com.kazuki43zoo.jpetstore.ui.controller.MyAccountController.java

@PostMapping("/update")
public String update(@Validated AccountForm form, BindingResult result,
        @AuthenticationPrincipal(expression = "account") Account account, Model model,
        RedirectAttributes redirectAttributes) {

    if (result.hasErrors()) {
        model.addAttribute(new Messages().error("Input values are invalid. Please confirm error messages."));
        return "account/updateForm";
    }/*  w w  w  .  j av a2 s  . c o m*/

    BeanUtils.copyProperties(form, account, "username", "password");

    accountService.updateAccount(account, form.getPassword());

    publisher.publishEvent(new EntityChangedEvent<>(this, account));

    redirectAttributes.addFlashAttribute(new Messages().success("Your account has been updated."));

    return "redirect:/my/account/update?form";
}