当前位置: 首页 > wzjs >正文

农业公司注册流程及费用广州网络优化最早的公司

农业公司注册流程及费用,广州网络优化最早的公司,江门英文网站建设,做网站一般需要哪些文件夹📖 模块概述 文章分类模块包括 新增文章分类、文章分类列表、获取文章分类详情、更新文章分类、删除文章分类 功能。本篇对于原项目进行了代码优化,将原先写在 Controller 层的业务逻辑代码迁移至了 Service 层。 🛠️ 技术实现要点 分组校…

📖 模块概述

  • 文章分类模块包括 新增文章分类、文章分类列表、获取文章分类详情、更新文章分类、删除文章分类 功能。
  • 本篇对于原项目进行了代码优化,将原先写在 Controller 层的业务逻辑代码迁移至了 Service 层。

🛠️ 技术实现要点

  • 分组校验
    • 定义分组:在实体类内部定义接口
    • 对校验项进行分组:通过 groups 属性指定
    • 校验时指定分组:给 @Validated 注解的 value 属性赋值
    • 校验项默认属于:Default 分组

⚙️ 各层职责与代码规范

🔗 Controller 层

@RestController
@RequiredArgsConstructor
@RequestMapping("/category")
public class CategoryController {...
}

🔗 Service 层

public interface CategoryService {...
}
@Service
@RequiredArgsConstructor
public class CategoryServiceImpl implements CategoryService {...
}

🔗 Mapper 层

@Mapper
public interface CategoryMapper {...
}

🔗 层间交互与依赖注入

@Service
@RequiredArgsConstructor
public class CategoryServiceImpl implements CategoryService {private final CategoryMapper categoryMapper;...
}
@RestController
@RequiredArgsConstructor
@RequestMapping("/category")
public class CategoryController {private final CategoryService categoryService;...
}

🔍 功能实现详解

🎯 新增文章分类

🧩 Controller 层

请求路径:/category
请求方式:POST
接口描述:该接口用于新增文章分类

@PostMapping
public Result addCategory(@RequestBody @Validated(Category.Add.class) Category category) {categoryService.addCategory(category);return Result.success();
}

🧩 Service 层

  • 接口
// 新增分类
void addCategory(Category category);// 根据分类名称查询分类信息
Category findCategoryByName(String categoryName);// 根据分类别名查询分类信息
Category findCategoryByAlias(String categoryAlias);
  • 实现
/*** 添加分类** @param category 分类对象*/
@Override
public void addCategory(Category category) {// 补充属性值category.setCreateTime(LocalDateTime.now());category.setUpdateTime(LocalDateTime.now());Map<String, Object> map = ThreadLocalUtil.get();Integer userId = (Integer) map.get("id");category.setCreateUser(userId);// 判断分类名称是否已存在Category categoryByName = findCategoryByName(category.getCategoryName());if (categoryByName != null) {throw new RuntimeException("分类名称已存在");}// 判断分类别名是否已存在Category categoryByAlias = findCategoryByAlias(category.getCategoryAlias());if (categoryByAlias != null) {throw new RuntimeException("分类别名已存在");}categoryMapper.addCategory(category);
}/*** 根据分类名称查询分类对象** @param categoryName 分类名称* @return 分类对象*/
@Override
public Category findCategoryByName(String categoryName) {return categoryMapper.findCategoryByName(categoryName);
}/*** 根据分类别名查询分类对象** @param categoryAlias 分类别名* @return 分类对象*/
@Override
public Category findCategoryByAlias(String categoryAlias) {return categoryMapper.findCategoryByAlias(categoryAlias);
}

Mapper 层

// 新增文章分类
@Insert("insert into category(category_name, category_alias, create_user, create_time, update_time) " +"values(#{categoryName}, #{categoryAlias}, #{createUser}, #{createTime}, #{updateTime})")
void addCategory(Category category);// 根据分类名称查询分类
@Select("select * from category where category_name = #{categoryName}")
Category findCategoryByName(String categoryName);// 根据分类别名查询分类
@Select("select * from category where category_alias = #{categoryAlias}")
Category findCategoryByAlias(String categoryAlias);

🎯 文章分类列表

🧩 Controller 层

请求路径:/category
请求方式:GET
接口描述:该接口用于获取当前已登录用户创建的所有文章分类

@GetMapping
public Result<List<Category>> getCategoryList() {List<Category> categoryList = categoryService.getCategoryList();return Result.success(categoryList);
}

🧩 Service 层

  • 接口
// 列表查询
List<Category> getCategoryList();
  • 实现
