當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot中使用thymeleaf模板时select下拉框怎样查询数据库赋值
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot中使用thymeleaf模板时select下拉框怎样查询数据库赋值
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
場景
實現(xiàn)效果
數(shù)據(jù)庫中碼表設計
實現(xiàn)
thymeleaf頁面代碼
當前頁面為:
receiveOrder/wmsReceiveOrder.html
<div class="col-sm-2"><div class="form-group"><label class="col-form-label" for="result">狀態(tài)</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的方法中查詢數(shù)據(jù)并返回到前端
來到后臺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)是代碼生成器自動生成的方法,會去數(shù)據(jù)庫查找
code_type為receiveOrderStatus的數(shù)據(jù)并返回一個List。
然后將List傳到前端進行顯示。
?
總結
以上是生活随笔為你收集整理的SpringBoot中使用thymeleaf模板时select下拉框怎样查询数据库赋值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jquery中使用ajax传json参数
- 下一篇: SpringBoot中使用fastjso