실행 결과 1) boardList에서 글작성 클릭 시 로그인 창 출력 로그인을 하지 않아도 글을 보거나 게시판 목록 접근 가능하지만 글 등록은 로그인하여야 함 2) ROLE_ADMIN 권한을 갖고 있는 아이디 비밀번호로 접속 3) 게시글 작성 4) 해당 게시글 확인 5. 테이블 설계 ▶member 테이블 create table member( userid varchar(50) primary key, userpw varchar(100) not null, username varchar(100) not null, regdate datetime not null default current_timestamp, updatedate datetime, enabled char(1) default '1' ); ▶member..
테이블 추가 ▶attach 테이블 create table attach( uuid varchar(100) primary key, uploadPath varchar(200) not null, fileName varchar(100) not null, fileType char(3) default 'I', board_id bigint ); ALTER TABLE attach ADD FOREIGN KEY(board_id) REFERENCES board(id); uuid: UUID가 포함된 파일 이름 uploadPath: 실제 파일이 업로드된 경로 fileName: 파일 이름 fileType: 파일 종류, 이미지 파일 여부 확인 board_id: 해당 게시물 번호 저장(board 테이블, 외래키 역할) DTO ▶Boa..
첨부파일 다운로드 UploadController.java @GetMapping(value = "/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @ResponseBody public ResponseEntity downloadFile(String fileName) { Resource resource = new FileSystemResource("D:\\upload\\" + fileName); String resourceName = resource.getFilename(); HttpHeaders headers = new HttpHeaders(); try { headers.add("Content-Disposition", "attachment; ..
중복된 파일 이름 해결하는 아이디어 파일 업로드 시간을 이용하는 방법 UUID를 이용해 중복이 발생할 가능성이 적은 문자열을 생성하는 방법 1. 파일 업로드 시간을 이용해 파일 생성 private String getFolder() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); String str = sdf.format(date); return str.replace("-", File.separator); } @PostMapping("/uploadAjaxAction") public void uploadAjaxPost(MultipartFile[] uploadFile) { String uploadFolder..