gpt4 book ai didi

java - 值图不是模型的成员

转载 作者:行者123 更新时间:2023-11-30 08:15:17 24 4
gpt4 key购买 nike

您好,我正在尝试从类中获取对象并显示它,但收到错误“值映射不是 models.TimeSheetDataStore 的成员”

这是我的模型类文件

TimeSheetDataStore.java

package models;
public class TimeSheetDataStore {
String ID;
String EmployeeID;
String RoleID;
String Task;
String TimeSheetDate;
String CreateDate;
String UpdateDate;
String TaskHour;
String IsBilled;
String ClientID;
String ProjectID;
String atHome;
String atClientSite;
}

TimeSheet.java

package models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import models.TimeSheetDataStore;

public class Timesheet {
public static List<TimeSheetDataStore> PopulateProject() {
List<TimeSheetDataStore> TimeSheetList = new ArrayList<TimeSheetDataStore>();
try {

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433","SUMEET","sumeet");
Statement sta = conn.createStatement();
String Sql = "select * from Project";
ResultSet rs = sta.executeQuery(Sql);
while (rs.next()) {
TimeSheetDataStore TSDS= new TimeSheetDataStore();
TSDS.ID=rs.getString("ID");
TSDS.EmployeeID=rs.getString("EmployeeID");
TSDS.RoleID=rs.getString("RoleID");
TSDS.Task=rs.getString("Task");
TSDS.TimeSheetDate=rs.getString("TimeSheetDate");
TSDS.CreateDate=rs.getString("CreateDate");
TSDS.UpdateDate=rs.getString("UpdateDate");
TSDS.TaskHour=rs.getString("TaskHour");
TSDS.IsBilled=rs.getString("IsBilled");
TSDS.ProjectID=rs.getString("ProjectID");
TSDS.ClientID=rs.getString("ClientID");
TSDS.atHome=rs.getString("atHome");
TSDS.atClientSite=rs.getString("atClientSite");
TimeSheetList.add(TSDS);
}

} catch (InstantiationException | IllegalAccessException
| ClassNotFoundException |SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return(TimeSheetList);

}

}

Controller 文件应用程序.java

public static Result myAction(String ClientFilter,String ConsultantFilter) {
DynamicForm requestData = Form.form().bindFromRequest();

if (requestData.get("Submit")!=null) {
return ok(index.render(Client.PopulateClient(),Consultant.PopulateConsultant(),Project.PopulateProject(ClientFilter)));
} else if (requestData.get("Generate Timesheet")!=null) {
//return ok(list.render(Client.PopulateClient(),Consultant.PopulateConsultant(),Project.PopulateProject()));
return ok(DisplayTimeSheet.render(Timesheet.PopulateProject()));
} else {
return badRequest("This action is not allowed");
}

}

查看文件 DisplayTimeSheet.scala.html

@(currentPage:List[TimeSheetDataStore])



<html>
<head></head>
<body>
<form>
<table>
<thead>
<tr>
<td>ID</td>
<td>EmployeeID</td>
<td>RoleID</td>
<td>Task</td>
<td>TimeSheetDate</td>
<td>CreateDate</td>
<td>UpdateDate</td>
<td>TaskHour</td>
<td>IsBilled</td>
<td>ProjectID</td>
<td>ClientID</td>
<td>atHome</td>
<td>atClientSite</td>
</tr>
</thead>
<tbody>
@for(i <- currentPage.indices) {
@for(element <- currentPage.get(i)) {
<tr>
<td>@element.ID</td>
<td>@element.EmployeeID</td>
<td>@element.RoleID</td>
<td>@element.Task</td>
<td>@element.TimeSheetDate</td>
<td>@element.CreateDate</td>
<td>@element.UpdateDate</td>
<td>@element.TaskHour</td>
<td>@element.IsBilled</td>
<td>@element.ProjectID</td>
<td>@element.ClientID</td>
<td>@element.atHome</td>
<td>@element.atClientSite</td>
</tr>
}
}
</tbody>
</table>
</form>
</body>
</html>

有人可以告诉我我做错了什么吗?

最佳答案

尝试代替

@for(i <- currentPage.indices) {
@for(element <- currentPage.get(i)) {
<tr>
<td>@element.ID</td>
<td>@element.EmployeeID</td>
<td>@element.RoleID</td>
.
.
.
</tr>
}
}

仅使用一个 for 循环,因为您有 currentPage: List[TimeSheetDataStore] 列表所以当你这样做时@for(element <- currentPage)它会返回一个分配给元素变量的对象,所以现在你有 TimeSheetDataStore元素变量中的对象,以便您可以直接访问它的字段

这样做:

<tbody>
@for(element <- currentPage) {
<tr>
<td>@element.ID</td>
<td>@element.EmployeeID</td>
<td>@element.RoleID</td>
<td>@element.Task</td>
<td>@element.TimeSheetDate</td>
<td>@element.CreateDate</td>
<td>@element.UpdateDate</td>
<td>@element.TaskHour</td>
<td>@element.IsBilled</td>
<td>@element.ProjectID</td>
<td>@element.ClientID</td>
<td>@element.atHome</td>
<td>@element.atClientSite</td>
</tr>
}
</tbody>

关于java - 值图不是模型的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29743070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com