精华内容
下载资源
问答
  • @Valid注解是什么

    万次阅读 多人点赞 2018-07-09 21:31:30
    @Valid 用于验证注解是否符合要求,直接加在变量user之前,在变量中添加验证信息的要求,当不符合要求时就会在方法中返回message 的错误提示信息。 @RestController @RequestMapping("/user") public class ...

    @Valid

    用于验证注解是否符合要求,直接加在变量user之前,在变量中添加验证信息的要求,当不符合要求时就会在方法中返回message 的错误提示信息。

    @RestController
    @RequestMapping("/user")
    public class UserController {
        @PostMapping
        public User create (@Valid @RequestBody User user) {
            System.out.println(user.getId());
            System.out.println(user.getUsername());
            System.out.println(user.getPassword());
            user.setId("1");
            return user;
        }
    }    

    然后在 User 类中添加验证信息的要求:

    public class User {
        private String id;  
    
        @NotBlank(message = "密码不能为空")
        private String password;
    }
    

    @NotBlank 注解所指的 password 字段,表示验证密码不能为空,如果为空的话,上面 Controller 中的 create 方法会将message 中的"密码不能为空"返回。

    当然也可以添加其他验证信息的要求:

    限制说明
    @Null限制只能为null
    @NotNull限制必须不为null
    @AssertFalse限制必须为false
    @AssertTrue限制必须为true
    @DecimalMax(value)限制必须为一个不大于指定值的数字
    @DecimalMin(value)限制必须为一个不小于指定值的数字
    @Digits(integer,fraction)限制必须为一个小数,且整数部分的位数不能超过integer,小数部分的位数不能超过fraction
    @Future限制必须是一个将来的日期
    @Max(value)限制必须为一个不大于指定值的数字
    @Min(value)限制必须为一个不小于指定值的数字
    @Past限制必须是一个过去的日期
    @Pattern(value)限制必须符合指定的正则表达式
    @Size(max,min)限制字符长度必须在min到max之间
    @Past验证注解的元素值(日期类型)比当前时间早
    @NotEmpty验证注解的元素值不为null且不为空(字符串长度不为0、集合大小不为0)
    @NotBlank验证注解的元素值不为空(不为null、去除首位空格后长度为0),不同于@NotEmpty,@NotBlank只应用于字符串且在比较时会去除字符串的空格
    @Email验证注解的元素值是Email,也可以通过正则表达式和flag指定自定义的email格式

    除此之外还可以自定义验证信息的要求,例如下面的 @MyConstraint:

    public class User {
    
        private String id;
    
        @MyConstraint(message = "这是一个测试")
        private String username;
    
    }

    注解的具体内容:

    @Constraint(validatedBy = {MyConstraintValidator.class})
    @Target({ELementtype.METHOD, ElementType.FIELD})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface MyConstraint {
        String message();
        Class<?>[] groups() default {};
        Class<? extends Payload>[] payload() default {}; 
    }

    下面是校验器:

    public class MyConstraintValidator implements ConstraintValidator<MyConstraint, Object> {
        @Autowired
        private UserService userService;
        
        @Override
        public void initialie(@MyConstraint constarintAnnotation) {
            System.out.println("my validator init");
        }
        
        @Override
        public boolean isValid(Object value, ConstraintValidatorContext context) {
            userService.getUserByUsername("seina");
            System.out.println("valid");
            return false;
        }
    }

     

     

    展开全文
  • During register allocation, mark these as write-thru, and mark all defs as write-thru, ensuring that the stack value is always valid. Mark those defs with GTF_SPILLED (this the "reload" flag ...
  • <div><p>Is there a way to directly pass the audio stream through to the home app from the camera... does not appear to be valid.</p><p>该提问来源于开源项目:Sunoo/homebridge-camera-ffmpeg</p></div>
  • leetcode 65. Valid Number

    2018-06-21 14:19:06
    # State (1) - initial state (scan ahead thru blanks) { 'blank' : 1 , 'sign' : 2 , 'digit' : 3 , '.' : 4 }, # State (2) - found sign (expect digit/dot) { 'digit' : 3 , '.' : 4 }, # State ...

    Validate if a given string is numeric.

    Some examples:

    "0" => true

    " 0.1 " => true

    "abc" => false

    "1 a" => false

    "2e10" => true

    Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.

    Update (2015-02-10):

    The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button to reset your code definition.

    class Solution(object):
        def isNumber(self, s):
            """
            :type s: str
            :rtype: bool
            """
            #define DFA state transition tables
            states = [{},
                     # State (1) - initial state (scan ahead thru blanks)
                     {'blank': 1, 'sign': 2, 'digit':3, '.':4},
                     # State (2) - found sign (expect digit/dot)
                     {'digit':3, '.':4},
                     # State (3) - digit consumer (loop until non-digit)
                     {'digit':3, '.':5, 'e':6, 'blank':9},
                     # State (4) - found dot (only a digit is valid)
                     {'digit':5},
                     # State (5) - after dot (expect digits, e, or end of valid input)
                     {'digit':5, 'e':6, 'blank':9},
                     # State (6) - found 'e' (only a sign or digit valid)
                     {'sign':7, 'digit':8},
                     # State (7) - sign after 'e' (only digit)
                     {'digit':8},
                     # State (8) - digit after 'e' (expect digits or end of valid input) 
                     {'digit':8, 'blank':9},
                     # State (9) - Terminal state (fail if non-blank found)
                     {'blank':9}]
            currentState = 1
            for c in s:
                # If char c is of a known class set it to the class name
                if c in '0123456789':
                    c = 'digit'
                elif c in ' \t\n':
                    c = 'blank'
                elif c in '+-':
                    c = 'sign'
                # If char/class is not in our state transition table it is invalid input
                if c not in states[currentState]:
                    return False
                # State transition
                currentState = states[currentState][c]
            # The only valid terminal states are end on digit, after dot, digit after e, or white space after valid input    
            if currentState not in [3,5,8,9]:
                return False
            return True
    展开全文
  • summary: DFA package myapp.kit.leetcode.top200; import java.util.HashMap; import java.util.HashSet;... * https://leetcode.com/problems/valid-number/ * * Validate if a given string can be

    summary:

    DFA

    package myapp.kit.leetcode.top200;
    
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Map;
    import java.util.Set;
    
    /**
     *
     * 65
     * hard
     * https://leetcode.com/problems/valid-number/
     *
     * Validate if a given string can be interpreted as a decimal number.
     *
     * Some examples:
     * "0" => true
     * " 0.1 " => true
     * "abc" => false
     * "1 a" => false
     * "2e10" => true
     * " -90e3   " => true
     * " 1e" => false
     * "e3" => false
     * " 6e-1" => true
     * " 99e2.5 " => false
     * "53.5e93" => true
     * " --6 " => false
     * "-+3" => false
     * "95a54e53" => false
     *
     * Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one. However, here is a list of characters that can be in a valid decimal number:
     *
     * Numbers 0-9
     * Exponent - "e"
     * Positive/negative sign - "+"/"-"
     * Decimal point - "."
     * Of course, the context of these characters also matters in the input.
     *
     * Update (2015-02-10):
     * The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button to reset your code definition.
     *
     *
     * @author huangdingsheng
     * @version 1.0, 2020/7/8
     */
    public class valid_number_65 {
    
        public static boolean isNumber(String s) {
            // =======DFA=======
            Map<Integer, Map<String,Integer>> dfa = new HashMap<>();
            // construct DFA
            // state 0 : start, init state
            dfa.put(0, new HashMap<>());
            dfa.get(0).put(".", 3);
            dfa.get(0).put("digit", 2);
            dfa.get(0).put("sign", 1);
            dfa.get(0).put("end", 8);
            // state 1 : found sign
            dfa.put(1, new HashMap<>());
            dfa.get(1).put("digit", 2);
            dfa.get(1).put(".", 3);
            // state 2 : digit
            dfa.put(2, new HashMap<>());
            dfa.get(2).put("digit", 2);
            dfa.get(2).put(".", 4);
            dfa.get(2).put("e", 5);
            dfa.get(2).put("end", 8);
            // state 3 : found dot
            dfa.put(3, new HashMap<>());
            dfa.get(3).put("digit", 4);
            // state 4 : after dot
            dfa.put(4, new HashMap<>());
            dfa.get(4).put("digit", 4);
            dfa.get(4).put("e", 5);
            dfa.get(4).put("end", 8);
            // state 5 : found e
            dfa.put(5, new HashMap<>());
            dfa.get(5).put("digit", 7);
            dfa.get(5).put("sign", 6);
            // state 6 : sign after e
            dfa.put(6, new HashMap<>());
            dfa.get(6).put("digit", 7);
            // state 7 : digit after e
            dfa.put(7, new HashMap<>());
            dfa.get(7).put("digit", 7);
            dfa.get(7).put("end", 8);
            // state 8 : end
            dfa.put(8, new HashMap<>());
            dfa.get(8).put("end", 8);
    
            s = s.trim();
            Integer currState = 0;
            String key = "";
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if (Character.isDigit(ch)) {
                    key = "digit";
                } else if (ch == '.') {
                    key = ".";
                } else if (ch == 'e') {
                    key = "e";
                } else if (ch == '-' || ch == '+'){
                    key = "sign";
                } else {
                    key = "unknown";
                }
                if (!dfa.get(currState).containsKey(key)) {
                    return false;
                }
                currState = dfa.get(currState).get(key);
            }
    
            return currState == 2 || currState == 4 || currState == 7 || currState == 8;
        }
    
    
    //    #define DFA state transition tables
    //        states = [{},
    //                 # State (1) - initial state (scan ahead thru blanks)
    //                 {'blank': 1, 'sign': 2, 'digit':3, '.':4},
    //                 # State (2) - found sign (expect digit/dot)
    //                 {'digit':3, '.':4},
    //                 # State (3) - digit consumer (loop until non-digit)
    //                 {'digit':3, '.':5, 'e':6, 'blank':9},
    //                 # State (4) - found dot (only a digit is valid)
    //                 {'digit':5},
    //                 # State (5) - after dot (expect digits, e, or end of valid input)
    //                 {'digit':5, 'e':6, 'blank':9},
    //                 # State (6) - found 'e' (only a sign or digit valid)
    //                 {'sign':7, 'digit':8},
    //                 # State (7) - sign after 'e' (only digit)
    //                 {'digit':8},
    //                 # State (8) - digit after 'e' (expect digits or end of valid input)
    //                 {'digit':8, 'blank':9},
    //                 # State (9) - Terminal state (fail if non-blank found)
    //                 {'blank':9}]
    //
        public static void main(String[] args) {
            System.out.println(isNumber("-1."));
        }
    }
    

     

    展开全文
  • this.form.valid) { this.helper.makeFieldsDirtyAndTouched(this.form); } else { this.loader = true; // save data in online_payment_ipn this.paymentService.saveOnlinePaymentIpn({}, 'paypal') .subscribe...

    问题

    I want to submit form to external site by POSTing the input fields in old school way(non Ajax) , it submits too but Angular giving me error in console before jumping to external page.

    I used following code in HTML(template)

    In component

    onSubmit(obj: any) {

    if (!this.form.valid) {

    this.helper.makeFieldsDirtyAndTouched(this.form);

    } else {

    this.loader = true;

    // save data in online_payment_ipn

    this.paymentService.saveOnlinePaymentIpn({}, 'paypal')

    .subscribe(response => {

    obj.target.submit();

    }, (err: any) => {

    this.loader = false;

    this.helper.redirectToErrorPage(err.status);

    });

    }

    }

    Now first this form saves data in my site via normal reactive form post(ajax). Now after that I post to 3rd party like paypal whole form in Old way of submitting form but I am getting

    Form submission canceled because the form is not connected

    Any help is appreciated. @H.B. Thanks

    回答1:

    You probably should use onSubmit($event) and then cancel the event to your custom logic. You can access the form via event.target. Passing in this in an angular binding probably just does not work, i might be mistaken.

    回答2:

    use addEventListener("click", foo) on the submit button and call e.preventDefault() as the first line of function foo(); insert custom logic from there.

    来源:https://stackoverflow.com/questions/49446854/angular-2-4-how-to-post-html-form-not-ajax-thru-component-on-callback-of-1

    展开全文
  • Validate Credit Card Number

    千次阅读 2014-10-09 13:03:02
    Given a positive integer of up to 16 digits, return true if it is a valid credit card number, and false if it is not. Here is the algorithm: If there are an even number of digits, ...
  • VS2005 DRAWTEXT的使用

    千次阅读 2011-03-04 13:42:00
     ASSERT_VALID(pDoc); // TODO: 在此处为本机数据添加绘制代码 HDC hDC; //Drawtext 第一个参数hdc, hDC = pDC->m_hDC; //将pDC的变量赋给hDC RECT rcText; //LPCSTR *str="Hello"; rcText.left = 10; ...
  • Artistic Style 3.1

    2020-04-19 00:28:05
    The valid values are 0 thru 4 indents. The default value is 1 indent. --indent-labels OR -L Indent labels so that they appear one indent less than the current indentation level, rather than being ...
  • 点击 Dialog 上的按钮会路由到 WifiDialog.BUTTON_SUBMIT 分支,如果是已经连接成功的 Wi-Fi 则路由到 WifiDialog.BUTTON_FORGET 分支。WifiDialog.BUTTON_SUBMIT 分支进一步调用了 submit(…) 方法。...
  • memblock=debug [KNL] Enable memblock debug messages. load_ramdisk= [RAM] [Deprecated] lockd.nlm_grace_period=P [NFS] Assign grace period. Format: <integer> lockd.nlm_tcpport=N [NFS] ...
  • // to avoid such problems, just march thru the list in the reverse order. for (int i = mObservers.size() - 1; i >= 0; i--) { mObservers.get(i).onChanged(); } } 这里的mObservers 是一个list  ...
  • Base64工具类(加密、解密)

    万次阅读 2018-08-09 19:28:41
    // bits shift up by 6 each time thru shift += 6; // loop, with new bits being put in accum |= value; // at the bottom. if (shift >= 8) { // whenever there are 8 or more shifted in, shift -= 8; //...
  • // to avoid such problems, just march thru the list in the reverse order. for (int i = mObservers.size() - 1 ; i >= 0 ; i--) { mObservers.get(i).onChanged(); } } } /** * Invokes { @link ...
  • KeyEvent类

    2021-04-17 08:15:08
    static char CHAR_UNDEFINED--KEY_PRESSED and KEY_RELEASED events which do not map to a valid Unicode character use this for the keyChar value.static int KEY_FIRST--The first number in the range of ids ...
  • uboot中rtc顶层分析

    2015-08-14 08:34:20
    * Some basic checking for valid values is done, but this will not catch * all possible error conditions. */ int mk_date (char *datestr, struct rtc_time *tmp) { int len, val; char *ptr...
  • * Called when the data set is no longer valid and cannot be queried again, * such as when the data set has been closed. * 数据集不再有效并且不能被获取时调用,例如数据集被关闭 */ public void ...
  • + "valid. If the first close of a file fails, " + "it may remain open and will not be renamed."); tryCount = 1; } Preconditions.checkArgument(batchSize > 0, "batchSize must be ...
  • OTG驱动分析(一)

    千次阅读 2015-06-02 17:32:38
    前一段时间弄了2个礼拜的OTG驱动调试,感觉精神疲惫啊。主要原因还是自己对OTG功能不了解造成的。现在终于完成但是对实质原理还有些模糊。所以自己重新总结一下。因为自己是菜鸟,所以用菜鸟的白话方式分析。...
  • Deploy SCO IP using Powershell

    千次阅读 2013-09-26 15:43:10
    # Loop thru the table $r = $view.InvokeMethod("Fetch") while($r -ne $null) { # Add property and value to hash table $prop = $r.InvokeParamProperty("StringData",1) $value = $r....
  • 本文主要介绍CheckStyle 5.6.1版本的各个规则配置项目,这个版本的CheckStyle将样式规则分为了以下十七种类型: 1. Annotations(注解:5个) ...Annotation Use Style(注解使用风格) ...检查java
  • Artistic Style2.04

    2014-04-22 12:41:23
    Artistic Style 2.04 A Free, Fast and Small Automatic Formatter for C, C++, C++/CLI, C#, and Java Source Code Contents General Information Quick Start Usage ...Bracket St
  • // to avoid such problems, just march thru the list in the reverse order. for (int i = mObservers.size() - 1; i >= 0; i--) { mObservers.get(i).onChanged(); } } } 看一下他的方法说明:当数据被...
  • Oracle Metalink Notes Collection

    万次阅读 2012-06-30 18:02:28
    Note 375282.1 - There Must Be A Valid Blanket Purchase Agreement In Effect For The Item You Wish To Transact Note 336778.1 - Consignment Transactions Error With Must Be A Valid Blanket Purchase ...
  • The parameters listed below are only valid if certain kernel build options were enabled and if respective hardware is present. The text in square brackets at the beginning of each description states ...
  • 【转帖】passthru的说明书!!!

    千次阅读 2008-11-01 17:09:00
    To activate LBFO, ensure that '#ifdef __LBFO' is a valid statement (not commented out) in Passthru.h. Only when __LBFO is defined will the Passthru driver call the NdisMSetMiniportSecondary API. ...
  • 46 个非常有用的 PHP 代码片段 (1)

    千次阅读 2016-02-20 08:47:21
    在编写代码的时候有个神奇的工具总是好的!下面这里收集了 40+ PHP 代码片段,可以...  ... 1. 发送 SMS  ...在开发 Web 或者移动应用的时候,经常会遇到需要发送 SMS 给用户,或者因为登录原因,或者是为了发送信息。...
  • 申明如下: static const struct xt_table packet_filter = { .name = "filter", .valid_hooks = FILTER_VALID_HOOKS, .me = THIS_MODULE, .af = NFPROTO_IPV4, .priority = NF_IP_PRI_FILTER, };...
  • 【UEFI基础】UEFI SCSI Stack介绍

    千次阅读 2018-02-22 21:23:40
    // // The following fields are only valid for ATAPI/SATA device // UINT32 Channel; UINT32 Device; ATAPI_IDENTIFY_DATA IdentifyData; // // Scsi UNMAP command parameters information // SCSI_UNMAP_PARAM...
  •  // bits shift up by 6 each time thru  shift += 6; // loop, with new bits being put in  accum |= value; // at the bottom.  if ( shift >= 8 ) // whenever there are 8 or more shifted in,  {  ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,005
精华内容 402
关键字:

thruvalid