詳解SpringBoot中Controller接收對(duì)象列表實(shí)現(xiàn)
如果Spring Boot中對(duì)應(yīng)的Controller要接收一個(gè)對(duì)象,該對(duì)象中又存放了一個(gè)List列表,那么頁(yè)面該如何傳遞相關(guān)應(yīng)的參數(shù)信息呢。
本篇文章給大家一個(gè)簡(jiǎn)單的示例,提供一種實(shí)現(xiàn)方式。
實(shí)體類
首先看實(shí)體類的結(jié)構(gòu)(注意使用了Lombok):
@Data public class Rules { private List<Rule> rules; }
對(duì)應(yīng)Rule實(shí)體類代碼如下:
@Data public class Rule { /** * 類名 */ private String className; /** * 字段名稱 */ private String column; /** * 操作符 */ private String operate; /** * 對(duì)應(yīng)值 */ private String value; }
對(duì)應(yīng)Controller方法
@Controller public class ManagerRulesController { @PostMapping("/rules/add") public String addDrl(Rules rules) { if (rules != null) { List<Rule> ruleList = rules.getRules(); for (Rule rule : ruleList) { // 具體業(yè)務(wù)處理 } return "result"; } }
對(duì)應(yīng)頁(yè)面呈現(xiàn)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>規(guī)則頁(yè)面管理頁(yè)面</title> <link rel="stylesheet" rel="external nofollow" /> </head> <body class="container"> <h4>頁(yè)面拼接模式</h4> <form method="post" action="/rules/add"> <#--第一條條件--> <div id="condition-0"> <div class="form-group"> <label>金額:</label> <input type="hidden" name="rules[0].column" value="amount"> 操作屬性操作: <select class="form-control" name="rules[0].operate"> <option value=">">大于</option> <option value="<">小于</option> </select> 屬性值: <input type="text" class="form-control" name="rules[0].value" placeholder="輸入值" value="1"> </div> </div> <div id="condition-1"> <div class="form-group"> <label>金額:</label> <input type="hidden" name="rules[1].column" value="amount"> 操作屬性操作: <select class="form-control" name="rules[1].operate"> <option value="<">小于</option> <option value=">">大于</option> </select> 屬性值: <input type="text" class="form-control" name="rules[1].value" placeholder="輸入值" value="100"> </div> </div> <button type="submit" class="btn btn btn-info">提交</button> </form> </body> </html>
注意要提交的頁(yè)面元素的name值為“rules[1].column”。通過這種形式來指定列表中的第幾個(gè)元素的具體屬性值是什么。
到此這篇關(guān)于詳解SpringBoot中Controller接收對(duì)象列表實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)SpringBoot中Controller接收對(duì)象列表內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- SpringBoot Controller接收參數(shù)的幾種常用方式
- SpringBoot在Controller層接收參數(shù)的n種姿勢(shì)(超詳細(xì))
- SpringBoot開發(fā)詳解之Controller接收參數(shù)及參數(shù)校驗(yàn)
- SpringBoot實(shí)現(xiàn)前后端、json數(shù)據(jù)交互以及Controller接收參數(shù)的幾種常用方式
- java springboot poi 從controller 接收不同類型excel 文件處理
- 詳解SpringBoot Controller接收參數(shù)的幾種常用方式
- SpringBoot項(xiàng)目中Controller接收兩個(gè)實(shí)體的實(shí)現(xiàn)方法
相關(guān)文章
Java調(diào)用計(jì)算機(jī)攝像頭拍照實(shí)現(xiàn)過程解析
這篇文章主要介紹了Java調(diào)用計(jì)算機(jī)攝像頭拍照實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05Mybatis+Druid+MybatisPlus多數(shù)據(jù)源配置方法
在項(xiàng)目開發(fā)中,經(jīng)常需要連接多個(gè)數(shù)據(jù)庫(kù),使用Mybatis、Druid和MybatisPlus可以實(shí)現(xiàn)多數(shù)據(jù)源配置,通過定義配置類和修改配置文件,如properties或yaml,可以設(shè)置多個(gè)數(shù)據(jù)源,本文介紹了配置項(xiàng)包括Druid基本配置、數(shù)據(jù)源一、數(shù)據(jù)源二,感興趣的朋友一起看看吧2024-09-09SpringBoot基于Redis實(shí)現(xiàn)短信登錄的操作
驗(yàn)證碼登錄是非常常見的一種登錄方式,能夠簡(jiǎn)化用戶登錄的過程,本文主要介紹了SpringBoot基于Redis實(shí)現(xiàn)短信登錄的操作,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12基于application和bootstrap的加載順序及區(qū)別說明
這篇文章主要介紹了application和bootstrap的加載順序及區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07基于JSON和java對(duì)象的互轉(zhuǎn)方法
下面小編就為大家?guī)硪黄贘SON和java對(duì)象的互轉(zhuǎn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09