반응형
BoardController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 |
@RequestMapping("/board/massiveWrite")
public ModelAndView writeMassiveArticle(MultipartHttpServletRequest request){
MultipartFile excelFile = request.getFile("excelFile");
if(excelFile==null || excelFile.isEmpty()){
throw new RuntimeException("엑셀파일을 선택해 주세요");
}
File destFile = new File("D:\\"+excelFile.getOriginalFilename());
try {
excelFile.transferTo(destFile);
} catch (IllegalStateException | IOException e) {
throw new RuntimeException(e.getMessage(),e);
}
boardService.insertMassiveArticleInBoard(destFile);
FileUtils.deleteFile(destFile.getAbsolutePath());
ModelAndView view = new ModelAndView();
view.setViewName("redirect:/board/list");
return view;
} |
cs |
BoardService.java
1
2
3
4 |
public void insertMassiveArticleInBoard(File destFile);
|
cs |
BoardServiceImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
@Override
public void insertMassiveArticleInBoard(File destFile) {
ReadOption readOption = new ReadOption();
readOption.setFilePath(destFile.getAbsolutePath());
readOption.setOutputColumns("A","B","C","D");
readOption.setStartRow(2);
List<Map<String, String>> excelContent = ExcelRead.read(readOption);
BoardVO boardVO = null;
for(Map<String, String> article : excelContent){
boardVO = new BoardVO();
boardVO.setSubject(article.get("A"));
boardVO.setContent(article.get("B"));
boardVO.setUserId(article.get("C"));
boardVO.setFileName(article.get("D"));
this.insertArticleInBoard(boardVO);
}
}
|
cs |
반응형
'IT > Spring' 카테고리의 다른 글
스프링에서 Sitemesh 설정 (0) | 2015.04.30 |
---|---|
Layer (0) | 2015.04.30 |
Excel파일 Read/Write (5) | 2015.04.28 |
메이블 플러그인 빌드 에러 (0) | 2015.04.27 |
Enum(이늄) (0) | 2015.04.27 |