单选按钮发送过“假”吗?

时间:2019-08-12 13:41:35

标签: spring java-ee

在我的user.jsp中,我有两个单选按钮,一个必须发送“ true”,另一个必须发送“ false”。但两者都发送“ false”

我的user.jsp和我的表单以及两个单选按钮:

<form action="create_user_bdd">
        <label for="pseudo">Pseudo</label><br><br>
        <input type="text" name="pseudo"><br><br>
        <label for="email">E-mail</label><br><br>
        <input type="text" name="email"><br><br>
        <label for="password">Password</label><br><br>
        <input type="text" name="password"><br><br>
<div>
<label for="isAdmin">Student</label>
<input type="radio" id="student" name="isAdmin" value="false" checked>
        </div>
<div>
<label for="isAdmin">Admin</label>
<input type="radio" id="admin" name="isAdmin" value="true"><br><br>
</div>
        <input type="submit" value="Create User">
</form>

我的模型“ User”和带有布尔值的boolean“ isAdmin”:

package Projet.stage.maven.virtualschool4.model;


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private Integer id_salle;
private String pseudo;
private String lastSee;
private String email;
private String password;
private boolean isAdmin;



public User() {
}

public User(Integer id, Integer id_salle, String pseudo, String 
lastSee, String email, String password, boolean isAdmin) {
    this.id = id;
    this.id_salle = id_salle;
    this.pseudo = pseudo;
    this.lastSee = lastSee;
    this.email = email;
    this.password = password;
    this.isAdmin = isAdmin;
}

public User(Integer id_salle, String pseudo, String lastSee, String 
email, String password, boolean isAdmin) {
    this.id_salle = id_salle;
    this.pseudo = pseudo;
    this.lastSee = lastSee;
    this.email = email;
    this.password = password;
    this.isAdmin = isAdmin;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public int getId_salle() {
    return id_salle;
}

public void setId_salle(int id_salle) {
    this.id_salle = id_salle;
}

public String getPseudo() {
    return pseudo;
}

public void setPseudo(String pseudo) {
    this.pseudo = pseudo;
}

public String getLastSee() {
    return lastSee;
}

public void setLastSee(String lastSee) {
    this.lastSee = lastSee;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

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

public boolean isAdmin() {
    return isAdmin;
}

public void setAdmin(boolean isAdmin) {
    this.isAdmin = isAdmin;
}

}

我的控制器:

package Projet.stage.maven.virtualschool4.controller;


import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import Projet.stage.maven.virtualschool4.model.Room;
import Projet.stage.maven.virtualschool4.model.User;
import Projet.stage.maven.virtualschool4.repository.RoomRepository;


@Controller
public class AdminController {
@Autowired
RoomRepository repo;

@RequestMapping(value = { "create_room" }, method = RequestMethod.GET)
public String index(Model model) {
    return "create_room";
}

@RequestMapping(value = { "create_user" }, method = RequestMethod.GET)
public String index2(Model model) {
    return "create_user";
}



@RequestMapping("/create_user_bdd")
public String index5(@ModelAttribute User user, Model model) {

    model.addAttribute("pseudo", user.getPseudo());
    model.addAttribute("email", user.getEmail());
    model.addAttribute("password", user.getPassword());
    model.addAttribute("isAdmin", user.isAdmin());


System.out.println("userPseudo : " +  user.getPseudo().toString());
System.out.println("userEmail : " + user.getEmail().toString());
System.out.println("userPassword : " + user.getPassword().toString());
System.out.println("usersAdmin : " + user.isAdmin());

    return "admin";
}

}

无论单选按钮选择什么,在我的控制台中,返回始终为“ false”?

0 个答案:

没有答案