码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-09-07 00:44:50      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:map   public   hash   aaa   tostring   name   com   mat   weight   

<%@ 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 +
‘}‘;
}
}
 

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

标签:map   public   hash   aaa   tostring   name   com   mat   weight   

原文地址:https://www.cnblogs.com/newcityboy/p/11478756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!