Ch 7. Spring EL (Spring Framework 3.0 M3) 백기선

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

The ArrayList Class and the enum Keyword
ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Strings in Java 1. strings in java are handled by two classes String &
Lecture # 21 Chapter 6 Uptill 6.4. Type System A type system is a collection of rules for assigning type expressions to the various parts of the program.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
Cmput Lecture 8 Department of Computing Science University of Alberta ©Duane Szafron 2000 Revised 1/26/00 The Java Memory Model.
1 Java Object Model Part 1. 2 Type Definition: set of values – a set of values and set of operations –a set of operations that can be applied to those.
Transformation of Java Card into Diet Java Semester Project Presentation Erich Laube.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
March 2005Java Programming1. March 2005Java Programming2 Why Java? Platform independence Object Oriented design Run-time checks (fewer bugs) Exception.
AAAARCH Research Group A grammar for Policies in a generic AAA Environment.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
MIT AITI 2003 Lecture 7 Class and Object - Part I.
Getting Started Example ICS2O curriculum
Lecture 3. 2 Introduction Java is a true OO language -the underlying structure of all Java programs is classes. Everything must be encapsulated in a class.
프로그래밍 기초와 실습 Chapter 7 Enumeration Types and typedef.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Chapter 06 데이터베이스 연동 지원 작성자 : 장은호 소속팀 : 네이버메인개발 작성년월일 :
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 C++
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
Objects.  Java Script is an OOP Language  So it allows you to make your own objects and make your own variable types  I will not be going over how.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Keith Elder Microsoft MVP
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
1/43 고급자바프로그래밍 (ADVANCED JAVA PROGRAMMING) 강원대학교 컴퓨터학부 2012 년 가을학기 담당교수 정충교 1.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
SE-1010 Dr. Mark L. Hornick 1 Java Programming Basics.
Types in programming languages1 What are types, and why do we need them?
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Exercise 2 Introduction to C# CIS Create a class called Employee that contains the following private instance variables: Social Securitystring.
Lab 1 Logbook ADT. OVERVIEW A monthly logbook consists of a set of entries, one for each day of the month.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
영상 획득 영상 저장 카메라 파라메터 커스텀 이미지
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
PHP5 STUDY # SPARCS 구성모. 공부하기전에  Xming  Xlaunch  Windows 용 Xserver 프리웨어.
Windows Programming(3)_OOP 1 Object Oriented Programming  Object & Class  Instance & Static  Fields  Constructor  Methods  Inheritance  is & as.
방명록 제작. 목차  기본 레이아웃  DB 구조  방명록 구조  코드 설명  화면 설명.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
아주대학교 LifecareScienceLAB Android Seminar 2 nd class Android Software Development 2011/04/13 – p.m. 06:00 – 팔달관 409 호 아주대학교.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Java Programming Language (3) - Input/Output Stream –
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CS520 Web Programming Spring – Inversion of Control
Primitive Types Vs. Reference Types, Strings, Enumerations
MSIS 655 Advanced Business Applications Programming
Principles of Computer Programming (using Java) Chapter 2, Part 1
An Introduction to Java – Part I, language basics
An overview of Java, Data types and variables
String Methods: length substring
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Recap Week 2 and 3.
Names of variables, functions, classes
Java: Variables, Input and Arrays
Presentation transcript:

Ch 7. Spring EL (Spring Framework 3.0 M3) 백기선

목차 1. 도입 2. 기능 개요 3.Expression 인터페이스 4. 빈 정의할 때 EL 사용하기 5.EL 레퍼런스 6. 예제에서 사용한 클래스

1. 도입

SpEL The Spring Expression Language (SpEL for short) is a powerful expression language that supports querying and manipulating an object graph at runtime. 독립적으로 사용 가능. 스프링을 사용하면 쉽게 사용 가능.

Dependency org.springframework.expression

2. 기능 개요

다양한 기능 제공 Literal expressions: 상수 표현 Boolean and relational operators: 불린과 관계형 연산자 Regular expressions: 정규 표현식 Class expressions: 클래스 표현식 Accessing properties, arrays, lists, maps: 속성, 배열, 리스트, 맵에 접근하기 Method invocation: 메서드 호출 Relational operators: 관계형 연산자 Assignment: 대입 Calling constructors: 생성자 호출 Ternary operator: 3 항 연산자 Variables: 변수 User defined functions: 사용자 정의 함수 Collection projection: 콜렉션 보기 Collection selection: 콜렉션 선택 Templated expressions: 템플릿 표현식

