728x90
각 부분에 값 가져오기
message.fileList[0].storedFilePath
'images/20220728/1365666336304400.png'
controller에서 배열로 보냄
@RequestMapping(value="/jpa/board", method=RequestMethod.GET)
public ModelAndView openBoardList() throws Exception {
ModelAndView mv = new ModelAndView("thymeleaf/board/jpaBoardList");
List<Board> list = jpaBoardService.selectBoardList();
mv.addObject("list", list);
return mv;
}
배열로 보냈으니 배열로 받아야함.
jpaBoardList.html에서
<td th:each="list : ${list}">
배열에 있는 객체 값 담아옴.
이 list 안에 배열 값을 담아오고 싶으면
<td th:each="list : ${list.fileList}">
하면 값이 담기며
그 안에 값은
<td th:text="${list.fileList[0]}"></td>
이렇게 list.fileList[0].~값 이렇게 가져와야함.
<script th:inline="javascript">
/*<![CDATA[*/
var message = /*[[${list}]]*/ 'default';
var message2 = /*[[${list.fileList}]]*/ 'default';
/*]]>*/
console.log(message);
console.log(message2);
console.log(message4);
</script>
</tr>
하면 콘솔 찍기 가능
controller
model.addAttribute("userId",1);
html
<input type="hidden" th:value="${userId}"/> 값 담기
[[${list}]]
도 사용 가능
@PostMapping("/permit")
public String permit_policy_page(PolicyDto dto,String userId){ // userId => firstPageId
Long firstPageId = Long.parseLong(userId);
....
}
다만, 이런 방식은 컨트롤러에서 Long 타입이 아닌, String으로밖에 받지 못합니다.
조금 더 세련된 방식으로는 @RequestParam을 이용하는 방법이 있습니다.
@PostMapping("/permit")
public String permit_policy_page(PolicyDto dto,@RequestParam("userId") Long firstPageId){ // userId => firstPageId
// Long firstPageId = Long.parseLong(userId);
...
}
th:name값을 받아서 바로 Long 타입으로 변환할 수 있습니다.
'개발 > Spring Boot' 카테고리의 다른 글
springboot 튜닝 application.yml hikari (0) | 2022.07.29 |
---|---|
Thymeleaf 비교 연산, 리터럴 정보 좋은 사이트 (0) | 2022.07.28 |
thymeleaf에서 th if 사용법 else 그리고 null (0) | 2022.07.27 |
Spring boot method put, delete 사용하려면 방법? (0) | 2022.07.27 |
[SpringBoot] 간단한 게시판 만들기 #3 - domain(Entity) 구현 (0) | 2022.07.19 |