spring获取数组参数(二)

来源:互联网 发布:淘宝 3d试衣 编辑:程序博客网 时间:2024/05/17 04:50

虽然标题是写的数组,其实这里例子是以List来写的,但其实和数组是一样的,只不过之前做测试的时候用的list就不想改了

首先需要一个类来封装

这里以钥匙和锁为例(一把锁对应多把钥匙)

TBLLock.java

public class TBLLock implements Serializable {private static final long serialVersionUID = 1L;private int lockId;private String lockName;private List<TBLKey> keys;public int getLockId() {return lockId;}public void setLockId(int lockId) {this.lockId = lockId;}public String getLockName() {return lockName;}public void setLockName(String lockName) {this.lockName = lockName;}public List<TBLKey> getKeys() {return keys;}public void setKeys(List<TBLKey> keys) {this.keys = keys;}}
TBLKey.java

public class TBLKey implements Serializable {private static final long serialVersionUID = 1L;private int keyId;private String keyName;private TBLLock lock;public int getKeyId() {return keyId;}public void setKeyId(int keyId) {this.keyId = keyId;}public String getKeyName() {return keyName;}public void setKeyName(String keyName) {this.keyName = keyName;}public TBLLock getLock() {return lock;}public void setLock(TBLLock lock) {this.lock = lock;}}

LockController.java

@Controller@RequestMapping("/lock/*")public class LockController {    @RequestMapping("/getLock")public String getKeyList(TBLLock lock,Model model){List<TBLKey> list = lock.getKeys();} }

前台MyTest.jsp(name直接写属性就可以了)

 <form action="/MyTest/lock/getLock" method="post">       <table align="center" border="1" id="param">                     <tr>           <td>LockName:</td>           <td><input type="text" name="lockName"></td>         </tr>         <tr>           <td>keyName1:</td>           <td><input type="text" name="keys[0].keyName"></td>          </tr>          <tr>           <td>keyName2:</td>           <td><input type="text" name="keys[1].keyName"></td>          </tr>         <tr>            <td><input type="submit" value="表单提交"></td>            <td><input type="reset"></td>        </tr>    </table> </form>


0 0
原创粉丝点击