3. Expression 인터페이스

Expression 인터페이스 ExpressionParser Expression parseExpression(String) CompositeStringExpression LiteralExpression SpelExpression

SpEL 은 ANTLR 을 사용하여 lexer 와 parser 를 구성한다. ExpressionParser 는 표현식을 파싱한다. Expression 은 표현식을 평가한다. 간단한 상수 표현식 ExpressionParser parser = new SpelAntlrExpressionParser(); Expression exp = parser.parseExpression("'Hello World'"); String message = (String) exp.getValue();

메서드 호출하기 String 클래스의 메서드 호출 ExpressionParser parser = new SpelAntlrExpressionParser(); Expression exp = parser.parseExpression("'Hello World'.concat('!')"); String message = (String) exp.getValue();

JavaBean 속성 호출하기 String.getBytes() 호출하기 ExpressionParser parser = new SpelAntlrExpressionParser(); Expression exp = parser.parseExpression("'Hello World'.bytes"); byte[] bytes = (byte[]) exp.getValue();

Nested dot(.) 연산자 사용하기 String.getBytes().length() ExpressionParser parser = new SpelAntlrExpressionParser(); Expression exp = parser.parseExpression("'Hello World'.bytes.length"); int length = (Integer) exp.getValue();

생성자 호출하기 new String() 호출 public T getValue(Class desiredResultType) ExpressionParser parser = new SpelAntlrExpressionParser(); Expression exp = parser.parseExpression("new String('hello world').toUpperCase()"); String message = exp.getValue(String.class);

특정 객체에 표현식 적용하기 Inventor(tesla) 의 name 속성에 할당 된 값을 가져오기 동일한 표현식을 여러 객체에 재사용 할 수 있다. // Create and set a calendar GregorianCalendar c = new GregorianCalendar(); c.set(1856, 7, 9); // The constructor arguments are name, birthday, and nationaltiy. Inventor tesla = new Inventor("Nikola Tesla", c.getTime(), "Serbian"); ExpressionParser parser = new SpelAntlrExpressionParser(); Expression exp = parser.parseExpression("name"); EvaluationContext context = new StandardEvaluationContext(); context.setRootObject(tesla); String name = (String) exp.getValue(context);

boolean 표현식 사용하기 이전 예제에 추가 코드. true 값을 갖는다. Expression exp = parser.parseExpression("name == 'Nikola Tesla'"); boolean result = exp.getValue(context, Boolean.class);

EvaluationContext 인터페이스 Expression EvaluationContext getValue StandardEvaluationContext

StandardEvaluationContext 특징 현재 스프링이 제공하는 유일한 EvaluationContext 인터페이스 구현체 Reflaction 을 사용한다. Method, Field, Constructor 인스턴스 캐싱 표현식 적용할 루트 객체 설정 가능. 변수와 함수 설정 가능. 커스텀 메서드 / 생성자 / 속성 리졸버 등록 가능.

타입 변환 Generic 정보를 참조하여 콜렉션에 들어가는 타입으로 변환해 준다. class Simple { public List booleanList = new ArrayList (); } Simple simple = new Simple(); simple.booleanList.add(true); StandardEvaluationContext simpleContext = new StandardEvaluationContext(simple); parser.parseExpression("booleanList[0]").setValue(simpleContext, "false"); Boolean b = simple.booleanList.get(0);

4. 빈 정의할 때 EL 사용하기

#{ 표현식 } in XML

systemProperties 사용하기

다른 빈의 속성 참조하기

@Value 애노테이션 사용하기 public static class systemProperties['user.region'] }") private String defaultLocale; public void setDefaultLocale(String defaultLocale) { this.defaultLocale = defaultLocale; } public String getDefaultLocale() { return this.defaultLocale; } 기본 값 설정하기

앞선 예제와 동일 public static class PropertyValueTestBean private String systemProperties['user.region'] }") public void setDefaultLocale(String defaultLocale) { this.defaultLocale = defaultLocale; } public String getDefaultLocale() { return this.defaultLocale; } 이번엔 세터에 설정

@Autowired 메서드에 사용하기 public class MovieRecommender { private String defaultLocale; private CustomerPreferenceDao public MovieRecommender(CustomerPreferenceDao systemProperties['user.country'] } String defaultLocale) { this.customerPreferenceDao = customerPreferenceDao; this.defaultLocale = defaultLocale; } //... }

5. EL 레퍼런스

6. 예제 코드

끝!끝!