1. @ExcelField :关于excel表格的导入导出的工具类(java的excel) 需要excel表格导出的属性。
@Length(min = 0, max = 100, message = "奖项名称长度必须介于 0 和 100 之间")
@ExcelField(title = "奖项名称", align = 1, sort = 5)
public String getPrizeName() { return prizeName; }
2. @ ModelAttribute 绑定请求参数到指定对象
public String test1(@ModelAttribute("user") UserModel user)
只是此处多了一个注解@ModelAttribute("user"),它的作用是将该绑定的命令对象
以“user”为名称添加到模型对象中供视图页面展示使用。我们此时可以在视图页面使用${user.username}来获取绑定的命令对象的属性。
@RequestMapping(value="/model2/{username}")
public String test2(@ModelAttribute("model") DataBinderTestModel model)
URI 模板变量也能自动绑定到命令对象中, 当你请求的URL 中包含“bool=yes&schooInfo.specialty=computer&hobbyList[0]=program&hobbyList[1]=music&map[key1]=value1&map[key2]=value2&state=blocked”会自动绑定到命令对象上。当URI模板变量和请求参数同名时,URI模板变量具有高优先权。
二、暴露表单引用对象为模型数据
/**
* 设置这个注解之后可以直接在前端页面使用hb这个对象(List)集合
* @return
*/
@ModelAttribute("hb")
public List<String> hobbiesList(){
List<String> hobbise = new LinkedList<String>();
hobbise.add("basketball");
hobbise.add("football");
hobbise.add("tennis");
return hobbise;
}
JSP页面展示出来
<br>
初始化的数据 : ${hb }
<br>
<c:forEach items="${hb}" var="hobby" varStatus="vs">
<c:choose>
<c:when test="${hobby == 'basketball'}">
篮球<input type="checkbox" name="hobbies" value="basketball">
</c:when>
<c:when test="${hobby == 'football'}">
足球<input type="checkbox" name="hobbies" value="football">
</c:when>
<c:when test="${hobby == 'tennis'}">
网球<input type="checkbox" name="hobbies" value="tennis">
</c:when>
</c:choose>
</c:forEach>
备注:
1、通过上面这种方式可以显示出一个集合的内容
2、上面的jsp代码使用的是JSTL,需要导入JSTL相关的jar包
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
三、暴露@RequestMapping方法返回值为模型数据
public @ModelAttribute("user2") UserModel test3(@ModelAttribute("user2") UserModel user)