Как сделать UPDATE нескольких строк Spring Boot
Имеется следующий вопрос: как обновить данные пользователя, при этом не переходя на него? До этого при изменении переходил на страницу пользователя, после чего в url передавал ID. Сейчас же необходимо делать изменения непосредственно на странице со всеми пользователями. Может как-то можно при активации кнопки "активен" передавать значение id в url, но идеи у меня полностью закончились, так что прошу вашей помощи. Спасибо!
Есть страница, на которой отображаются пользователи, у которых не указан статус аккаунта:
@GetMapping("/incomingApplications")
public String incomingApplications(Customer customer, Model model) {
Iterable<Customer> notActiveCustomers = customerRepository.findNotActive(customer.getAccount_status());
model.addAttribute("customer", new Customer());
model.addAttribute("notActiveCustomers", notActiveCustomers);
return "admin/incomingApplications";
}
В базе данных, в поле "Статус аккаунта" у пользователя стоит null. Для активации пользователя администратор должен изменить статус аккаунта и сохранить изменения. Пробовал сделать следующим образом:
@PostMapping("/incomingApplications")
public String customerConfirmation(@PathVariable("id_customer") Integer id_customer,
@Valid String account_status,
@ModelAttribute("notActiveCustomers") Customer customer,
Model model) {
Customer updateCustomer = customerRepository.updateAccount(account_status, id_customer);
model.addAttribute("updateCustomer", updateCustomer);
customerRepository.save(updateCustomer);
return "redirect:/";
}
Это код Thymeleaf страницы
<form th:method="POST" th:action="@{incomingApplications}" th:object="${customer}">
<thead>
<tr>
<th>ID</th>
<th>Имя</th>
<th>Фамилия</th>
<th>Отчество</th>
<th>Почта</th>
<th>Цель</th>
<th>Вид деятельности</th>
<th>Название организации</th>
<th>Статус аккаунта</th>
</tr>
</thead>
<tbody>
<tr th:each="customer : ${notActiveCustomers}">
<td th:text="${customer.id_customer}"></td>
<td th:text="${customer.firstname}"></td>
<td th:text="${customer.lastname}"></td>
<td th:text="${customer.fathername}"></td>
<td th:text="${customer.mail}"></td>
<td th:text="${customer.goal.goal_description}"></td>
<td th:text="${customer.businessForm.business_form_name}"></td>
<td th:text="${customer.name_of_organization}"></td>
<td>
<div class="form-group">
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="account_status" name="account_status" class="custom-control-input" value="активен" th:field="*{account_status}">
<label class="custom-control-label" for="account_status">активен</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="не активен" name="не активен" class="custom-control-input" value="не активен" th:field="*{account_status}">
<label class="custom-control-label" for="не активен">не активен</label>
</div>
</div>
<button class="btn btn-primary" type="submit">Сохранить изменения</button>
</td>
Репозиторий:
@Query("select cust from Customer cust where cust.account_status is null")
Iterable<Customer> findNotActive(String account_status);
@Query("update Customer set account_status = (:account_status) where id_customer = (:id_customer)")
Customer updateAccount(@Param("account_status") String account_status, @Param("id_customer") Integer id_customer);
