mirror of
https://github.com/suhf/No1WMS.git
synced 2026-02-04 19:54:00 +09:00
add CategoryMapper.xml and update Category files
This commit is contained in:
@@ -1,43 +1,90 @@
|
||||
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.ui.Model;
|
||||
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.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class CategoryController {
|
||||
|
||||
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
|
||||
// 카테고리 리스트 출력
|
||||
@GetMapping("/list")
|
||||
public String list() {
|
||||
@GetMapping("/category/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";
|
||||
}
|
||||
|
||||
// 상세페이지
|
||||
@PostMapping("/read/{kan_code}")
|
||||
public String read(@PathVariable UUID kan_code) {
|
||||
@PostMapping("/category/read/{kan_code}")
|
||||
public String read(@PathVariable String kan_code, Model m) {
|
||||
// 선택한 kan_code를 바탕으로 원하는 상세정보 출력하는 메서드 작성
|
||||
CategoryDto dto = categoryService.selectByKanCode(kan_code);
|
||||
m.addAttribute("dto", dto);
|
||||
return "category/read";
|
||||
}
|
||||
|
||||
// 생성
|
||||
@GetMapping("/create")
|
||||
public String createform() {
|
||||
// 생성 - 폼
|
||||
@PostMapping("/category/create")
|
||||
public String create() {
|
||||
return "category/create";
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public void create(CategoryDto dto) {
|
||||
|
||||
// 생성 - Ajax
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.no1.wms.category;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.apache.ibatis.type.Alias;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Alias("CategoryDto")
|
||||
public class CategoryDto {
|
||||
|
||||
private UUID kan_code;
|
||||
private String kan_code;
|
||||
private String cls_nm_1;
|
||||
private String cls_nm_2;
|
||||
private String cls_nm_3;
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
package com.no1.wms.category;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface CategoryMapper {
|
||||
List<CategoryDto> categoryList(Map<String, Object> m);
|
||||
CategoryDto selectByKanCode(String kan_code);
|
||||
int createProcess(CategoryDto dto);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,43 @@
|
||||
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;
|
||||
|
||||
@Service
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
39
src/main/resources/mappers/CategoryMapper.xml
Normal file
39
src/main/resources/mappers/CategoryMapper.xml
Normal 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>
|
||||
Reference in New Issue
Block a user