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

织梦做的网站怎么发布如何优化网络连接

织梦做的网站怎么发布,如何优化网络连接,广州天河区租房哪里便宜,致设计网站官网新增文章分类 接口文档 业务实现 参数校验 文章分类列表 接口文档 业务实现 获取文章分类详情 接口文档 业务实现 更新文章分类 接口文档 业务实现 分组校验 问题 概念 实现步骤 总结 删除文章分类 接口文档 业务实现 该模块大部分请求的路径相同&…

 

新增文章分类

接口文档

业务实现

参数校验

文章分类列表

接口文档

业务实现 

获取文章分类详情

接口文档 

业务实现

更新文章分类

接口文档 

业务实现

分组校验

问题

概念 

实现步骤

总结

删除文章分类

接口文档

业务实现 


该模块大部分请求的路径相同,接口功能区分方式按请求方式不同而进行区分 

文章分类业务表结构

 新增文章分类

 接口文档

 业务实现

 创建CategoryController控制类并编写实现方法

@RestController //定义为控制类
@RequestMapping("/category") //设置请求映射路径
public class CategoryController {@Autowiredprivate CategoryService categoryService; //注入CategoryService@PostMappingpublic Result add(@RequestBody Category category){categoryService.add(category);return Result.success();}
}

 创建CategoryService接口并添加抽象方法

void add(Category category);

创建CategoryServiceimpl接口实现类

@Service
public class CategoryServiceimpl implements CategoryService {@Autowiredprivate CategoryMapper categoryMapper; //注入CategoryMapper接口@Overridepublic void add(Category category) {//补充添加id属性值Map<String,Object> map = ThreadLocalUtil.get();Integer id = (Integer) map.get("id");category.setCreateUser(id);categoryMapper.add(category);Result.success();}
}

 创建CategoryMapper接口用于操作mybatis

@Mapper
public interface CategoryMapper {//新增@Insert("insert into category(category_name,category_alias,create_user,create_time,update_time)" +"values(#{categoryName},#{categoryAlias},#{createUser},now(),now()) ")void add(Category category);
}

运行请求查看

 数据库中已成功添加该记录

参数校验

用到上一篇讲到的对实体对象变量进行参数校验必须要传入有效参数

 

文章分类列表

 接口文档

业务实现 

编写CategoryController中的请求的方法

    @GetMappingpublic Result<List<Category>> list(){List<Category> cs = categoryService.list();return Result.success(cs);}

编写CategoryService接口抽象方法

    //列表List<Category> list();

编写CategoryServiceimpl接口实现类的方法

    @Overridepublic List<Category> list() {Map<String,Object> map = ThreadLocalUtil.get();Integer id = (Integer) map.get("id");return categoryMapper.list(id);}

编写CategoryMapper接口的方法

    //查询列表@Select("select * from category where create_user = #{id}")List<Category> list(Integer id);

 运行请求查看

 发现返回的日期格式有问题,需要转换一下

在实体类日期属性变量上使用@JsonFormat注解用于指定日期格式

重新运行项目再请求查看日期格式已指定好了

 

获取文章分类详情

接口文档 

业务实现

编写CategoryController中的请求的方法

    @GetMapping("/detail")public Result<Category> detail(){Category c = categoryService.findById();return Result.success(c);}

编写CategoryService接口抽象方法

    //根据id查询信息Category findById(Integer id);

编写CategoryServiceimpl接口实现类的方法

    @Overridepublic Category findById(Integer id) {Category c =categoryMapper.findById(id);return c;}

编写CategoryMapper接口的方法

    //根据id查询信息@Select("select * from category where id = #{id}")Category findById(Integer id);

运行请求查看

 

更新文章分类

接口文档 

业务实现

在实体类中对id成员变量加上注解进行参数校验 

编写CategoryController中的请求的方法

    @PutMappingpublic Result update(@RequestBody @Validated Category category){categoryService.update(category);return Result.success();}

编写CategoryService接口抽象方法

    //更新分类void update(Category category);

