The controller is missing a value.

Asked 2 years ago, Updated 2 years ago, 124 views

I'm a beginner in programming.

No value is received from the controller.Even if I change the value from the controller, the result remains the same and the decision is not made, so I feel that the switch statement is out of touch with the controller, but I don't know what to do.Please let me know.

<tbody>
    <trth:each="User:${userList}">
        <td class="text-center">
            <divth:switch="${User.plan}">
                <pth:case="'plann'">Preparing</p>
            </div>

            <div th:case="'Save'">
                <a href="'>Save</a>
            </div>

            <div th:case="'Submit'">
                <a href=">Submit</a>
            </div>

            <div th:case="'Cancel'">
                <a href=">Cancel</a>
            </div>

            <div th:case="*">
                <a href="">Refer to </a>
            </div>-->   
        </td>
<tbody>
package com.example.demo;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.announcement.RequestMapping;

@ Controller
public class test {

    @RequestMapping(value="user")

    public String User (Model Model) {

        List<User>pro=new ArrayList<User>();

        Mission P = new Mission();

        Model.addAttribute("userList", P);

        return "userList.html";
    }

}

package com.example.demo;

public class User {

    private String plan; 

    public User() {
        This.plan="Submit";
    }

    public String getplan() {
        return MissionSt;
    }

    public void setplan(String missionSt){
        MissionSt = missionSt;
    }

thymeleaf

2022-09-29 20:29

1 Answers

There are many mistakes, but the most incorrect thing is that Model.addAttribute() is passing the Mission object to Model.addAttribute() instead of the list of users that ArrayList<User> expects.

Model.addAttribute("userList", P);

At least the following:

Model.addAttribute("userList", pro);

However, even with this modification, pro is an array with zero elements, so html does not display anything.At least one line of pro.add(...); is required.

And just a quick look at it.

  • th:switch tags not in parallel
  • <tbody> tag, <tr> tag not closed
  • <a href="'> does not require a single quotation
  • Mission and plan are mixed up
  • The method name is not getplan(), setplan(), but getPlan(), setPlan()
  • Variable names are hard to understand (List<User>pro=new ArrayList<User>();). Why is the list of users pro?
  • Variable names start with uppercase letters (Mission P=new Mission();), usually with lowercase letters.

and so on.


2022-09-29 20:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.