freemaker 里面 读取对象中封装的List<String>集合报错,应该怎么读取循环读取List<String> 30
在用freemaker 读取时候报错
<#list _question.getQuestionoptions() as opt></#list>
Expression _question.getQuestionoptions() is undefined
<#list _question.questionoptions as opt></#list>
用_question.questionoptions也报同样的错。 展开
2018-07-09 · 国内最优秀java资源共享平台
User类
public class User {
private String userName;
private String passWord;
private int age;
(省略set和get方法)
}
2.controller
@Controller
public class UserList {
@RequestMapping("/userlist")
public String userList(Model model){
ArrayList<User> list = new ArrayList<User>();
User u1 = new User("张三1", "123", 21);
User u2 = new User("张三2", "旅旦123", 22);
User u3 = new User("张三3", "123", 24);
User u4 = new User("张三4", "123", 23);
list.add(u1);
list.add(u2);
list.add(u3);
list.add(u4);
model.addAttribute("list",list);
return "userList";
}
}
3. userlist.ftl
<#--Freemarker遍历list-->
<#list userList as user>
用户名:${user.userName}
密 正衡 码:举镇做${user.userPassword}
年 龄: ${user.age}
</#list>
4. 效果