Iterable<Sales> sales = saleRepo.findAll();
Iterable<AdminProductions> adminproductions = adminproductionsRepo.findAll();
Integer whCount = 0;
List<Warehouse> sls = warehouseRepo.findByWarehousename(salename);
for (Warehouse sl : sls){
whCount = Integer.parseInt(sl.getWarehousecount());
whCount = whCount - Integer.parseInt(salecount);
sl.setWarehousecount(whCount.toString());
warehouseRepo.save(sl);
}
model.put("adminproductions", adminproductions);
model.put("sales", sales);
package com.example.beton.repos;
import com.example.beton.domain.AdminProductions;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface AdminProductRepo extends CrudRepository<AdminProductions, Integer> {
List<AdminProductions> findByAdminproductname(String adminproductname);
AdminProductions deleteByAdminproductname(String adminproductname);
}
package com.example.beton.controller;
import com.example.beton.domain.AdminProductions;
import com.example.beton.repos.AdminProductRepo;
import com.example.beton.repos.WarehouseRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
@Controller
//@PreAuthorize("hasAuthority('ADMIN')")
public class RemoveController {
@Autowired
private AdminProductRepo adminProductRepo;
@Autowired
private WarehouseRepo warehouseRepo;
@GetMapping("/removeproduct")
public String remPage(Map<String, Object> model){
Iterable<AdminProductions> adminproductions = adminProductRepo.findAll();
model.put("adminproductions", adminproductions);
return "removeproduct";
}
@PostMapping("/removeproduct")
public String removeAdminProduct(@RequestParam String removname, Map<String, Object> model){
adminProductRepo.deleteByAdminproductname(removname);
Iterable<AdminProductions> adminproductions = adminProductRepo.findAll();
model.put("adminproductions", adminproductions);
return "removeproduct";
}
}
контроллер
логи:
Можно заметить, что с @PostMapping("/removeproduct") System.out.println(removname) не работает