如何利用EL表达式获取list,map,对象等值

mac2022-06-30  73

<%@ page import="com.hopetesting.domain.User" %><%@ page import="java.util.*" %><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>el表达式获取对象属性</title></head><body><h1>el设置对象是属性</h1><% User user = new User(); user.setName("zmy"); user.setAge(11); user.setBirthday(new Date()); request.setAttribute("user", user); List list = new ArrayList(); list.add("aaa"); list.add("bbb"); list.add(user); request.setAttribute("list",list); Map map = new HashMap(); map.put("sname","light"); map.put("gender","male"); map.put("user",user); request.setAttribute("map",map);%><h1>el获取对象属性</h1> ${requestScope.user}<br/> ${requestScope.user.name}<br/> ${user.age}<br/> ${user.birStr}<h1>el获取list值</h1>${list[0]}<br/>${list[1]}<br/>${list[10]}<br/>${list[2].name}<br/><h1>el获取Map值</h1>${map.sname}<br/>${map.gender}<br/>${map.user.birStr}<br/></body></html> package com.hopetesting.domain;import java.text.SimpleDateFormat;import java.util.Date;/** * @author newcityman * @date 2019/9/6 - 21:00 */public class User {private String name; private Integer age; private Date birthday; public User() { }public User(String name, Integer age, Date birthday) {this.name = name; this.age = age; this.birthday = birthday; }public String getName() {return name; }public Integer getAge() {return age; }public Date getBirthday() {return birthday; }public String getBirStr(){if(birthday!=null){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(birthday); }else{return ""; } }public void setName(String name) {this.name = name; }public void setAge(Integer age) {this.age = age; }public void setBirthday(Date birthday) {this.birthday = birthday; }@Override public String toString() {return "User{" +"name='" + name + '\'' +", age=" + age +", birthday=" + birthday +'}'; }}  

转载于:https://www.cnblogs.com/newcityboy/p/11478756.html

最新回复(0)