本文主要是介绍SpringMVC 多层嵌套的数据接收与展现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
业务需求与设计
一个媒体可以创建多条返点规则
返点规则 分为 阶梯返点 / 固定返点
阶梯返点 分为 返点下限 与 返点上限 以及 返点率
固定返点 分为 返点率
设计
返点规则 - 》 返点规则 JavaBean
返点明细 -》 返点明细 JavaBean
返点规则 下面有 返点明细(固定/阶梯)。
返点明细
package com.ybl.test.threetiercurd.bean;/*** Created by szh on 2017/11/28.*/
public class RebateTest {private String rebateFloor;private String rebateUpper;private String fixedUpper;public String getRebateFloor() {return rebateFloor;}public void setRebateFloor(String rebateFloor) {this.rebateFloor = rebateFloor;}public String getRebateUpper() {return rebateUpper;}public void setRebateUpper(String rebateUpper) {this.rebateUpper = rebateUpper;}public String getFixedUpper() {return fixedUpper;}public void setFixedUpper(String fixedUpper) {this.fixedUpper = fixedUpper;}
}
返点规则
package com.ybl.test.threetiercurd.bean;import java.util.List;/*** Created by szh on 2017/11/28.*/
public class RebateRuleTest {private String rebateRuleName;private Integer rebateRuleType;private List<RebateTest> rebateTestList;public Integer getRebateRuleType() {return rebateRuleType;}public void setRebateRuleType(Integer rebateRuleType) {this.rebateRuleType = rebateRuleType;}public String getRebateRuleName() {return rebateRuleName;}public void setRebateRuleName(String rebateRuleName) {this.rebateRuleName = rebateRuleName;}public List<RebateTest> getRebateTestList() {return rebateTestList;}public void setRebateTestList(List<RebateTest> rebateTestList) {this.rebateTestList = rebateTestList;}
}
媒体下的返点规则列表
package com.ybl.test.threetiercurd.bean;import java.util.List;/*** Created by szh on 2017/11/28.*/
public class ThreeTierVO {public String mediaName;List<RebateRuleTest> rebateRuleTestList;public String getMediaName() {return mediaName;}public void setMediaName(String mediaName) {this.mediaName = mediaName;}public List<RebateRuleTest> getRebateRuleTestList() {return rebateRuleTestList;}public void setRebateRuleTestList(List<RebateRuleTest> rebateRuleTestList) {this.rebateRuleTestList = rebateRuleTestList;}
}
前端Controller
package com.ybl.test.threetiercurd.controller;import com.ybl.test.threetiercurd.bean.RebateRuleTest;
import com.ybl.test.threetiercurd.bean.RebateTest;
import com.ybl.test.threetiercurd.bean.ThreeTierVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;import java.util.ArrayList;
import java.util.List;/*** Created by szh on 2017/11/28.*/
@RequestMapping("/threeTierContoller/*")
@Controller
public class ThreeTierContoller {@RequestMapping("show")public String showThreeTier(Model model){RebateTest rebateTest1 = new RebateTest();rebateTest1.setRebateFloor("下限 : 0");rebateTest1.setRebateUpper("上限 : 10");RebateTest rebateTest2 = new RebateTest();rebateTest2.setRebateFloor("下限 : 10");rebateTest2.setRebateUpper("上限 : 20");RebateTest rebateTest3 = new RebateTest();rebateTest3.setRebateFloor("下限 : 20");rebateTest3.setRebateUpper("上限 : 40");List<RebateTest> rebateTestList1 = new ArrayList<>();rebateTestList1.add(rebateTest1);rebateTestList1.add(rebateTest2);rebateTestList1.add(rebateTest3);RebateRuleTest rebateRuleTest1 = new RebateRuleTest();rebateRuleTest1.setRebateRuleName("测试返点规则1");rebateRuleTest1.setRebateRuleType(1);rebateRuleTest1.setRebateTestList(rebateTestList1);//------------------------------------------RebateTest rebateTest4 = new RebateTest();rebateTest4.setFixedUpper("固定阶梯 : 50");List<RebateTest> rebateTestList2 = new ArrayList<>();rebateTestList2.add(rebateTest4);RebateRuleTest rebateRuleTest2 = new RebateRuleTest();rebateRuleTest2.setRebateRuleName("测试返点规则2");rebateRuleTest2.setRebateRuleType(0);rebateRuleTest2.setRebateTestList(rebateTestList2);ThreeTierVO threeTierVO = new ThreeTierVO();threeTierVO.setMediaName("三层关系测试");List<RebateRuleTest> rebateRuleTestList = new ArrayList<>();rebateRuleTestList.add(rebateRuleTest1);rebateRuleTestList.add(rebateRuleTest2);threeTierVO.setRebateRuleTestList(rebateRuleTestList);model.addAttribute("threeTierVO",threeTierVO);return "jsp/test/threetiercurd/testThreeTier.jsp";}@RequestMapping("modify")public String modifyThreeTier(Model model, ThreeTierVO threeTierVO){model.addAttribute("threeTierVO",threeTierVO);for(int i=0; i<threeTierVO.getRebateRuleTestList().size(); i++){System.out.println("返点规则名字 : " + threeTierVO.getRebateRuleTestList().get(i).getRebateRuleName());System.out.println("返点条目数量 : " + threeTierVO.getRebateRuleTestList().get(i).getRebateTestList().size());}return "jsp/test/threetiercurd/testThreeTier.jsp";}
}
页面
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head><title>3层嵌套的增删查改例子</title><link rel="shortcut icon" href="${baseResourcePath}/images/favicon.ico"><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><meta http-equiv="Cache-Control" content="no-store"/><meta http-equiv="Pragma" content="no-cache"/><meta http-equiv="Expires" content="0"/><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name="viewport" content="initial-scale=1,maximum-scale=1"/><jsp:include page="/resource/jsp/common/resourceFile.jsp"/>
</head><body><form action="/threeTierContoller/modify" method="post"><label>媒体名称</label><input type="text" name="mediaName" value="${threeTierVO.mediaName}"/><br/><br/><br/><c:forEach items="${threeTierVO.rebateRuleTestList}" var="rebateRuleTest" varStatus="rebateRulestatus"><label>返点规则名称</label><input type="text" name="rebateRuleTestList[${rebateRulestatus.index}].rebateRuleName" value="${rebateRuleTest.rebateRuleName}"/><br/><!-- 固定返点 --><c:if test="${rebateRuleTest.rebateRuleType == 0 }"><label>固定返点表单</label><br/><input type="hidden" name="rebateRuleTestList[${rebateRulestatus.index}].rebateRuleType" value="0"/><c:forEach items="${rebateRuleTest.rebateTestList}" var="rebateTest2" varStatus="fixedRebateStatus"><label>固定返点</label><input type="text" name="rebateRuleTestList[${rebateRulestatus.index}].rebateTestList[${fixedRebateStatus.index}].fixedUpper" value="${rebateTest2.fixedUpper}" /></c:forEach><br/><br/><br/><br/><br/><br/></c:if><!-- 阶梯返点 --><c:if test="${rebateRuleTest.rebateRuleType == 1 }"><label>阶梯返点表单</label><br/><input type="hidden" name="rebateRuleTestList[${rebateRulestatus.index}].rebateRuleType" value="1"/><c:forEach items="${rebateRuleTest.rebateTestList}" var="rebateTest3" varStatus="stageRebateStatus"><label>阶梯返点<c:out value="${stageRebateStatus.index}"/></label><br/><label>阶梯下限</label><input type="text" name="rebateRuleTestList[${rebateRulestatus.index}].rebateTestList[${stageRebateStatus.index}].rebateFloor" value="${rebateTest3.rebateFloor}" /><label>阶梯上限</label><input type="text" name="rebateRuleTestList[${rebateRulestatus.index}].rebateTestList[${stageRebateStatus.index}].rebateUpper" value="${rebateTest3.rebateUpper}" /><br/></c:forEach><br/><br/><br/><br/><br/><br/></c:if></c:forEach><input type="submit" value="提交"></form>
</body>
</html>
效果:
这篇关于SpringMVC 多层嵌套的数据接收与展现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!