When doing business update, name the only name check, Problems and Solutions

1. When doing business update, when updating the name, you need to check whether there is the phenomenon of the same name exists. Problems encountered is that if a simple bean determine whether the agreement will lead to rename themselves also reported no repeat, if the size according to the size, sometimes not accurate. Resolve as follows:

2. When the parameters of the package, will pass an entity bean. This bean, after obtaining his name, and then look for a bean Gets a collection of classes in this list, the traversal his every bean, each id, if not the same id exists, it explained that it had the same name

3. follows, in this example, authc is updated bean. This embodiment pro test.

@RequestMapping ( "/ authcUpdate / {ID}" )
     public the Map authcUpdate (@Valid Authc authc, the BindingResult error) { 
        the Map <String, Object> = Map new new the HashMap <String, Object> (); 

        List <Authc> authcByResource = authcService .getAuthcByResource (authc); 

        IF (authcByResource.size ()> 0 ) {
             for (Authc authc2: authcByResource) {
                 // is determined there are no duplicates id, if any, of this section was modified data, if a new, described there are other duplicate data. 
                IF (authc2.getId ()! = authc.getId ()) { 
    
                    error.addError ( new new FieldError ( "authc", "Resource", "resource name repeated"
                }
            }
        }

 

Guess you like

Origin www.cnblogs.com/sdgtxuyong/p/12106936.html