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

网站搜索优化方法老牛wordpress

网站搜索优化方法,老牛wordpress,九江网站开发公司,伊春百姓网免费发布信息网我们在写Rest API接口时候会用到很多的RequestParam和PathVariable进行参数的传递#xff0c;但是在校验的时候#xff0c;不像使用RequestBody那样的直接写在实体类中#xff0c;我们这篇文章讲解一下如何去校验这些参数。 依赖配置 要使用Java Validation API#xff0c;… 我们在写Rest API接口时候会用到很多的RequestParam和PathVariable进行参数的传递但是在校验的时候不像使用RequestBody那样的直接写在实体类中我们这篇文章讲解一下如何去校验这些参数。 依赖配置 要使用Java Validation API我们必须添加validation-api依赖项dependencygroupIdjavax.validation/groupIdartifactIdvalidation-api/artifactIdversion2.0.1.Final/version /dependency 通过添加Validated注解来启用控制器中的RequestParams和PathVariables的验证RestController RequestMapping(/) Validated public class Controller {// ... } 校验RequestParam 我们将数字作为请求参数传递给控制器方法GetMapping(/name-for-day) public String getNameOfDayByNumber(RequestParam Integer dayOfWeek) {// ... } 我们保证dayOfWeek的值在1到7之间我们使用Min和Max注解GetMapping(/name-for-day) public String getNameOfDayByNumber(RequestParam Min(1) Max(7) Integer dayOfWeek) {// ... } 任何与这些条件不匹配的请求都将返回HTTP状态500并显示默认错误消息。 如果我们尝试调用http://localhost:8080/name-for-day?dayOfWeek24这将返回以下响应信息 There was an unexpected error (typeInternal Server Error, status500). getNameOfDayByNumber.dayOfWeek: must be less than or equal to 7 当然我们也可以在Min和Max注解后面加上message参数进行修改默认的返回信息。 校验PathVariable 和校验RequestParam一样我们可以使用javax.validation.constraints包中的注解来验证PathVariable。 验证String参数不是空且长度小于或等于10GetMapping(/valid-name/{name}) public void test(PathVariable(name) NotBlank Size(max 10) String username) {// ... } 任何名称参数超过10个字符的请求都会导致以下错误消息There was an unexpected error (typeInternal Server Error, status500). createUser.name:size must be between 0 and 10 通过在Size注解中设置message参数可以覆盖默认消息。 其实我们可以看到校验RequestParam和PathVariable参数和我们校验RequestBody方式一致只不过一个是写在了实体中一个写在了外部当然我们也可以将RequestParam的参数写入到实体类中进行使用RequestParam注解进行引入比如我们使用一个分页的实例 分页实体类/*** Licensed to the Apache Software Foundation (ASF) under one* or more contributor license agreements. See the NOTICE file* distributed with this work for additional information* regarding copyright ownership. The ASF licenses this file* to you under the Apache License, Version 2.0 (the* License); you may not use this file except in compliance* with the License. You may obtain a copy of the License at* p* http://www.apache.org/licenses/LICENSE-2.0* p* Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an AS IS BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/ package com.zhuanqb.param.page;import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotEmpty;import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull;/*** PageParam br/* 描述 : PageParam br/* 作者 : qianmoQ br/* 版本 : 1.0 br/* 创建时间 : 2018-09-23 下午7:40 br/* 联系作者 : a hrefmailTo:shichengoooo163.comqianmoQ/a*/ Data ToString NoArgsConstructor AllArgsConstructor public class PageParam {NotNull(message 每页数据显示数量不能为空)Min(value 5)Max(value 100)private Integer size; // 每页数量NotNull(message 当前页显示数量不能为空)Min(value 1)Max(value Integer.MAX_VALUE)private Integer page; // 当前页数private Boolean flag true;} RequestParam调用方式 GetMapping(value list)public CommonResponseModel findAll(Validated PageParam param) {...} 这样的话可以使我们的校验定制化更加简单。
http://wiki.neutronadmin.com/news/150118/

相关文章:

  • 公司简介通用模板太原百度快速优化排名
  • jsp网站开发总结百度做网站多少钱能做
  • 自己做网站wordpress表单统计插件下载
  • 网站建设总体费用网页怎么做成app
  • 网站建设案例完整代码九江网站建设服务
  • 做网站电信运营许可证吉利网站建设
  • 服装网站html模板传媒有限公司
  • 网站说服力 营销...ps做网页
  • 织梦网站打不开软件推广平台
  • 云南做网站的公司有哪些做网站的心得
  • 网站的设计思路怎么写中装建设股票行情
  • 龙岗区住房和建设局在线网站公司网站运营方案策划
  • 搭建模板seo营销名词解释
  • 网站开发工具排行江西省建设厅教育网站
  • 新浪做网站库存管理系统软件
  • 系统网站怎么做的检测网站是否正常
  • 建一个收费网站 怎么收费成都今晚全部解封
  • 模板网站有哪几类公众号登录超时
  • 大型网站开发用的技术装修平台app
  • 学校网站php源码微信公众平台应用开发
  • 学校网站怎么做优化河南搜索引擎推广公司
  • 最好网站建设WordPress的数据库在哪
  • 营销推广费计入什么科目谷歌排名网站优化
  • 找网站建设需要问什么软件国外有哪些优秀的网站
  • 网站建设中企动力最佳a5公司备案查询网站
  • 网页设计做军事网站的感想南京电子商务网站开发公司
  • 和平东路网站建设施工队找工程
  • 网站单个页面紧张搜索引擎蜘蛛oa手机端
  • 做公司子网站的请示报告常州地区网页制作公司
  • 手机网站怎么优化关键词网站咋做