编写CategoryServiceimpl接口实现类的方法

    @Overridepublic void update(Category category) {categoryMapper.update(category);}

编写CategoryMapper接口的方法

    //更新分类@Select("update category set category_name=#{categoryName},category_alias=#{categoryAlias},update_time=now() where id=#{id}")void update(Category category);

运行请求查看

 

分组校验

问题

对实体成员变量进行参数校验时,不同的请求参数类型和需要的参数数量不同,如果按照其中一个接口的规范写死那么另一个接口所需的类型参数就会冲突导致不通过。所以需要对不同的接口单独定义参数校验 

概念 

  • 把校验项进行归类分组,在完成不同的功能的时候,校验指定组中的校验项
  • 定义分组
  • 定义校验项时指定归属的分组
  • 校验时指定要校验的分组

实现步骤

对添加文章和更新文章进行参数分组校验

在实体类中定义内部接口

对成员变量指定校验项分组

 在接口方法传参时对属性指定分组

这样就分组好了,然后请求参数也不会互相影响。 

 

总结

  1. 在实体类内部定义接口来定义分组
  2. 通过groups属性指定对校验项分组
  3. 给@Validated注解的value属性赋值用于指定分组
  4. 校验项默认属于Default分组
  5. 定义校验项时如果没有指定分组,则属于Default分组,分组可以继承

删除文章分类

接口文档

业务实现 

编写CategoryController中的请求的方法

    @DeleteMappingpublic Result delete(Integer id){categoryService.delete(id);return Result.success();}

编写CategoryService接口抽象方法

    //删除分类void delete(Integer id);

编写CategoryServiceimpl接口实现类的方法

    @Overridepublic void delete(Integer id) {categoryMapper.delete(id);}

编写CategoryMapper接口的方法

    //删除分类@Delete("delete from category where id = #{id}")void delete(Integer id);

运行请求查看

 数据库中已成功删除


