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

子域名做微信开放平台网站应用佛山设计网站设计价格

子域名做微信开放平台网站应用,佛山设计网站设计价格,网站安全建设模板下载安装,浠水网站建设今天主要完成了#xff1a; 新增棋子分类 棋子分类列表 获取棋子分类详情 更新棋子分类 更新棋子分类和添加棋子分类_分组校验 新增棋子 新增棋子参数校验 棋子分类列表查询(条件分页) 先给出分类实体类 Data public class Category {private Integer id;//主键IDNot…今天主要完成了 新增棋子分类 棋子分类列表 获取棋子分类详情 更新棋子分类 更新棋子分类和添加棋子分类_分组校验 新增棋子 新增棋子参数校验 棋子分类列表查询(条件分页) 先给出分类实体类 Data public class Category {private Integer id;//主键IDNotEmptyprivate String categoryName;//分类名称(赛季全名)NotEmptyprivate String categoryAlias;//分类别名(赛季版本号)private Integer createUser;//创建人IDprivate LocalDateTime createTime;//创建时间private LocalDateTime updateTime;//更新时间 }新增棋子分类 接口文档 读接口文档需求就是一个Insert但是发现接口文档没有考虑到可能会有重复分类的创建我认为重复分类的创建是不合适的所以我做了一个分类存在检测以防止重复分类的出现 基本属于User新建的小修小改直接上代码 Controller层 PostMappingpublic Result add(RequestBody Validated Category category){String init_name category.getCategoryName();Category incategory categoryService.getCategoryByNAME(init_name);if (incategory null){ categoryService.add(category);return Result.success();} else {return Result.error(棋子分类已存在);}} 写了一个条件判断来防止重复分类的出现用json里给的分类名查分类是否存在 Service层 Overridepublic void add(Category category) {MapString,Object map ThreadLocalUtil.get();Integer id (Integer) map.get(id);category.setCreateTime(LocalDateTime.now());category.setUpdateTime(LocalDateTime.now());category.setCreateUser(id);categoryMapper.add(category);}Overridepublic Category getCategoryByNAME(String init_name) {Category c categoryMapper.getCategoryByNAME(init_name);return c;} 一个新增一个查询为了达成给分类写入创建人相关信息还是老方法从ThreadLocal里面取 Mapper层 Insert(insert into category(category_name,category_alias,create_user,create_time,update_time) values(#{categoryName},#{categoryAlias},#{createUser},#{createTime},#{updateTime}) )void add(Category category);Select(Select * from category where category_name #{init_name})Category getCategoryByNAME(String init_name); 搞定 棋子分类列表 接口文档 可以看到这次不需要接入任何参数返回的是一个棋子分类列表区别不大开搞 ps:突然发现接口文档要求的时间格式跟直接捞出来的localdatatime格式不一样这是个问题 Controller层 GetMappingpublic ResultListCategory list(){ListCategory categoryList categoryService.list();return Result.success(categoryList);} Service层 Overridepublic ListCategory list() {MapString,Object map ThreadLocalUtil.get();Integer id (Integer) map.get(id);return categoryMapper.list(id);} 老规矩ThreadLocal拿用户信息  Mapper层 Select(select * from category where create_user #{id})ListCategory list(Integer id); 解决给出时间格式需修改问题  在实体类中用 JsonFormat接口 private LocalDateTime createTime;//创建时间JsonFormat(pattern TIME_REGEXP)private LocalDateTime updateTime;//更新时间 RT相应的也更新了我的正则文件 public static final String TIME_REGEXP ^yyyy-MM-dd HH:mm:ss; 搞定收工  获取棋子分类详情 接口文档 阅读接口文档通过分类ID获取分类全部信息再多考虑下非法ID输入就行 Controller层 GetMapping(detail)public ResultCategory getDetail(Integer id){Category category categoryService.getCategoryByID(id);if (category null){return Result.error(查询分类不存在);}else {return Result.success(category);}} 做了个简单逻辑判断来确保查询的分类是存在的  Service层 Overridepublic Category getCategoryByID(Integer init_ID) {return categoryMapper.getCategoryByID(init_ID);} Mapper层 Select(Select * from category where id #{init_ID})Category getCategoryByID(Integer init_ID); 顺手修改下新增棋子接口 由于这个按ID查询棋子和新增棋子接口用的按分类名查询实际上效果一样为了提高代码复用率把新增棋子接口的查询直接改成按ID查询如下 PostMappingpublic Result add(RequestBody Validated Category category){Integer init_ID category.getId();Category incategory categoryService.getCategoryByID(init_ID);if (incategory null){ categoryService.add(category);return Result.success();} else {return Result.error(棋子分类已存在);}} 别忘了删除其他基层的按分类名查询  更新棋子分类 接口文档 读接口文档注意下参数校验和身份验证就行 先看Controller层 PutMappingpublic Result update(RequestBody Validated Category incategory){Category category categoryService.getCategoryByID(incategory.getId());if (category null){return Result.error(要修改的分类不存在);}else {Integer userID category.getCreateUser();MapString,Object map ThreadLocalUtil.get();Integer id_user (Integer) map.get(id);if (userID.equals(id_user)){categoryService.update(incategory);return Result.success();}else {return Result.error(您所要更改的分类不属于您);}}} 先对要更改的分类存不存在进行验证如果存在在进行身份验证都验证通过了就可以进行修改操作了 Service层 Overridepublic void update(Category category) {category.setUpdateTime(LocalDateTime.now());categoryMapper.update(category);} Mapper层 Update(update category set category_name #{categoryName} , category_alias #{categoryAlias} , update_time #{updateTime} where id #{id})void update(Category category); 对了要在实体类中给id加一个NotNull注解来验证 NotNullprivate Integer id;//主键ID 搞定收工  更新棋子分类和添加棋子分类_分组校验 由于我们在刚刚写修改棋子分类的时候给ID加上了notnull的注解导致了在每次检验CateGory对象的时候都会检验id是否为null而我们在写新增分类的时候由于id是会自增的所以我们并没有传入棋子id。这时刚刚的更改会导致新增分类接口无法正常使用为了解决这个问题我们就要用到分组校验 分组校验 把校验项进行归类分组在完成不同功能的时候校验指定组中的校验项 步骤 1.定义分组 使用接口来定义分组 例如我们要给category加add和update两个分组我们就可以在其实体类中定义如下两个分组 public interface Add{}public interface Update{} 2.定义校验项时指定归属的分组 如下例 NotNull(groups Update.class)private Integer id;//主键IDNotEmpty(groups {Update.class,Add.class})private String categoryName;//分类名称NotEmpty(groups {Update.class,Add.class})private String categoryAlias;//分类别名 可以看到分组可以同时指定多个用{}来承接  3.校验时指定要校验的分组 public Result add(RequestBody Validated(Category.Add.class) Category category){public Result update(RequestBody Validated(Category.Update.class) Category incategory){ 小优化 校验分组存在如下两条规则 1.如果某个校验项没有指定分组则默认属于Defult分组 2.分组之间可以继承A extends B则A中继承B中所有的校验项目 那么我们可以对上例进行如下优化 我们可以看到add和update的唯一区别就是对于ID非空的检验所以我们可以让其他所有校验直接进入Defult组并让我们自定义的两个分组都继承Defult组add独立的划入对于ID的飞控检查 Data public class Category {NotNull(groups Update.class)private Integer id;//主键IDNotEmptyprivate String categoryName;//分类名称NotEmptyprivate String categoryAlias;//分类别名private Integer createUser;//创建人IDJsonFormat(pattern TIME_REGEXP)private LocalDateTime createTime;//创建时间JsonFormat(pattern TIME_REGEXP)private LocalDateTime updateTime;//更新时间public interface Add extends Default {}public interface Update extends Default {}
http://www.dnsts.com.cn/news/111000.html

