Spring MVC form:select selected value?

后端 未结 6 1396
遇见更好的自我
遇见更好的自我 2021-02-19 09:56

Is there any way to select current value in dropdown list by Spring MVC by ?

6条回答
  •  清歌不尽
    2021-02-19 10:19

    No need to use if else

    Example:

    Student student = new Student();
    student.gender = "F";
    model.addObject("student", student);
    
    Map genders = new LinkedHashMap();
    genders.put("M", "Male");
    genders.put("F", "Female");
    model.addObject("genders", genders);
    

    JSP Code

    modelAttribute & commandName are interchangeable

    
    
      
        
      
    
    

提交回复
热议问题