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

新增文章分类

pojo.Category

package com.lin.springboot01.pojo;import jakarta.validation.constraints.NotEmpty;
import lombok.Data;import java.time.LocalDateTime;@Data
public class Category {private Integer id;//主键@NotEmptyprivate String categoryName;//分类名称@NotEmptyprivate String categoryAlias;//分类别名private Integer createUser;//创建人IDprivate LocalDateTime createTime;//创建时间private LocalDateTime updateTime;//更新时间
}

controller.CategoryController

package com.lin.springboot01.controller;import com.lin.springboot01.pojo.Category;
import com.lin.springboot01.pojo.Result;
import com.lin.springboot01.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;//@RestController注解,相当于@Controller+@ResponseBody两个注解的结合,
// 返回json数据不需要在方法前面加@ResponseBody注解了,
// 但使用@RestController这个注解,就不能返回jsp,html页面,视图解析器无法解析jsp,html页面
@RestController
@RequestMapping("/category")
public class CategoryController {@Autowiredprivate CategoryService categoryService;@PostMapping//@RequestBody,请求参数形式必须是json格式,表格提单不可以用。去掉就可以使用表单提交,不能用json提交public Result add(@RequestBody @Validated Category category){categoryService.add(category);return Result.success();}
}

service.CategoryService

package com.lin.springboot01.service;import com.lin.springboot01.pojo.Category;public interface CategoryService {void add(Category category);
}

service.impl.CategoryServiceImpl

package com.lin.springboot01.service.impl;import com.lin.springboot01.mapper.CategoryMapper;
import com.lin.springboot01.pojo.Category;
import com.lin.springboot01.service.CategoryService;
import com.lin.springboot01.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.time.LocalDateTime;
import java.util.Map;@Service
public class CategoryServiceImpl implements CategoryService {@Autowiredprivate CategoryMapper categoryMapper;@Overridepublic void add(Category category) {category.setCreateTime(LocalDateTime.now());category.setUpdateTime(LocalDateTime.now());Map<String,Object> map = ThreadLocalUtil.get();Integer id = (Integer) map.get("id");category.setCreateUser(id);categoryMapper.add(category);}
}

mapper.CategoryMapper

package com.lin.springboot01.mapper;import com.lin.springboot01.pojo.Category;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface CategoryMapper {//新增@Insert("insert into category(category_name,category_alias,create_user,create_time,update_time) values (" +"#{categoryName},#{categoryAlias},#{createUser},#{createTime},#{updateTime })")void add(Category category);
}

完成: 

http://www.lryc.cn/news/235037.html

相关文章:

  • 选硬币该用动态规划
  • LeetCode 2342. 数位和相等数对的最大和:哈希表
  • Vulkan渲染引擎开发教程 一、开发环境搭建
  • (带教程)商业版SEO关键词按天计费系统:关键词排名优化、代理服务、手机自适应及搭建教程
  • IDEA 快捷键汇总
  • 目标检测YOLO实战应用案例100讲-基于机器视觉的水稻病虫害监测预警
  • OrthoNets:正交信道注意网络
  • C_12练习题
  • 导航守卫有哪三种?
  • 强烈 推荐 13 个 Web前端在线代码IDE
  • 网络协议 WebSocket
  • 路径操作 合法路径名
  • JavaEE初阶 01 计算机是如何工作的
  • 【shell 常用脚本30例】
  • 【我和Python算法的初相遇】——体验递归的可视化篇
  • 【C语言的秘密】密探—深究C语言中多组输入的秘密!
  • ClickHouse 语法优化规则
  • 3-运行第一个docker image-hello world
  • 【漏洞复现】泛微e-Weaver SQL注入
  • 「git 系列」git 如何存储代码的?
  • IDEA 集成 Docker 插件一键部署 SpringBoot 应用
  • IDEA无法查看源码是.class,而不是.java解决方案?
  • 机器视觉系统选型-定光照强度
  • ChatGLM3-6B:新一代开源双语对话语言模型,流畅对话与低部署门槛再升级
  • StoneDB顺利通过中科院软件所 2023 开源之夏 结项审核
  • Linux本地docker一键部署traefik+内网穿透工具实现远程访问Web UI管理界面
  • SpringCloud FeignClient声明式服务调用采坑记录(A调用服务B/C,B/C重启后必须重启A后才能成功调用配置项)
  • 安装银河麒麟linux系统docker(docker-compose)环境,注意事项(一定能解决,有环境资源)
  • BUG:编写springboot单元测试,自动注入实体类报空指针异常
  • 深度解析 InterpretML:打开机器学习模型的黑箱