值映射不是模型的成员

value map is not a member of models

您好,我正在尝试从 class 中获取一个对象并显示它,但出现错误 "value map is not a member of models.TimeSheetDataStore"

这是我的模型 class 个文件

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);

    }

}

控制器文件 Application.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) 时,它会 return 您将一个对象分配给元素变量,所以现在您有 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>