分类管理(WRITE)

This commit is contained in:
slhaf
2024-09-10 15:29:04 +08:00
parent ae69dba64a
commit d6471726b9
4 changed files with 43 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package com.sky.controller.category;
import com.sky.dto.CategoryDTO; import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO; import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult; import com.sky.result.PageResult;
import com.sky.result.Result; import com.sky.result.Result;
import com.sky.service.CategoryService; import com.sky.service.CategoryService;
@@ -13,6 +14,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController @RestController
@Api(tags = "分类相关接口") @Api(tags = "分类相关接口")
@RequestMapping("/admin/category") @RequestMapping("/admin/category")
@@ -88,5 +91,16 @@ public class CategoryController {
return Result.success(); return Result.success();
} }
/**
* 根据id查询分类
* @param type
* @return
*/
@GetMapping("/list")
@ApiOperation("根据id查询分类")
public Result<List> list(Integer type){
log.info("根据id查询分类");
List<Category> result = categoryService.list(type);
return Result.success(result);
}
} }

View File

@@ -6,6 +6,9 @@ import com.sky.entity.Category;
import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper @Mapper
public interface CategoryMapper { public interface CategoryMapper {
@@ -20,4 +23,7 @@ public interface CategoryMapper {
void deleteById(long id); void deleteById(long id);
void update(Category category); void update(Category category);
@Select("select * from category where type = #{type}")
List<Category> selectByType(Integer type);
} }

View File

@@ -2,9 +2,12 @@ package com.sky.service;
import com.sky.dto.CategoryDTO; import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO; import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult; import com.sky.result.PageResult;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
@Service @Service
public interface CategoryService { public interface CategoryService {
/** /**
@@ -38,4 +41,11 @@ public interface CategoryService {
* @param categoryDTO * @param categoryDTO
*/ */
void update(CategoryDTO categoryDTO); void update(CategoryDTO categoryDTO);
/**
* 根据类型查询分类
* @param type
* @return
*/
List<Category> list(Integer type);
} }

View File

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List; import java.util.List;
@Service @Service
@@ -104,4 +105,15 @@ public class CategoryServiceImpl implements CategoryService {
BaseContext.removeCurrentId(); BaseContext.removeCurrentId();
categoryMapper.update(category); categoryMapper.update(category);
} }
/**
* 根据类型查询分类
* @param type
* @return
*/
@Override
public List<Category> list(Integer type) {
List<Category> list = categoryMapper.selectByType(type);
return list;
}
} }