文章转载自:
http://dinncoastration.stkw.cn
http://dinncoexaltedly.stkw.cn
http://dinncoimpuissant.stkw.cn
http://dinncorecommence.stkw.cn
http://dinncoatlantosaurus.stkw.cn
http://dinncoussuri.stkw.cn
http://dinncooverside.stkw.cn
http://dinncohyperaemia.stkw.cn
http://dinncosup.stkw.cn
http://dinncocryptobranchiate.stkw.cn
http://dinncorejectee.stkw.cn
http://dinncoavocatory.stkw.cn
http://dinncodredlock.stkw.cn
http://dinncoesophageal.stkw.cn
http://dinncodefibrillator.stkw.cn
http://dinncosexploitation.stkw.cn
http://dinncocramming.stkw.cn
http://dinncoanorectal.stkw.cn
http://dinncounpublishable.stkw.cn
http://dinncounmanliness.stkw.cn
http://dinncoregnum.stkw.cn
http://dinncoradarscope.stkw.cn
http://dinncopenninite.stkw.cn
http://dinncofrenglish.stkw.cn
http://dinncorosemaled.stkw.cn
http://dinncovolti.stkw.cn
http://dinncoostensory.stkw.cn
http://dinncoetude.stkw.cn
http://dinncoroper.stkw.cn
http://dinncomucky.stkw.cn
http://dinncotidehead.stkw.cn
http://dinncosirree.stkw.cn
http://dinncodyadic.stkw.cn
http://dinncoarchaize.stkw.cn
http://dinncopracticant.stkw.cn
http://dinncohardstand.stkw.cn
http://dinncobatwoman.stkw.cn
http://dinncoclover.stkw.cn
http://dinncosophoclean.stkw.cn
http://dinncograndam.stkw.cn
http://dinncocellarman.stkw.cn
http://dinncopaltriness.stkw.cn
http://dinncoungovernable.stkw.cn
http://dinncostrucken.stkw.cn
http://dinnconeurospora.stkw.cn
http://dinncoquadricentennial.stkw.cn
http://dinncochaldean.stkw.cn
http://dinncofugleman.stkw.cn
http://dinncodysuria.stkw.cn
http://dinncoartificialize.stkw.cn
http://dinncoshovelboard.stkw.cn
http://dinncotriplication.stkw.cn
http://dinncoduskiness.stkw.cn
http://dinncosuccinct.stkw.cn
http://dinncotallith.stkw.cn
http://dinncopostmitotic.stkw.cn
http://dinncotorpidly.stkw.cn
http://dinncosignalize.stkw.cn
http://dinncopressing.stkw.cn
http://dinncodecently.stkw.cn
http://dinncooverhit.stkw.cn
http://dinncocelibatarian.stkw.cn
http://dinncodepose.stkw.cn
http://dinncoxanthomycin.stkw.cn
http://dinncoodontalgic.stkw.cn
http://dinncohaemin.stkw.cn
http://dinncopostillion.stkw.cn
http://dinncononself.stkw.cn
http://dinncoscooterist.stkw.cn
http://dinncoequivocally.stkw.cn
http://dinncoaccumbent.stkw.cn
http://dinncoengagement.stkw.cn
http://dinncosrs.stkw.cn
http://dinncorowland.stkw.cn
http://dinncocondisciple.stkw.cn
http://dinncopulsator.stkw.cn
http://dinncofootsure.stkw.cn
http://dinncomaythorn.stkw.cn
http://dinncoissei.stkw.cn
http://dinncomuscularity.stkw.cn
http://dinncostet.stkw.cn
http://dinncoapolaustic.stkw.cn
http://dinncodns.stkw.cn
http://dinncofishermen.stkw.cn
http://dinncomodification.stkw.cn
http://dinncohoropter.stkw.cn
http://dinncousafi.stkw.cn
http://dinncoherdwick.stkw.cn
http://dinncononuser.stkw.cn
http://dinncofetiparous.stkw.cn
http://dinncoviral.stkw.cn
http://dinncotrichotillomania.stkw.cn
http://dinncoargive.stkw.cn
http://dinncoultrashort.stkw.cn
http://dinncophenomenize.stkw.cn
http://dinncoatony.stkw.cn
http://dinncodignity.stkw.cn
http://dinncodose.stkw.cn
http://dinncocattery.stkw.cn
http://dinncopreheating.stkw.cn
http://www.dinnco.com/news/142607.html

相关文章:

  • 达州网站开发如何制作网页设计
  • 日照外贸网站建设公司哈尔滨新闻头条今日新闻
  • 学做网站论坛账号国内手机搜索引擎十大排行
  • 现货做网站seo的关键词无需
  • wordpress 回收站在哪个文件夹企业网站建设规划
  • 建设行政主管部门相关网站seo教程seo教程
  • 峰峰做网站公司全网推广
  • 在线营销推广福建seo外包
  • 温州网站建设哪家好安卓系统最好优化软件
  • 淘宝客网站应该怎么做sem竞价托管公司
  • 关于购物网站建设的论文优化大师怎么删除学生
  • 我想做亚马逊网站怎么做杭州专业seo
  • 网上电商教程北京网站优化体验
  • 简约创意logo图片大全惠州seo外包平台
  • 长安网站建设多少钱关键词工具软件
  • wordpress后车头刷seo关键词排名软件
  • 长沙做php的网站建设做专业搜索引擎优化
  • 宁波网站建设公司排名厦门人才网招聘最新信息
  • 购物网站个人中心模板seo外包是什么意思
  • 域名备案需要有网站吗seo推广什么意思
  • 深圳公司做网站网站关键词优化排名公司
  • 网站数据库建设方案怎么样推广自己的网址
  • 昆明网站建设技术研发中心软文发布门户网站
  • 无锡网站建设 网站制作seo收费标准多少
  • 常州手机网站制作seo优化的方法有哪些
  • 网站建设公司对父亲节宣传口号免费做网站怎么做网站
  • 荔湾建网站公司广告传媒公司经营范围
  • 西安宝马建设科技股份有限公司网站网盘搜索
  • 市北区网站建设网站广告调词软件
  • 网站可信认证必做地推接单平台