블로그

4월9일 spring,jsp 수업 내용 본문

개발자 준비과정/Spring, SpringBoot, JSP

4월9일 spring,jsp 수업 내용

하늘바람a 2024. 4. 9. 19:39

1. ${ } attribute

  • attribute의 타입 중에 자주 사용하는 타입
    • String
    • 기본타입(Wrapper)
    • 배열
    • List
    • Map
    • JavaBeans

위의 타입들을 섞어서 사용. spring과 jsp로 작성

${myList.key1[1]} = ${myList["key1"][1]}

 

 

2. ${ } requestScope

 

${3} //3 출력. attribute의 값이 출력되지 않음.
${삼} //에러
-> ${requestScope["3"]} // 3의 attribute 값 출력됨.
주의) ${requestScope[3]} 은 에러

 


3. jstl : jsp standard tag library

  • jsp의 커스텀 태그 라이브러리 모음
  • EL(Expression Language)를 사용하여 표현
  • html태그(<>) 형태로 직관적인 코딩을 지원하는 라이브러리


3-1. ${ } 안에 쓸 수 있는 연산자

  • 간단한 연산 사용 가능
  • 산술연산, 논리연산, 비교연산, 삼항연산 가능. empty 가능
${5+3} //8 ${"5"+"3"} //8출력. 자바와 다름
${num1} + ${num2} = ${num1+num2} // num1이 문자, num2가 숫자일 때 
// 문자와 숫자가 섞여있어도 숫자로 출력


3-2. ${ } if 태그

<%@ taglib prefix="c" uri="jakarta.tags.core"%> //  태그 선언

 

<c:if test="${age > 20 } var="result">성인</c:if>
<c:if test="${not result}>미성년자</c:if>

 

  • else 역할을 하는 기능은 없음.
  • 그러므로 해당 조건문을 var라는 곳에 담는다.
    • 👉이는 page영역의 attribute에 들어감


3-3. choose when otherwise

  • 복합조건문 제어. 자바의 if-else와 유사한 구문
<c:choose>
   <c:when test="true"> true일 때 출력 </c:when>
   <c:when test="true"> 위 조건문이 true가 아니고 현재 조건문이true일 때 출력</c:when>
   <c:otherwise> when이 모두 true가 아닐 때 출력 </c:otherwise>
</c:choose>


3-4. forEach

  • 반복문 제어
  • forEach begin="" end=""
  • 항상 begin의 값 <=end의 값.
  • var에 저장 가능
<c:forEach begin="1" end="2"><p>2번 출력됨</p></c:forEach>
<c:forEach begin="1" end="9" var="num"><p>${dan} x ${num} = ${dan*num}</p></c:forEach> // 여기서 dan은 attribute의 값

 

//위의 jsp와 연결되는 spring 코드
@Controller
public class Controller12{ @RequestMapping("main12/sub3")
public void method(Model model){ model.addAttribute("dan",5);}}


4. emmet

  • html 코드 단축키
<%--div>p--%>
<div>
    <p></p>
</div>

<%--h1+p--%>
<h1></h1>
<p></p>

<%--p#elem2.note--%>
<p id="elem2" class="note"></p>

<%--p.note.error.special--%>
<p class="note error special"></p>

<%--p#para$*2--%>
<p id="para1"></p>
<p id="para2"></p>

<%--p{content}*3--%>
<p>content</p>
<p>content</p>
<p>content</p>

<%--p[title]--%>
<p title=""></p>
<%--p[title="some title"]--%>
<p title="some title"></p>
<%--a[href="https://daum.net"][target="_blank"]--%>
<a href="https://daum.net" target="_blank"></a>

<%--table>thead>tr>th*2>lorem1^^^tbody>tr>td*2>lorem1--%>
<table>
    <thead>
    <tr>
        <th>Lorem.</th>
        <th>Eaque?</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>Lorem.</td>
        <td>Sit.</td>
    </tr>
    </tbody>
    <tbody>
    <tr>
        <td>Lorem.</td>
        <td>Eveniet.</td>
    </tr>
    </tbody>
</table>
</body>
</html>

'개발자 준비과정 > Spring, SpringBoot, JSP' 카테고리의 다른 글

JDBC  (0) 2024.04.16
4월11일 수업내용 jstl, lombok, ModelAttribute  (0) 2024.04.11
4월8일 수업내용  (0) 2024.04.08
@RequestParam  (0) 2024.04.08
4월5일 스프링 수업 내용  (0) 2024.04.08