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

[烧脑时刻]EL表达式1分钟完事

时间:2017-03-22 21:13:38      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:开始   pack   date   style   color   表达式   快速   type   bean   

  1. 一天,程序员A问我,我们比比谁的知识点多,反应快。我回答:那就看谁最快用EL表达式的显示在页面上吧。
  2. 话不多说,计时开始。
  3. 技术分享
  4. 项目的结构如上,大概就是一个Family的JavaBean,一个jsp页面,再加上Tomcat的包
  5. Family.java
  6.  1 package com.chan.basic.domain;
     2 
     3 /**
     4  * Created by Chan on 2017/3/21.
     5  */
     6 public class Family {
     7     private String wife;
     8     private String cat;
     9     private String children;
    10     private String dog;
    11 
    12     public String getWife() {
    13         return wife;
    14     }
    15 
    16     public void setWife(String wife) {
    17         this.wife = wife;
    18     }
    19 
    20     public String getCat() {
    21         return cat;
    22     }
    23 
    24     public void setCat(String cat) {
    25         this.cat = cat;
    26     }
    27 
    28     public String getChildren() {
    29         return children;
    30     }
    31 
    32     public void setChildren(String children) {
    33         this.children = children;
    34     }
    35 
    36     public String getDog() {
    37         return dog;
    38     }
    39 
    40     public void setDog(String dog) {
    41         this.dog = dog;
    42     }
    43 }
  7. 值得一提的是IDEA,快速getter和setter的快捷键是Alt + Insert .
  8. index.jsp
  9.  1 <%@ page import="com.chan.basic.domain.Family" %>
     2 <%--
     3   Created by IntelliJ IDEA.
     4   User: Administrator
     5   Date: 2017/3/22
     6   Time: 17:49
     7   To change this template use File | Settings | File Templates.
     8 --%>
     9 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    10 <html>
    11 <head>
    12     <title></title>
    13 </head>
    14 <body>
    15 <%
    16     //NEW
    17     Family me =new Family();
    18     //SET
    19     me.setDog("Tom");
    20     me.setWife("Jack");
    21     me.setChildren("James");
    22     me.setCat("Tomcat");
    23     //REQUEST
    24     request.setAttribute("myFamily",me);
    25 %>
    26 <h1>使用EL表达式,秒杀你</h1>
    27 <%--request应为requestScope--%>
    28 ${requestScope.myFamily.cat}
    29 </body>
    30 </html>

     

  10. 技术分享
  11. 然后再运行Tomcat,比程序员A快了几秒,哈哈哈哈。技术分享

[烧脑时刻]EL表达式1分钟完事

标签:开始   pack   date   style   color   表达式   快速   type   bean   

原文地址:http://www.cnblogs.com/chanchifeng/p/6601716.html

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