spring MVC 前台后台数据交互(一)

服务端到客户端

因为我们在spring-MVC.xml文件里配置了如下代码:

<bean id="viewResolver"
	  class="org.springframework.web.servlet.view.InternalResourceViewResolver"
	  p:prefix="/WEB-INF/jsp/"
	  p:suffix=".jsp"/>

所以control里返回页面,Controller中方法返回StringString对应的是view的位置,如果需要携带数据通过model(相当于一个Map)传递到view,view中使用jstlEL表达式来绑定model带来的数据。

control代码:

/**
	 * 申请成为讲师页面
	 * @return
	 * @throws NamingException
	 */
	@RequestMapping("/applyToTeacherPage")
	public String applyToTeacherPage(Model model) throws NamingException {
		String userId = "Euo34x6HfxNq2tVaPLhZ2V";
		Student student = studentBean.findEntityByIdGeneric(userId, dataBaseName);
		model.addAttribute(student);
		
		//所以省信息
		List<Province> provinces = new ArrayList<Province>();
		provinces = studentBean.queryProvince(dataBaseName);
		model.addAttribute("provinces", provinces);

		//查询所有领域
		List<Field> fields = new ArrayList<>();
		fields = studentBean.queryOneField(dataBaseName);
		model.addAttribute("oneLevelFields", fields);
		
		//查询所有行业
		List<Industry> industrys = new ArrayList<>();
		industrys = studentBean.queryIndustry(dataBaseName);
		model.addAttribute("industrys", industrys);

		return "/applyToTeacher";
	}

jsp代码:

<span style="white-space:pre">		</span><div class="row" style="margin-top: 10px">
						<div class="col-xs-3" style="text-align:right;">擅长领域</div>
						<div class="col-xs-9">
							<div class="col-xs-8" style="padding: 0">
								<div class="form-group">
<!-- 		                            <input id="field" type="text" name="field" class="form-control" /> -->
									<div class="col-xs-5">
									<select id="oneLevelFields" name="oneLevelFields" οnchange="changeOneLevelField()"class="form-control">
										<option value="0" selected="selected">请选择</option> 
										<c:forEach items="${oneLevelFields }" var="oneLevelField">
												<option value="${oneLevelField.id }">${oneLevelField.fieldName }</option>		
										</c:forEach>
									</select>
									</div>
									<div class="col-xs-5">
									<select id="twoLevelFields" name="twoLevelFields"  class="combobox form-control" >
										<option value="0" selected="selected">请选择</option> 
									</select>
									</div>
									<div class="col-xs-2">
									<font style="color:red">*</font><label id="errorOneLevelField"  style="color:red"></label>
									<img οnclick="" src="Images/addField.png" style="padding-top: 20px" />
									</div>
		                        </div>                        
							</div>
							<div id="goodFields" class="col-xs-4" style="padding: 0">
		                       	
<!-- 		                       	<label id="fieldsName" name="fieldsName"></label> -->
		                    </div>
		                    <input id="fields" name="fields" type="hidden">					
						</div>
					</div>
					<div class="row" style="margin-top: 10px">
				<div class="col-xs-3" style="text-align:right;">擅长行业</div>
				<div class="col-xs-9">
					<div class="col-xs-5" style="padding: 0">
						<div class="form-group">
<!--                             <input id="industry" class="btn btn-primary" type="button" name="industry" class="form-control" /> -->
							<select id="industrys" name="industrys" οnchange="addIndustry()" class="combobox form-control" >
								<option value="0" selected="selected">请选择</option> 
								<c:forEach items="${industrys }" var="industry">
									<option value="${industry.id }">${industry.industryName }</option>		
								</c:forEach>
							</select>
							<font style="color:red">*</font><label id="errorIndustrys"  style="color:red"></label>
							<div id="goodIndustrys"></div>
							
                        </div>                        
					</div>
					<input id="goodIndustrysIds" name="goodIndustrysIds" type="hidden">
				</div>
			</div>
				</div>
				<div class="col-xs-4" >
					<img src="Images/123.bmp" style="padding-top: 20px" />
				</div>
			</div>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值