1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-09 02:11:38 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

添加分类搜索功能

This commit is contained in:
2022-03-16 00:09:35 +08:00
parent 174d24d5d0
commit 33f8dc4ea4
7 changed files with 144 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
package plus.bookshelf.Controller.Controller;
import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -53,22 +53,22 @@ public class BaseController {
}
// 定义ExceptionHandler解决未被Controller层吸收的Exception
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Object handlerException(HttpServletRequest request, Exception ex) {
HashMap<Object, Object> responseData = new HashMap<>();
if (ex instanceof BusinessException) {
BusinessException businessException = (BusinessException) ex;
responseData.put("errCode", businessException.getErrCode());
responseData.put("errMsg", businessException.getErrMsg());
} else {
responseData.put("errCode", BusinessErrorCode.UNKNOWN_ERROR.getErrCode());
responseData.put("errMsg", BusinessErrorCode.UNKNOWN_ERROR.getErrMsg());
}
return CommonReturnType.create(responseData, CommonReturnTypeStatus.FAILED);
}
// @ExceptionHandler(Exception.class)
// @ResponseStatus(HttpStatus.OK)
// @ResponseBody
// public Object handlerException(HttpServletRequest request, Exception ex) {
// HashMap<Object, Object> responseData = new HashMap<>();
//
// if (ex instanceof BusinessException) {
// BusinessException businessException = (BusinessException) ex;
// responseData.put("errCode", businessException.getErrCode());
// responseData.put("errMsg", businessException.getErrMsg());
// } else {
// // 生产环境输出格式化信息
// responseData.put("errCode", BusinessErrorCode.UNKNOWN_ERROR.getErrCode());
// responseData.put("errMsg", BusinessErrorCode.UNKNOWN_ERROR.getErrMsg());
// }
//
// return CommonReturnType.create(responseData, CommonReturnTypeStatus.FAILED);
// }
}

View File

@@ -0,0 +1,49 @@
package plus.bookshelf.Controller.Controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Controller.VO.BookVO;
import plus.bookshelf.Controller.VO.CategoryVO;
import plus.bookshelf.Service.Model.BookModel;
import plus.bookshelf.Service.Model.CategoryModel;
import plus.bookshelf.Service.Service.BookService;
import plus.bookshelf.Service.Service.CategoryService;
@Api(value = "书籍分类")
@Controller("category")
@RequestMapping("/category")
public class CategoryController {
@Autowired
CategoryService categoryService;
@ApiOperation(value = "获取书籍分类", notes = "获取书籍分类")
@RequestMapping(value = "get", method = {RequestMethod.GET})
@ResponseBody
public CommonReturnType get(@RequestParam(value = "id") Integer id) {
if (id == null) {
return null;
}
CategoryModel categoryModel = categoryService.getCategoryById(id);
CategoryVO categoryVO = convertFromModel(categoryModel);
return CommonReturnType.create(categoryVO);
}
private CategoryVO convertFromModel(CategoryModel categoryModel) {
if (categoryModel == null) {
return null;
}
CategoryVO categoryVO = new CategoryVO();
BeanUtils.copyProperties(categoryModel, categoryVO);
return categoryVO;
}
}

View File

@@ -0,0 +1,25 @@
package plus.bookshelf.Controller.VO;
import lombok.Data;
@Data
public class CategoryVO {
// 分类名称
Integer id;
// 分类名称
String name;
// 分类简介
String description;
// 分类显示顺序
Integer order;
// 分类级别 0为一级分类, 1为二级分类...
Integer level;
// 父分类
Integer parentId;
}

View File

@@ -14,7 +14,7 @@ public class CategoryModel {
// 分类简介
String description;
// 是否展示 (该字段暂未启用)
Boolean isShow;
// 分类显示顺序