Programming Language/Javascript, ...

[EL] EL 연산

Ma_Sand 2022. 6. 7. 21:40
반응형

servlet

request.setAttribute("big", 10);
request.setAttribute("small", 3);
		
request.setAttribute("sOne", "방가");
request.setAttribute("sTwo", new String("방가"));
		
request.setAttribute("pOne", new Person("장조림", 29, "남자"));
request.setAttribute("pTwo", null);
		
ArrayList<String> list1 = new ArrayList<>();
request.setAttribute("lOne", list1);
		
ArrayList<String> list2 = new ArrayList<>();
list2.add("리스트");
request.setAttribute("lTwo", list2);

 

 

1. 산술 연산

 1) 기존 방식

10+3=<%=(int)request.getAttribute("big") + (int)request.getAttribute("small")%>

 

 2) EL 연산

10 + 3 = ${big + small }
10 - 3 = ${big - small }
10 * 3 = ${big * small }
10 / 3 = ${big / small } 또는 ${big div small }
10 % 3 = ${big % small } 또는 ${big mod small }

 

 

 

2. 숫자 간 대소 비교 연산

 1) 기존 방식

10>3 : <%=(int)request.getAttribute("big") > (int)request.getAttribute("small") %>

 

 2) EL 연산

10 > 3 : ${big gt small }
10 < 3 : ${big lt small }
10 >= 3 : ${big ge small }
10 <= 3 : ${big le small }

 

 

 

3. 동등 비교 연산

 1) 기존 방식

10과 3이 일치하는가? : 
<%=(int)request.getAttribute("big") == (int)request.getAttribute("small") %>
sOne과 sTwo가 일치하는가? : 
<%=request.getAttribute("sOne").equals(request.getAttribute("sTwo")) %>

 

 2) EL 연산

10과 3이 일치하는가? : ${big eq small }
big에 담긴 값이 10과 일치하는가? : ${big eq 10 }

sOne과 sTwo가 일치하는가? : ${sOne eq sTwo }
sOne과 sTwo가 불일치한가? : ${sOne ne sTwo }
		
sOne에 담긴 값이 "방가"와 일치하는가? : ${sOne eq "방가" }

 

 

 

4. 객체가 null인지, 리스트가 비어있는지 확인하는 연산

pTwo가 null인가? : ${pTwo == null } 또는 ${empty pTwo }
pOne이 null인가? : ${pOne == null } 또는 ${empty pOne }
pOne이 null이 아닌가? : ${pOne != null } 또는 ${!empty pOne }
		
lOne이 비어있는가? : ${empty lOne }
lTwo가 비어있는가? : ${empty lTwo }

 

 

 

5. 논리 연산자

AND 연산 : ${true && true } 또는 ${true and true }
OR 연산 : ${true || false } 또는 ${true or false }

반응형