모든 개발자를 위한 HTTP 웹 기본 지식
수강 중/resources/static/css
폴더 아래에 새로운 css 파일 추가했다.normalize.css
를 다운로드했다.style.css
를 생성했다.main.css
에 작성하였다..main-container section ul li a .img-wrap {
width: 100%;
margin-bottom: 1em;
overflow: hidden;
}
.main-container section ul li a .img-wrap img {
width: 100%;
height: 100%;
transition: all 0.3s;
}
.main-container section ul li a .img-wrap img:hover {
transform: scale(1.1);
}
<!-- 로컬 파일 그대로 크롬에서 볼 때 -->
<!-- <link rel="stylesheet" href="../../static/css/normalize.css">
<link rel="stylesheet" href="../../static/css/style.css">
<link rel="stylesheet" href="../../static/css/main.css"> -->
<!-- 이클립스에서 서버 구동해서 사이트에서 볼 때 -->
<link rel="stylesheet" th:href="@{/css/normalize.css}">
<link rel="stylesheet" th:href="@{/css/style.css}">
<link rel="stylesheet" th:href="@{/css/main.css}">
th:if, th:unless
를 사용하여 결과리스트 길이가 0이면 (결과 없으면) "등록된 게시물이 없습니다" 텍스트 보이기<p th:if="${postList.size==0}" class="no-resultList" >등록된 게시물이 없습니다.</p>
<ul th:unless="${postList.size==0}" class="list-wrap">...</ul>
// JpaPostRepository.java
@Override
public List<Post> findAllFromHome(Long homeId) {
return em.createQuery("select p from Post p where p.homeId = :homeId order by updatedAt desc", Post.class)
.setParameter("homeId", homeId)
.getResultList();
}
form객체
로 받고, 그걸 다시 post객체
로 받는 과정이 꼭 필요한가 의문이 들었음// PostController
// 기존 form 객체 사용
public String createPost(@PathVariable("homeId")Long homeId, PostForm form) {
Post post = new Post();
post.setHomeId(homeId);
post.setAuthorId(form.getAuthorId());
post.setContent(form.getContent());
postService.createPost(post);
return "redirect:/homes?homeId=" + homeId;
}
// post 객체 사용
public String createPost(@PathVariable("homeId")Long homeId, Post post) {
post.setHomeId(homeId);
postService.createPost(post);
return "redirect:/homes?homeId=" + homeId;
}