服务端到客户端
因为我们在spring-MVC.xml文件里配置了如下代码:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"/>
所以control里返回页面,Controller中方法返回String,String对应的是view的位置,如果需要携带数据通过model(相当于一个Map)传递到view,view中使用jstl的EL表达式来绑定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>