zoukankan      html  css  js  c++  java
  • 测试开发进阶——spring boot——MVC——设置请求方式——参数校验——示例

    控制器:

    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访问:

     

    ===================================================================

    ===================================================================

    控制器:

    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:访问

     

     

  • 相关阅读:
    LeetCode 326. Power of Three
    LeetCode 324. Wiggle Sort II
    LeetCode 322. Coin Change
    LeetCode 321. Create Maximum Number
    LeetCode 319. Bulb Switcher
    LeetCode 318. Maximum Product of Word Lengths
    LeetCode 310. Minimum Height Trees (DFS)
    个人站点大开发!--起始篇
    LeetCode 313. Super Ugly Number
    LeetCode 309. Best Time to Buy and Sell Stock with Cooldown (DP)
  • 原文地址:https://www.cnblogs.com/xiaobaibailongma/p/15092415.html
Copyright © 2011-2022 走看看