弹簧

时间:2018-06-07 14:07:19

标签: spring thymeleaf

在创建网络应用程序时,我真的很环保,而且我被困了。

因此,在用户登录我的应用程序后,我的目标是创建下拉菜单,其中包含我在数据库中的所有用户。  这是我把它放在选择菜单中的方式:

@RequestMapping(value = "/loginWeb", method = RequestMethod.POST)
public String loginWeb(HttpServletRequest request, Model model) {
model.addAttribute("users", repository.findAll());
return "loginWeb"; }

我的loginWeb模板如下所示:

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Title</title>
</head>
<body>
<p>Choose employee</p>
<form th:action="@{/getDetailsWeb}" method="post">
    <select name="idUser">
        <option th:each="user : ${users}"
                th:value="${user.idUser}"
                th:text="${user.lastName}"/>
    </select>
    <button type="submit" value="Submit" title="Submit">Get details</button>
</form>
</body>
</html>

,下拉菜单中填充了用户的姓氏。问题是我想将idUser传递给我的控制器中的另一个方法,它具有奇怪的价值,基本上它不起作用。我的第二种方法:

@RequestMapping(value = "/getDetailsWeb", method = RequestMethod.POST)
public String loginTimestampWeb(@RequestParam("idUser") String idUser, Model model) {
    // here i tired to acquired idUser and start a new template with it
    return "details"; // template displaying id
}

我的用户类:

@Entity
@Table(name="users")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "idUser", unique = true, nullable = false)
    @Expose
    @SerializedName("idUser")
    private Integer idUser;
    @Expose
    @SerializedName("firstName")
    private String firstName;
    @Expose
    @SerializedName("lastName")
    private String lastName;
    @Column(nullable = false, columnDefinition = "TINYINT(1)")
    @Expose
    @SerializedName("isAdmin")
    private boolean isAdmin;
    @Expose
    @SerializedName("password")
    private String password;
    @Expose
    @SerializedName("currentToken")
    private String currentToken;
    @Expose
    @SerializedName("photo")
    private String photo;

    public User() {
    }

    public User(String firstName, String lastName, String password, String currentToken, String photo) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.isAdmin = false;
        this.password = password;
        this.currentToken = currentToken;
        this.photo = photo;
    }

    public Integer getIdUser() {
        return idUser;
    }

    public void setId(Integer idUser) {
        this.idUser = idUser;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Boolean getAdmin() {
        return isAdmin;
    }

    public void setAdmin(Boolean admin) {
        isAdmin = admin;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCurrentToken() {
        return currentToken;
    }

    public void setCurrentToken(String currentToken) {
        this.currentToken = currentToken;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }
}

任何帮助将不胜感激

0 个答案:

没有答案