11package  com .boylegu .springboot_vue .controller ;
22
33import  org .springframework .web .bind .annotation .RequestMapping ;
4+ import  org .springframework .web .bind .annotation .RequestMethod ;
45import  org .springframework .web .bind .annotation .RestController ;
56import  org .springframework .beans .factory .annotation .Autowired ;
6- import  org .springframework .web .bind .annotation .RequestMethod ;
7+ import  org .springframework .http .ResponseEntity ;
8+ import  org .springframework .http .HttpStatus ;
79
810import  com .boylegu .springboot_vue .dao .PersonsRepository ;
9- import  com .boylegu .springboot_vue .entities .Persons ;
1011
12+ import  java .util .Map ;
13+ import  java .util .HashMap ;
14+ import  java .util .ArrayList ;
1115
12- import  java .util .List ;
1316
1417@ RestController 
1518@ RequestMapping ("/api/persons" )
1619public  class  MainController  {
1720
21+     /** 
22+      * @api {GET} /api/persons/sex Get all sexList 
23+      * @apiName GetAllSexList 
24+      * @apiGroup Info Manage 
25+      * @apiVersion 1.0.0 
26+      * @apiExample {httpie} Example usage: 
27+      * <p> 
28+      * http /api/persons/sex 
29+      * @apiSuccess {String} label 
30+      * @apiSuccess {String} value 
31+      */ 
32+ 
1833    @ Autowired 
1934    private  PersonsRepository  personsRepository ;
2035
21-     @ RequestMapping (value = "/sex" , method  = RequestMethod .GET )
22-     public  List < Persons > getAll () {
36+     @ RequestMapping (value  =  "/sex" , method  = RequestMethod .GET )
37+     public  ResponseEntity <? > getAll () {
2338
24-         return  personsRepository .findAll ();
39+         ArrayList <Map <String , String >> results  = new  ArrayList <Map <java .lang .String , java .lang .String >>();
40+ 
41+         for  (Object  value  : personsRepository .findSex ()) {
42+             Map <String , String > sex  = new  HashMap <String , String >();
43+ 
44+             sex .put ("label" , value .toString ());
45+             sex .put ("value" , value .toString ());
46+             results .add (sex );
47+         }
48+         ResponseEntity <ArrayList <Map <String , String >>> responseEntity  = new  ResponseEntity <>(results ,
49+                 HttpStatus .OK );
50+         return  responseEntity ;
2551    }
52+ 
2653}
0 commit comments