상세 컨텐츠

본문 제목

프로그래머 도전기 112일차

프로그래머가 될거야!

by Choyee 2024. 2. 6. 22:56

본문

오늘은

 

내일은 중간 발표일입니다

지금까지 진행한 프로젝트의 중간점검을 하는 날입니다

배포를 위해 jar 파일을 만들었고

github도 충분히 활용중입니다

 

 

 

프로젝트

 

백엔드 파트에서는 파일 첨부 기능을 넣었습니다

	private String hopeFilename;
	private String hopeFilepath;

 

관련 필드를 생성해주고,

	@Column
	private String hopeFilename;
	@Column
	private String hopeFilepath;

칼럼으로도 생성해줍니다

 

글쓰기 폼에서 enctype 속성을 추가해줍니다

 <form th:action="@{/hopeboard/write}" method="post" th:object=${hopeBoard} enctype="multipart/form-data">

 

컨트롤러와 서비스에서 데이터 처리를 해줍니다

 

    @PostMapping("/hopeboard/write")
    public String write(@ModelAttribute HopeBoard hopeBoard,
    				    @AuthenticationPrincipal SecurityUser principal,
    				    MultipartFile hopeBoardFile
    				    /*BindingResult bindingResult*/) throws IOException, Exception {
    	hopeBoard.setMember(principal.getMember());
    	hopeBoard.setHbhit(0);
    	hopeBoardService.save(hopeBoard, hopeBoardFile);

        return "redirect:/hopeboard/pagelist";
    }

 

public void save(HopeBoard hopeBoard, MultipartFile hopeBoardFile) throws Exception, IOException {

    if(!hopeBoardFile.isEmpty()) { 
    /*String hopeFilepath = "C:\\Final_project\\final-project\\finalproject\\src\\main\\resources\\static\\upload\\";*/
    String hopeFilepath = "C:\\final-project\\finalproject\\src\\main\\resources\\static\\upload";
    UUID uuid = UUID.randomUUID();
    String hopeFilename = uuid + "_" + hopeBoardFile.getOriginalFilename();

    File savedHopeFile = new File(hopeFilepath, hopeFilename);
    hopeBoardFile.transferTo(savedHopeFile);

    hopeBoard.setHopeFilename(hopeFilename);
    hopeBoard.setHopeFilepath("/upload/" + hopeFilename);
    }

    hopeBoardRepository.save(hopeBoard);
}

 

 

 

 

프론트엔드 파트에서는 게시판 관련 html과 css,

댓글 기능 관련 코딩을 하였습니다

 

 

 

 

 

2024. 02. 06 (화)

관련글 더보기