mirror of
https://github.com/suhf/No1WMS.git
synced 2026-02-05 19:53:26 +09:00
change Category and add category jsp files and add ExcelUtils(test)
This commit is contained in:
@@ -5,38 +5,46 @@ import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.no1.wms.excel.ExcelUtils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@Controller
|
||||
public class CategoryController {
|
||||
|
||||
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
ExcelUtils excelUtils;
|
||||
|
||||
// 테스트
|
||||
@GetMapping("/category/test")
|
||||
public String testpage(Model m) {
|
||||
public String testPage(Model m) {
|
||||
List<CategoryDto> dto = categoryService.selectAllCategory();
|
||||
m.addAttribute("dto", dto);
|
||||
|
||||
|
||||
return "category/test";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 카테고리 리스트 출력
|
||||
@GetMapping("/category/list")
|
||||
public String list(@RequestParam(name="p", defaultValue = "1")int p, Model m) {
|
||||
|
||||
public String list(@RequestParam(name = "p", defaultValue = "1") int p, Model m) {
|
||||
|
||||
// 서비스로 카테고리 목록 불러오는 메서드 작성
|
||||
List<CategoryDto> dto = categoryService.categoryList(p);
|
||||
m.addAttribute("list", dto);
|
||||
return "category/list";
|
||||
}
|
||||
|
||||
|
||||
// 상세페이지
|
||||
@PostMapping("/category/read/{kan_code}")
|
||||
public String read(@PathVariable String kan_code, Model m) {
|
||||
@@ -45,57 +53,78 @@ public class CategoryController {
|
||||
m.addAttribute("dto", dto);
|
||||
return "category/read";
|
||||
}
|
||||
|
||||
|
||||
// 생성 - 폼
|
||||
@PostMapping("/category/create")
|
||||
@GetMapping("/category/create")
|
||||
public String create() {
|
||||
return "category/create";
|
||||
}
|
||||
|
||||
|
||||
// 생성 - Ajax
|
||||
@PostMapping("/category/create_process")
|
||||
@ResponseBody
|
||||
public int createProcess(CategoryDto dto, Model m) {
|
||||
int i = categoryService.createProcess(dto);
|
||||
if(i == 1) {
|
||||
if (i == 1) {
|
||||
return i;
|
||||
}else{
|
||||
} else {
|
||||
// ajax테스트후 결정
|
||||
//m.addAttribute("dto", dto);
|
||||
// m.addAttribute("dto", dto);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 수정 - 폼
|
||||
@PostMapping("/category/update/{kan_code}")
|
||||
@GetMapping("/category/update/{kan_code}")
|
||||
public String update(@PathVariable String kan_code, Model m) {
|
||||
CategoryDto dto = categoryService.selectByKanCode(kan_code);
|
||||
m.addAttribute("dto", dto);
|
||||
return "category/update";
|
||||
}
|
||||
// 수정 - Ajax
|
||||
|
||||
|
||||
@PutMapping("/category//update_process")
|
||||
@ResponseBody
|
||||
public int updateProcess(CategoryDto dto, Model m) {
|
||||
|
||||
int i = categoryService.createProcess(dto);
|
||||
if(i == 1) {
|
||||
|
||||
int i = categoryService.updateByKanCode(dto);
|
||||
if (i == 1) {
|
||||
return i;
|
||||
}else{
|
||||
} else {
|
||||
// ajax테스트후 결정
|
||||
//m.addAttribute("dto", dto);
|
||||
// m.addAttribute("dto", dto);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 삭제
|
||||
@DeleteMapping("/category/delete/{kan_code}")
|
||||
@ResponseBody
|
||||
public int delete(@PathVariable String kan_code) {
|
||||
int i = categoryService.deactivateByKanCode(kan_code);
|
||||
if (i == 1) {
|
||||
return i;
|
||||
} else {
|
||||
// ajax테스트후 결정
|
||||
// m.addAttribute("dto", dto);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 삭제
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/category/download")
|
||||
public void downloadExcel(HttpServletResponse response) {
|
||||
List<CategoryDto> dto = categoryService.selectAllCategory();
|
||||
String excelFileName = "카테고리 테스트 파일";
|
||||
String sheetName = "카테고리";
|
||||
String[] columnName = {"KAN_CODE","대분류","중분류","소분류","세분류"};
|
||||
excelUtils.downloadCategoryExcelFile(excelFileName, response, sheetName, columnName, dto);
|
||||
|
||||
}
|
||||
|
||||
// KAN코드 중복확인 메서드
|
||||
public int chackKancode(String kan_code) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ public interface CategoryMapper {
|
||||
CategoryDto selectByKanCode(String kan_code);
|
||||
int createProcess(CategoryDto dto);
|
||||
List<CategoryDto> selectAllCategory();
|
||||
|
||||
|
||||
int updateByKanCode(CategoryDto dto);
|
||||
int deactivateByKanCode(String kan_code);
|
||||
int activateByKanCode(String kan_code);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ public class CategoryService {
|
||||
// String start에 int값 넣고 String end에 int값 넣고
|
||||
// CategoryMapper에 있는 메서드 사용함.
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
int count = 10;
|
||||
|
||||
Map m = new HashMap<String, Object>();
|
||||
m.put("start", start);
|
||||
m.put("end", end);
|
||||
m.put("count", count);
|
||||
|
||||
|
||||
|
||||
@@ -33,13 +33,26 @@ public class CategoryService {
|
||||
}
|
||||
|
||||
public int createProcess(CategoryDto dto) {
|
||||
mapper.createProcess(dto);
|
||||
return 1;
|
||||
return mapper.createProcess(dto);
|
||||
}
|
||||
|
||||
public List<CategoryDto> selectAllCategory() {
|
||||
// 테스트용
|
||||
return mapper.selectAllCategory();
|
||||
}
|
||||
|
||||
public int updateByKanCode(CategoryDto dto) {
|
||||
return mapper.updateByKanCode(dto);
|
||||
}
|
||||
|
||||
public int deactivateByKanCode(String kan_code) {
|
||||
return mapper.deactivateByKanCode(kan_code);
|
||||
}
|
||||
public int activateByKanCode(String kan_code) {
|
||||
return mapper.activateByKanCode(kan_code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
78
src/main/java/com/no1/wms/excel/ExcelUtils.java
Normal file
78
src/main/java/com/no1/wms/excel/ExcelUtils.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package com.no1.wms.excel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.no1.wms.category.CategoryDto;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@Service
|
||||
public class ExcelUtils {
|
||||
|
||||
public void downloadCategoryExcelFile(String excelFileName, HttpServletResponse response,
|
||||
String sheetName, String[] columnName, List<CategoryDto> dto) {
|
||||
String fileName = "";
|
||||
try {
|
||||
fileName = new String((excelFileName + ".xlsx").getBytes("utf-8"), "iso-8859-1");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
response.setContentType("ms-vnd/excel");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";");
|
||||
|
||||
Workbook workbook = new HSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet(sheetName);
|
||||
|
||||
Row row = null;
|
||||
Cell cell = null;
|
||||
int rowNum = 0;
|
||||
|
||||
row = sheet.createRow(rowNum);
|
||||
for( int i = 0; i <= columnName.length -1; i++ ) {
|
||||
cell = row.createCell(i);
|
||||
cell.setCellValue(columnName[i]);
|
||||
}
|
||||
rowNum += 1;
|
||||
//수정부분
|
||||
makeCategoryBody(dto,row,sheet,cell,rowNum);
|
||||
|
||||
try {
|
||||
workbook.write(response.getOutputStream());
|
||||
workbook.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void makeCategoryBody(List<CategoryDto> listdto, Row row, Sheet sheet,
|
||||
Cell cell, int rowNum) {
|
||||
//
|
||||
for (int i = 0; i < listdto.size(); i++) {
|
||||
row = sheet.createRow(rowNum++);
|
||||
CategoryDto dto = listdto.get(i);
|
||||
cell = row.createCell(0);
|
||||
cell.setCellValue(dto.getKan_code());
|
||||
cell = row.createCell(1);
|
||||
cell.setCellValue(dto.getCls_nm_1());
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue(dto.getCls_nm_2());
|
||||
cell = row.createCell(3);
|
||||
cell.setCellValue(dto.getCls_nm_3());
|
||||
cell = row.createCell(4);
|
||||
cell.setCellValue(dto.getCls_nm_4());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user