2017-04-25 3 views
0

Comment accéder au contrôleur l'utilisateur a entré les données à html - checkBox et sélectionnez la liste. J'ai utilisé Thymeleaf et SpringBoot.Spring Boot Thymeleaf GetParameter

<form id="register-form" th:object="${worker}" th:action="@{/worker/save}" 
              method="post" 
              role="form"> 
             <div class="form-group"> 
              <input type="text" th:field="*{firstName}" id="firstName" tabindex="1" 
                class="form-control" placeholder="First Name" value=""/> 
             </div> 
             <div class="form-group"> 
              <input type="text" th:field="*{secondName}" id="secondName" tabindex="1" 
                class="form-control" placeholder="Second Name" value=""/> 
             </div> 

             <div class="form-group"> 
              <input class="form-control" placeholder="Date of Bithday" type="text" 
                th:field="*{dateBirth}" id="datepicker"/> 
             </div> 

             <div class="form-group"> 
              <label class="checkbox-inline"> 
               <input type="checkbox" value="java"/>JAVA Skill 
              </label> 
              <select class="form-control" id="exampleSelect1"> 
               <option value=""></option> 
               <option value="first"> First level</option> 
               <option value="second"> Second level</option> 
               <option value="third"> Third level</option> 
               <option value="fourth"> Fourth level</option> 
               <option value="fifth"> Fifth level</option> 
              </select> 
             </div> 

             <div class="form-group"> 
              <label class="checkbox-inline"> 
               <input th:field="*{phpSkill}" type="checkbox" value="php"/>PHP Skill 
              </label> 
              <select class="form-control" id="exampleSelect2"> 
               <option value=""></option> 
               <option value="first"> First level</option> 
               <option value="second"> Second level</option> 
               <option value="third"> Third level</option> 
               <option value="fourth"> Fourth level</option> 
               <option value="fifth"> Fifth level</option> 
              </select> 
             </div> 

             <div class="form-group"> 
              <label class="checkbox-inline"> 
               <input th:field="*{javascriptSkill}" type="checkbox" 
                 value="javascript"/>JAVA 
               SCRIPT Skill 
              </label> 
              <select class="form-control" id="exampleSelect3"> 
               <option value=""></option> 
               <option value="first"> First level</option> 
               <option value="second"> Second level</option> 
               <option value="third"> Third level</option> 
               <option value="fourth"> Fourth level</option> 
               <option value="fifth"> Fifth level</option> 
              </select> 
             </div> 

             <hr/> 


             <div class="form-group"> 
              <div class="row"> 
               <div class="col-sm-6 col-sm-offset-3"> 
                <input type="submit" name="register-submit" id="register-submit" 
                  tabindex="4" class="form-control btn btn-register" 
                  value="Register Now"/> 
               </div> 
              </div> 
             </div> 
            </form> 

Ceci est mon code Controller: Je dois recevoir ici sélectionner la valeur option et vérifier la valeur de la boîte

@Controller 
public class WorkerController { 



    private WorkerServ workerServ; 

     @Autowired 
     public WorkerController(WorkerServ workerServ) { 
      this.workerServ = workerServ; 
     } 

     @RequestMapping(value = "/worker/register") 
     public String saveWorker(Model model) { 
      model.addAttribute("worker", new Worker()); 
      return "signupWorker"; 
     } 
     @RequestMapping(value = "worker/save", method = RequestMethod.POST) 
     public String saveWorker(Worker worker) { 
      String firstName = worker.getFirstName(); 
      String secondName = worker.getSecondName(); 
      String dateBith = worker.getDateBirth(); 


      workerServ.registerWorker(firstName, secondName, dateBith, null); 
      return "index"; 
     } 
    } 

Répondre

0

Si vous utilisez javaSkill et niveau CheckBox et Select, votre modèle "travailleur" devrait avoir les variables avec getter et setter!

CheckBox:

<input type="checkbox" name="javaSkill" th:checked="*{javaSkill}" /> 

Sélectionner:

<select th:field="*{level}"> 
    <option th:value="first" th:text="First Level"></option> 
    <option th:value="second" th:text="Second Level"></option> 
</select> 
0

Voici un exemple simple et efficace pour le menu déroulant

Exemple

<select class="form-control" th:value="${appointment.location}" name="location" id="location"> 
         <option disabled="disabled" selected="selected" > -- select the location --</option> 
         <option>Boston</option> 
         <option>New York</option> 
         <option>Chicago</option> 
         <option>San Francisco</option> 
        </select> 

si vous accédez à la valeur location dans le contrôleur, alors vous serez en mesure d'obtenir la valeur de la liste déroulante

semblable va cocher la case