小编gaz*_*lo4的帖子

Java在TreeMap上迭代 - 不兼容的类型

我有以下集合:

private Map <String, Staff> staff;
Run Code Online (Sandbox Code Playgroud)

实现为TreeMap:

staff = new TreeMap <String, Staff> ();
Run Code Online (Sandbox Code Playgroud)

我需要迭代这个映射中的值,但是当我尝试下面的代码时,我得到了一个不兼容的类型编译错误.我不明白为什么会这样; 我的地图中的值是Staff对象和

it.HasNext() 
Run Code Online (Sandbox Code Playgroud)

应该将它们返回存储在staffMember变量中,这应该对我的知识很好?非常感谢.

Collection <Staff> staffList = staff.values(); 
         Iterator it = staffList.iterator ();
         while ((isJobAssigned = false) ||it.hasNext())
         {
             Staff staffMember = it.next(); 
             if ((staffMember instanceof Typist) && (jobType.equalsIgnoreCase("Typist")))
             {
                 newJob.setJobState ("Assigned");
                 staffMember.setState("Working");
                 return newJon.getJobNo() + " Staff allocated: " + staffMember.getName () + ", ID: " + staffMember.getId();
                }
Run Code Online (Sandbox Code Playgroud)

java iteration iterator treemap

3
推荐指数
1
解决办法
211
查看次数

为什么POST动作会丢失模型值?

我有一个ViewModel,我试图回发以保存在数据库中.虽然ViewModel正在获取//GET Create(int id)它所设置的值,但是当它到达时它会丢失一些//POST Create ().将GoalLevelGoalTitle正在通过确定已过,但ActorIdProjectId正在丧失,甚至虽然调试器是通过去if (Model.State.IsValid)块,即正在经历的值没有被保存到数据库中.然后重定向会失败,因为我不再有效ProjectId传递给URL.

如果你知道你在做什么,我相信这是显而易见的!

CONTROLLER

  // GET: UseCases/Create

    public ActionResult Create(int id)

    {

        ViewBag.projectId = id;

        //Populate the ViewModel
        UserGoalsStepViewModel model = new UserGoalsStepViewModel()
        {
            ProjectId = id,
            ActorList = new SelectList(db.Actors.Where(a => a.projectID == id), "id", "Title"),

        };

        return View(model);
    }

    // POST: UseCases/Create
    // To protect from overposting attacks, please enable the specific properties you want to bind to, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

2
推荐指数
1
解决办法
114
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

iteration ×1

iterator ×1

java ×1

treemap ×1