Html 提交后无法显示选定的下拉列表值
单击“提交”后,我无法显示选定的下拉列表值Html 提交后无法显示选定的下拉列表值,html,spring,spring-boot,spring-mvc,thymeleaf,Html,Spring,Spring Boot,Spring Mvc,Thymeleaf,单击“提交”后,我无法显示选定的下拉列表值 基础知识 XYZ 当我选择XYZ并提交时 我在您的表单中没有看到提交按钮。不过我明白你的要求。假设page1.html首先由一些控制器方法加载,如下所示 @GetMapping(path = "/") public ModelAndView home() { ModelAndView mav = new ModelAndView(); mav.addObject("value", "XYZ");
基础知识
XYZ
当我选择XYZ并提交时
我在您的表单中没有看到提交按钮。不过我明白你的要求。假设page1.html首先由一些控制器方法加载,如下所示
@GetMapping(path = "/")
public ModelAndView home()
{
ModelAndView mav = new ModelAndView();
mav.addObject("value", "XYZ");
mav.setViewName("page1");
return mav;
}
这提供了下面的html页面表单
<form action="#" th:action="@{/page1/send}" method="post">
<select class="form-control" name="action" id="action">
<option th:selected="'ABC' == ${value}" value="ABC">ABC</option>
<option th:selected="'XYZ' == ${value}" value="XYZ">XYZ</option>
</select>
<input type="submit" value="submit"/>
</form>
如果有帮助,请告诉我
@RequestMapping("/page1/send")
public String testSubmit(@RequestParam("action") String action, Model model) {
model.addAttribute("value",action);
return "page1";
}