相关文章:

  • 网站等保需要几年一做协会网站建设的优势
  • 昆山小程序制作外国网站在内地做seo
  • 网站建站推荐电子商务网站建设与管理的理解
  • 中国核工业华兴建设公司网站网站开发90天
  • 网站自己维护wordpress怎么添加关键词
  • 做mip网站需要多钱wordpress字体风格
  • 河南映天建设网站网站的企业风采怎么做
  • 做软件挣钱的网站wordpress 筛选
  • 网站推广计划书范文网站开发包含上线吗
  • 郑州做网站易云巢瓷器网站怎么做
  • 做网站的流程方法成都专业网站搭建公司
  • 衡水购物网站制作江阴网站制作
  • 马鞍山天立建设网站汽车门户网站建设
  • app网站开发培训重庆机有哪些网站建设公司
  • 天动力网站开发视频制作课程
  • 重庆企业网站开发服务器未备案网站 赚钱
  • 文件链接 win wordpress网站建设优化加盟代理
  • wordpress 首页 插件夫唯老师seo
  • 网站建设加数据库网站流量不够怎么办
  • icp备案和网站不符qq空间钓鱼网站后台怎么做
  • 响应式相册网站模板下载网站降权表现
  • 网站建设公司项目介绍地方网站运营方案
  • 网站互动设计方式河北建设网网站
  • 网站建设与管理专业学什么平台建设包括什么
  • 网站搭建工具陕西省住房和城乡建设厅门户网站
  • 在线制作网站系统网站模板如何修改
  • 做外贸用什么视频网站网站开发项目工期流程
  • 那些网站权重高福建城乡建设网站查询
  • html5特效网站源码自己做的网站网页错位
  • 如何制作一网站医学类的网站做Google