add CategoryMapper.xml and update Category files

This commit is contained in:
Kana
2024-01-03 14:52:27 +09:00
parent 28a9b0b5c5
commit 28eecf0f24
5 changed files with 146 additions and 14 deletions

View File

@@ -1,44 +1,91 @@
package com.no1.wms.category; package com.no1.wms.category;
import java.util.UUID; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller @Controller
public class CategoryController { public class CategoryController {
@Autowired
CategoryService categoryService;
// 카테고리 리스트 출력 // 카테고리 리스트 출력
@GetMapping("/list") @GetMapping("/category/list")
public String list() { 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"; return "category/list";
} }
// 상세페이지 // 상세페이지
@PostMapping("/read/{kan_code}") @PostMapping("/category/read/{kan_code}")
public String read(@PathVariable UUID kan_code) { public String read(@PathVariable String kan_code, Model m) {
// 선택한 kan_code를 바탕으로 원하는 상세정보 출력하는 메서드 작성 // 선택한 kan_code를 바탕으로 원하는 상세정보 출력하는 메서드 작성
CategoryDto dto = categoryService.selectByKanCode(kan_code);
m.addAttribute("dto", dto);
return "category/read"; return "category/read";
} }
// 생성 // 생성 - 폼
@GetMapping("/create") @PostMapping("/category/create")
public String createform() { public String create() {
return "category/create"; return "category/create";
} }
@PostMapping("/create") // 생성 - Ajax
public void create(CategoryDto dto) { @PostMapping("/category/create_process")
public int createProcess(CategoryDto dto, Model m) {
int i = categoryService.createProcess(dto);
if(i == 1) {
return i;
}else{
// ajax테스트후 결정
//m.addAttribute("dto", dto);
return 0;
}
}
// 수정 - 폼
@PostMapping("/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
@PostMapping("/category//update_process")
public int updateProcess(CategoryDto dto, Model m) {
int i = categoryService.createProcess(dto);
if(i == 1) {
return i;
}else{
// ajax테스트후 결정
//m.addAttribute("dto", dto);
return 0;
}
} }
} }

View File

@@ -1,13 +1,16 @@
package com.no1.wms.category; package com.no1.wms.category;
import java.util.UUID; import org.apache.ibatis.type.Alias;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@Data @Data
@AllArgsConstructor
@Alias("CategoryDto")
public class CategoryDto { public class CategoryDto {
private UUID kan_code; private String kan_code;
private String cls_nm_1; private String cls_nm_1;
private String cls_nm_2; private String cls_nm_2;
private String cls_nm_3; private String cls_nm_3;

View File

@@ -1,8 +1,16 @@
package com.no1.wms.category; package com.no1.wms.category;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@Mapper @Mapper
public interface CategoryMapper { public interface CategoryMapper {
List<CategoryDto> categoryList(Map<String, Object> m);
CategoryDto selectByKanCode(String kan_code);
int createProcess(CategoryDto dto);
} }

View File

@@ -1,8 +1,43 @@
package com.no1.wms.category; package com.no1.wms.category;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class CategoryService { public class CategoryService {
@Autowired
CategoryMapper mapper;
public List<CategoryDto> categoryList(int p) {
// 페이지 넘버 p를 이용해서 장원형님이 만드신 페이징 메서드를 이용해서
// String start에 int값 넣고 String end에 int값 넣고
// CategoryMapper에 있는 메서드 사용함.
int start = 0;
int end = 0;
Map m = new HashMap<String, Object>();
m.put("start", start);
m.put("end", end);
return mapper.categoryList(m);
}
public CategoryDto selectByKanCode(String kan_code) {
return mapper.selectByKanCode(kan_code);
}
public int createProcess(CategoryDto dto) {
mapper.createProcess(dto);
return 1;
}
} }

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.no1.wms.category.CategoryMapper">
<!-- insert -->
<insert id="createProcess" parameterType="CategoryDto">
INSERT INTO product_category (kan_code, cls_nm_1, cls_nm_2, cls_nm_3, cls_nm_4, activation)
VALUES (#{dto.kan_code}, #{dto.cls_nm_1},#{dto.cls_nm_2},#{dto.cls_nm_3},#{dto.cls_nm_4},1)
</insert>
<!-- update -->
<update id="updatebyCanCode" parameterType="CategoryDto">
UPDATE product_category
SET cls_nm_1 = #{dto.cls_nm_1}, cls_nm_2 = #{dto.cls_nm_2},cls_nm_3 = #{dto.cls_nm_3}, cls_nm_4 = #{dto.cls_nm_4}
WHERE kan_code = {dto.kan_code}
</update>
<!-- delete -->
<!-- select -->
<select id="categoryList" parameterType="map" resultType="CategoryDto">
select * from product_category
order by kan_code desc limit #{start} , #{count}
</select>
<select id="selectByKancode" parameterType="String" resultType="CategoryDto">
select * from product_category where kan_code = #{kan_code}
</select>
</mapper>