@@ -39,11 +39,12 @@ public UserController() {
3939 super ();
4040 }
4141
42+ // API - READ
43+
4244 @ RequestMapping (method = RequestMethod .GET , value = "/users" )
4345 @ ResponseBody
4446 public List <User > findAll (@ RequestParam (value = "search" , required = false ) final String search ) {
4547 final List <SearchCriteria > params = new ArrayList <SearchCriteria >();
46-
4748 if (search != null ) {
4849 final Pattern pattern = Pattern .compile ("(\\ w+?)(:|<|>)(\\ w+?)," );
4950 final Matcher matcher = pattern .matcher (search + "," );
@@ -57,19 +58,15 @@ public List<User> findAll(@RequestParam(value = "search", required = false) fina
5758 @ RequestMapping (method = RequestMethod .GET , value = "/users/spec" )
5859 @ ResponseBody
5960 public List <User > findAllBySpecification (@ RequestParam (value = "search" ) final String search ) {
60- UserSpecificationsBuilder builder = new UserSpecificationsBuilder();
61- if (search != null) {
62- final Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),");
63- final Matcher matcher = pattern.matcher(search + ",");
64- while (matcher.find()) {
65- builder = builder.with(matcher.group(1), matcher.group(2), matcher.group(3));
66- }
61+ final UserSpecificationsBuilder builder = new UserSpecificationsBuilder ();
62+ final Pattern pattern = Pattern .compile ("(\\ w+?)(:|<|>)(\\ w+?)," );
63+ final Matcher matcher = pattern .matcher (search + "," );
64+ while (matcher .find ()) {
65+ builder .with (matcher .group (1 ), matcher .group (2 ), matcher .group (3 ));
6766 }
67+
6868 final Specification <User > spec = builder .build ();
69- if (spec == null)
70- return dao.findAll();
71- else
72- return dao.findAll(spec);
69+ return dao .findAll (spec );
7370 }
7471
7572 @ RequestMapping (method = RequestMethod .GET , value = "/myusers" )
@@ -91,6 +88,8 @@ public Iterable<MyUser> findAllByQuerydsl(@RequestParam(value = "search") final
9188 return mydao .findAll (exp );
9289 }
9390
91+ // API - WRITE
92+
9493 @ RequestMapping (method = RequestMethod .GET , value = "/users/new" )
9594 @ ResponseBody
9695 public long addUser (@ RequestParam ("first" ) final String first , @ RequestParam ("last" ) final String last , @ RequestParam ("age" ) final int age ) {
@@ -114,4 +113,5 @@ public long addMyUser(@RequestParam("first") final String first, @RequestParam("
114113 mydao .save (user );
115114 return user .getId ();
116115 }
116+
117117}
0 commit comments