spring boot——参数传递——设置请求方式——参数校验——示例
控制器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package com.awaimai.web; import org.hibernate.validator.constraints.*; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.Size; import java.util.Enumeration; @RestController @Validated public class kzq { @RequestMapping (value= "/test4" , method=RequestMethod.GET) public String test4( @Size (min = 2 ,max = 6 ,message = "姓名长度必须为2到6" ) @RequestParam ( "username" ) String name) { String s = name; return s; } } |
web访问:
===================================================================
===================================================================
控制器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package com.awaimai.web; import org.hibernate.validator.constraints.*; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.Size; import java.util.Enumeration; @RestController @Validated public class kzq { @RequestMapping (value= "/test4" , method=RequestMethod.GET) public String test4( @Size (min = 2 ,max = 4 ,message = "姓名长度必须为2到4" ) @RequestParam ( "name" ) String name, @Min (value = 3 ,message = "年龄最小为3" ) @Max (value = 5 ,message = "年龄最大为5" ) @RequestParam ( "age" ) Integer age) { return name+age; } } |
web:访问
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」