SpringBoot 3일차에유

jyp·2023년 3월 24일
0

학원

목록 보기
51/57

SitemeshApplication.java

@SpringBootApplication
public class Sitemesh1Application {

// 메인 함수가 실행될때 모든 함수가 실행됨

    public static void main(String[] args) {
        SpringApplication.run(Sitemesh1Application.class, args);
    }

    @Bean
    public FilterRegistrationBean<SitemeshConfig> sitemeshbean()
    {
        FilterRegistrationBean<SitemeshConfig> bean = new FilterRegistrationBean<SitemeshConfig>();
        bean.setFilter(new SitemeshConfig());

        return bean;
    }

}
    
    

SitemeshConfig.java

public class SitemeshConfig extends ConfigurableSiteMeshFilter {

  @Override
  protected void applyCustomConfiguration(SiteMeshFilterBuilder builder)
  {
      // 설정관련내용 >> default.jsp , exclude

                          //   모든파일,     해당 파일의 경로
      builder.addDecoratorPath("/*", "/views/common/default.jsp"); // DecoratorPath는 jsp 관련
      builder.addDecoratorPath("/login/*", "/views/common/default2.jsp");
      
      decorator 제외시키기
      					  //  제외시킬파일명
      builder.addExcludedPath("/login/my");
      or
      builder.addExcludedPath("/login/my*"); << 해당 문서 뒤에 값이 있다면 제외되는거임
      
      예) ???/login/my?test=1 >> 이런식으로 뒤에 파람값으로 붙여줬기 때문에 decorator 제외가 되는거
  }
}

default.jsp

사용하는 코드가 달라졌음

<sitemesh:write property="head"/>
</head>
<body>
    여기는 메뉴임둥.
    <hr>
    <sitemesh:write property="body"/> << 해당부분 아래가 body가 되는거임
    <hr>
    여기는 bottom임둥.
</body>

타임리프 반복문 코드

<table width="800" align="center">
	<tr>
		<td> 제 목 </td>
		<td> 작성자 </td>
		<td> 조회수 </td>
		<td> 작성일 </td>
	</tr>
	
              기존var , 기존items
	<tr th:each="bvo:${list}">
		<td th:text="${bvo.title}"> </td> << 값을 태그 안에 직접 넣어되고 태그를 적어서 안에 넣어줘도 됨
		<td th:text="${bvo.name}"> </td>
		<td th:text="${bvo.readnum}"> </td>
		<td th:text="${bvo.writeday}"> </td>
	</tr>
	
</table>

each문 사용 시작값과 끝을 이용해서 반복시키기

<th:block th:each="i:${#numbers.sequence(1,10,2)}">
	<div th:text="${i+'하하하'}"> </div>
</th:block>

타임리프는 거꾸로도 출력된다.
<th:block th:each="i:${#numbers.sequence(10,1)}">
	<div th:text="${i+'하하하'}"> </div>
</th:block>

each문에서 index값 구하기

<th:block th:each="str,cnt:${list}">
	<span th:text="${cnt.index}"></span>
	<span th:text="${str}"></span>
</th:block>

타임리프 if문

model.addAttribute("chk",1); << 값 보내줄때 String인지 int인지 따짐
model.addAttribute("num",1);

<th:block th:if="${chk=='1'}">
	<div> 합격임둥 </div>
</th:block>

<th:block th:if="${chk=='2'}">
	<div> 불합격임둥 </div>
</th:block>

<th:block th:if="${num==1}">
	<div> 합격임둥 </div>
</th:block>

<th:block th:if="${num==2}">
	<div> 불합격임둥 </div>
</th:block>

타임리프 switch문

<th:block th:switch="${sel}">
	<div th:case="1"> 광어초밥임둥 </div>
	<div th:case="2"> 연어초밥임둥 </div>
	<div th:case="3"> 학수고대초밥임둥 </div>
	<div th:case="4"> 병에담긴초밥임둥 </div>
	<div th:case="*"> 어우동초밥임둥 </div>
</th:block>
profile
국비 코딩

0개의 댓글