Код контроллера Spring для обработки индексной страницы (LaptopController.java):
Код: Выделить всё
@Controller
@RequestMapping("/manage-laptops")
public class LaptopController
{
@Autowired
public LaptopService laptopService;
@Autowired
private DatabaseLaptopService dbLaptopService;
// private List idList = new ArrayList();
@GetMapping(path = "/home")
public String handleIndexPage(@RequestParam(required = false) Map allParams, Model model)
{
List laptops = new ArrayList();
Pageable pageable = null;
Page chunk = null;
int pageSize = 5;
if (!allParams.isEmpty())
{
if (allParams.containsKey("filter_by"))
{
}
if (allParams.containsKey("page") && allParams.containsKey("size"))
{
String page = (String)allParams.get("page");
String size = (String)allParams.get("size");
pageable = PageRequest.of(Integer.parseInt(page) - 1, Integer.parseInt(size));
chunk = dbLaptopService.getAllLaptops(pageable);
laptops = chunk.getContent();
}
else
{
pageable = PageRequest.of(0, 5);
chunk = dbLaptopService.getAllLaptops(pageable);
laptops = chunk.getContent();
}
HashSet unique = new HashSet();
List tmp = laptops;
unique.addAll(laptops);
laptops = new ArrayList(tmp);
laptops.clear();
laptops.addAll(unique);
}
else
{
pageable = PageRequest.of(0, 5);
chunk = dbLaptopService.getAllLaptops(pageable);
laptops = chunk.getContent();
}
model.addAttribute("currentPage", chunk.getNumber() + 1);
model.addAttribute("totalItems", chunk.getTotalElements());
model.addAttribute("totalPages", chunk.getTotalPages());
model.addAttribute("pageSize", pageSize);
model.addAttribute("laptop", new Laptop());
// model.addAttribute("idList", idList);
SelectedIds selectedIds = new SelectedIds();
model.addAttribute("selectedIds", selectedIds);
model.addAttribute("laptops", laptops);
return "laptopHomePage";
}
}
Код: Выделить всё
Device Form
body {
background-color: #f8f9fa;
padding: 30px;
}
.form-container {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
padding: 20px;
}
Device Information Form
Model Name
Description
RAM Capacity (GB)
Disk Capacity (GB)
Submit
Filter
Select
Model Name
Model Description
Ram
Disk capacity
Код: Выделить всё
Код: Выделить всё
@PostMapping(path = "/delete-selected")
public String deleteSelected(@ModelAttribute("selectedIds") SelectedIds selectedIds, Model model)
{
if (selectedIds != null)
{
System.out.println("Selected: " + selectedIds.getIds().size());
}
return "redirect:home";
}
Код: Выделить всё
Selected: 0
Подробнее здесь: https://stackoverflow.com/questions/791 ... el-as-attr