11package org .baeldung .web .controller ;
22
3+ import java .util .ArrayList ;
34import java .util .HashMap ;
45import java .util .List ;
56import java .util .Map ;
1011import org .baeldung .persistence .model .User ;
1112import org .baeldung .persistence .service .impl .MyUserService ;
1213import org .baeldung .persistence .service .impl .UserService ;
14+ import org .baeldung .web .util .SearchCriteria ;
1315import org .springframework .beans .factory .annotation .Autowired ;
1416import org .springframework .stereotype .Controller ;
1517import org .springframework .web .bind .annotation .RequestMapping ;
@@ -33,13 +35,13 @@ public UserController() {
3335 @ RequestMapping (method = RequestMethod .GET , value = "/users" )
3436 @ ResponseBody
3537 public List <User > findAll (@ RequestParam (value = "search" , required = false ) final String search ) {
36- final Map < String , Object > params = new HashMap < String , Object >();
38+ final List < SearchCriteria > params = new ArrayList < SearchCriteria >();
3739
3840 if (search != null ) {
39- final Pattern pattern = Pattern .compile ("(\\ w+?): (\\ w+?)," );
41+ final Pattern pattern = Pattern .compile ("(\\ w+?)(:|<|>) (\\ w+?)," );
4042 final Matcher matcher = pattern .matcher (search + "," );
4143 while (matcher .find ()) {
42- params .put ( matcher .group (1 ), matcher .group (2 ));
44+ params .add ( new SearchCriteria ( matcher .group (1 ), matcher .group (2 ), matcher . group ( 3 ) ));
4345 }
4446 }
4547 return service .searchUser (params );
@@ -48,13 +50,13 @@ public List<User> findAll(@RequestParam(value = "search", required = false) fina
4850 @ RequestMapping (method = RequestMethod .GET , value = "/users/spec" )
4951 @ ResponseBody
5052 public List <User > findAllBySpecification (@ RequestParam (value = "search" , required = false ) final String search ) {
51- final Map < String , Object > params = new HashMap < String , Object >();
53+ final List < SearchCriteria > params = new ArrayList < SearchCriteria >();
5254
5355 if (search != null ) {
54- final Pattern pattern = Pattern .compile ("(\\ w+?): (\\ w+?)," );
56+ final Pattern pattern = Pattern .compile ("(\\ w+?)(:|<|>) (\\ w+?)," );
5557 final Matcher matcher = pattern .matcher (search + "," );
5658 while (matcher .find ()) {
57- params .put ( matcher .group (1 ), matcher .group (2 ));
59+ params .add ( new SearchCriteria ( matcher .group (1 ), matcher .group (2 ), matcher . group ( 3 ) ));
5860 }
5961 }
6062 return service .searchBySpecification (params );
0 commit comments