/*** 查询分类列表** @return 分类列表*/
@Override
public List<Category> getCategoryList() {Map<String, Object> map = ThreadLocalUtil.get();Integer userId = (Integer) map.get("id");return categoryMapper.getCategoryList(userId);
}

🧩 Mapper 层

// 查询某用户的所有文章分类
@Select("select * from category where create_user = #{userId}")
List<Category> getCategoryList(Integer userId);

🎯 获取文章分类详情

🧩 Controller 层

请求路径:/category/detail
请求方式:GET
接口描述:该接口用于根据ID获取文章分类详情

@GetMapping("/detail")
public Result<Category> getCategoryDetail(Integer id) {Category category = categoryService.findCategoryById(id);return Result.success(category);
}

🧩 Service 层

  • 接口
// 根据 id 查询分类信息
Category findCategoryById(Integer id);
  • 实现
/*** 根据id查询分类对象** @param id 分类id* @return 分类对象*/
@Override
public Category findCategoryById(Integer id) {Category category = categoryMapper.findCategoryById(id);return category;
}

🧩 Mapper 层

// 根据 id 查询文章分类
@Select("select * from category where id = #{id}")
Category findCategoryById(Integer id);

🎯 更新文章分类

🧩 Controller 层

请求路径:/category
请求方式:PUT
接口描述:该接口用于更新文章分类

@PutMapping
public Result updateCategory(@RequestBody @Validated(Category.Update.class) Category category) {categoryService.updateCategory(category);return Result.success();
}

🧩 Service 层

  • 接口
// 更新文章分类
void updateCategory(Category category);
  • 实现
/*** 修改分类** @param category 分类对象*/
@Override
public void updateCategory(Category category) {category.setUpdateTime(LocalDateTime.now());categoryMapper.updateCategory(category);
}

🧩 Mapper 层

@Update("update category " +"set category_name = #{categoryName}, category_alias = #{categoryAlias}, update_time = #{updateTime} " +"where id = #{id}")
void updateCategory(Category category);

🎯 删除文章分类

请求路径:/category
请求方式:DELETE
接口描述:该接口用于根据ID删除文章分类

🧩 Controller 层

@DeleteMapping
public Result deleteCategory(Integer id){categoryService.deleteCategoryById(id);return Result.success();
}

🧩 Service 层

  • 接口
// 删除文章分类
void deleteCategoryById(Integer id);
  • 实现
/*** 根据id删除分类** @param id 分类id*/
@Override
public void deleteCategoryById(Integer id) {categoryMapper.deleteCategoryById(id);
}

🧩 Mapper 层

@Delete("delete from category where id = #{id}")
void deleteCategoryById(Integer id);
http://www.dtcms.com/wzjs/240345.html

相关文章:

  • 华为网站建设的目标是否明确郑州网站关键词排名技术代理
  • 云南建设投资控股集团有限公司网站珠海网站建设
  • 南阳做网站价格2019年 2022疫情爆发
  • 如何设计优秀的公司网站互联网项目推广
  • 烟台网站的建设个人主页网页设计模板
  • 农业大学网站建设特点深圳网站设计小程序
  • 深圳网站开发公司哪家好网页设计与制作作业成品
  • 甘肃省环保建设申报网站品牌营销策划书
  • 重庆企业网站制作公司百姓网推广电话
  • 地方门户网站建设要求申请域名
  • 安徽休宁建设厅网站网店代运营正规公司
  • 网站制作公司 郑州青岛seo整站优化招商电话
  • 哪些网站做黑名单seo排名优化公司
  • 淘宝上做微请帖的在哪个网站十种营销方式
  • 住房和城乡建设厅电工证东莞seo优化排名推广
  • 西安中风险地区百度竞价推广关键词优化
  • 建筑装饰公司做网站的作用seo排名快速上升
  • 政府网站内容建设 规范企业培训体系
  • php电子商务网站开发实例网站搜索排名优化怎么做
  • 独立网店系统seo的基本步骤是什么
  • 昆明网站推广排名文案写作软件app
  • 珠海网站建设杰作科技sem竞价托管价格
  • 网站开发技术介绍大连企业网站建站模板
  • 网站建设中英文版中国搜索引擎市场份额
  • 农夫山泉vi设计案例如何优化网站快速排名
  • 做个网站一般多少钱培训机构招生方案
  • 网站建设会计科目湘潭营销型网站建设
  • 遵义网站建设公司seo推广计划
  • 交友网站美女要一起做外贸站长之家新网址
  • icp备案网站旺道seo软件技术