java Spring应用程序未在网页中显示数据?
我遇到的问题是,当加载localhost:8080时,html页面会显示,但是数据不会显示在web应用程序中,因为它是空的。显示的唯一信息是每个文本的标题,例如来自HTML页面的职务参考。知道为什么我的数据库中的信息没有显示吗?我已经检查了正确的数据库名和表名。下面是包含控制器、存储库、服务、模型和html的代码
作业类的控制器
@Controller
public class JobController {
@Autowired
private JobService jobService;
//display list of jobs
@GetMapping("/")
public String viewHomePage(Model model) {
model.addAttribute("listJobs",jobService.getAllJobs());
return "index";
}
}
作业模型的类
@Entity
@Table(name = "jobsmanagement")
public class Job {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "job_reference")
private String jobReference;
@Column(name = "client_id")
private int clientId;
@Column(name = "location")
private String location;
@Column(name = "description")
private String description;
@Column(name = "status")
private String status;
@Column(name = "driver_rider_id")
private int driverRiderId;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getJobReference() {
return jobReference;
}
public void setJobReference(String jobReference) {
this.jobReference = jobReference;
}
public int getClientId() {
return clientId;
}
public void setClientId(int clientId) {
this.clientId = clientId;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getDriverRiderId() {
return driverRiderId;
}
public void setDriverRiderId(int driverRiderId) {
this.driverRiderId = driverRiderId;
}
}
作业库
@Repository
public interface JobRepository extends JpaRepository<Job, Long> {
}
为工作服务
public interface JobService {
List<Job> getAllJobs();
}
作业的serviceImpl
@Service
public class JobServiceImpl implements JobService {
@Autowired
private JobRepository jobRepository;
@Override
public List<Job> getAllJobs() {
return jobRepository.findAll();
}
}
索引页html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Job Management System</title>
</head>
<body>
<div align="center">
<h1> Job List </h1>
<table border="1">
<thead>
<tr>
<th>Job Reference</th>
<th>Client ID</th>
<th>Location</th>
<th>Description</th>
<th>Status</th>
<th>Driver Rider ID</th>
</tr>
</thead>
<tbody>
<tr th:each="job : ${listJobs}">
<td th:text="${job.jobReference}"></td>
<td th:text="${job.clientId}"></td>
<td th:text="${job.location}"></td>
<td th:text="${job.description}"></td>
<td th:text="${job.status}"></td>
<td th:text="${job.driverRiderId}"></td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
共 (0) 个答案