Spring MVC form:select selected value?

后端 未结 6 1397
遇见更好的自我
遇见更好的自我 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:40

    prior to binding the form to the model, you should set whatever variable you want to be selected to the desired value in the controller of your jsp.

        Form form = new Form();
        form.setFoo("bar");
        model.addAttribute("form", form);
    

    When the form is built in the jsp, that form variable will be the default selected value in your options list.

提交回复
热议问题