当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
SpringBoot中使用thymeleaf模板时select下拉框怎样查询数据库赋值
生活随笔
收集整理的这篇文章主要介绍了
SpringBoot中使用thymeleaf模板时select下拉框怎样查询数据库赋值
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
场景
实现效果
数据库中码表设计
实现
thymeleaf页面代码
当前页面为:
receiveOrder/wmsReceiveOrder.html
<div class="col-sm-2"><div class="form-group"><label class="col-form-label" for="result">状态</label><select class="form-control" id="status" name="status"><option value="">全部</option><option th:each="result : ${codeList}" th:value="${result.codeValue}" th:text="${result.codeName}"></option></select></div></div>
然后在点击按钮后跳转到后台Controller的方法中查询数据并返回到前端
来到后台Controller
@RequestMapping("/wmsReceiveOrder.html")public String page(Model model) {Map<String,Object> param=new HashMap<String,Object>();param.put("code_type","receiveOrderStatus");List<SysCode> codeList=codeMapper.selectByMap(param);model.addAttribute("codeList",codeList);return "receiveOrder/wmsReceiveOrder.html";}其中selectByMap(param)是代码生成器自动生成的方法,会去数据库查找
code_type为receiveOrderStatus的数据并返回一个List。
然后将List传到前端进行显示。
总结
以上是生活随笔为你收集整理的SpringBoot中使用thymeleaf模板时select下拉框怎样查询数据库赋值的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Jquery中使用ajax传json参数
- 下一篇: SpringBoot中使用fastjso