Open anishcana opened 3 months ago
<!DOCTYPE html>
ID:
Name:
Age:
<!DOCTYPE html>
ID:
Name:
Age:
<h1>Record Details</h1>
<p>ID: <span th:text="${record.id}"></span></p>
<p>Name: <span th:text="${record.name}"></span></p>
<p>Age: <span th:text="${record.age}"></span></p>
{ if (id != null) { Record record = recordService.getRecordById(id); if (record != null) { model.addAttribute("record", record); return "nextScreen"; }
private final RecordService recordService;
@Autowired
public TableController(RecordService recordService) {
this.recordService = recordService;
}
// RecordService.java package com.example.demo;
import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.List;
@Service public class RecordService {
// Dummy data for demonstration
private final List<Record> records = new ArrayList<>();
public RecordService() {
// Initialize dummy records
records.add(new Record(1, "John Doe", 30));
records.add(new Record(2, "Jane Smith", 25));
// Add more records as needed
}
public List<Record> getAllRecords() {
return records;
}
public Record getRecordById(int id) {
for (Record record : records) {
if (record.getId() == id) {
return record;
}
}
return null; // Return null if record with given ID is not found
}
}
<td><a th:href="@{/next(id=${record.id})}">Click Here</a></td>
// TableController.java package com.example.demo;
import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable;
@Controller public class TableController {
}