如果我们在Spring Rest Controller中有多个参数,是否可以使用单个参数获取记录

时间:2018-08-24 09:39:22

标签: spring-restcontroller

这是我的控制器

@Path("/findResourcesBySearch/{primarySkills}/{jobCategory}/{location}/{experience}/{pageNo}/{pageSize}")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public com.ojas.ra.response.Response findResourcesBySearchs(@Context ServletContext context,
            @PathParam("primarySkills") String primarySkills, @PathParam("jobCategory") String jobCategory,
            @PathParam("location") String location, @PathParam("experience") String experience,
            @PathParam("pageNo") int pageNo, @PathParam("pageSize") int pageSize) {
        Map<String, Map<String, Integer>> allLists = null;
        try {
            MongoSortVO sort = new MongoSortVO();
            sort.setPrimaryKey("_id");
            sort.setPrimaryOrderBy(MongoOrderByEnum.DESC);

            String[] ar = primarySkills.split(",");
            Arrays.sort(ar);
            int i = 0;
            StringBuilder values = new StringBuilder();
            for (String string : ar) {
                values.append(string);
                i++;
                if (i != ar.length) {
                    values.append(",");
                }
            }
            String ps = values.toString();
            int count = resourceService.getCount(sort);
            int pages = resourceService.getPages(sort, pageSize);
            List<Resource> resourcelist = null;

            BasicDBObject andQuery = new BasicDBObject();
            List<BasicDBObject> c = new ArrayList<BasicDBObject>();
            c.add(new BasicDBObject("primarySkills", ps));
            c.add(new BasicDBObject("jobCategory", jobCategory));
            c.add(new BasicDBObject("currentLocation", location));
            c.add(new BasicDBObject("yearsOfExperience", experience));
            c.add(new BasicDBObject("status", "Active"));
            c.add(new BasicDBObject("hardLock", "No"));
            andQuery.put("$and", c);
            try {
                resourcelist = resourceService.findAllByCondition(andQuery, sort, pageNo, pageSize);
            } catch (RAException e) {
                e.getMessage();
            }

            if (null != resourcelist) {

                allLists = allTLists(resourcelist);
            }
            List<ResourceMapper> mapperList = null;
            try {
                mapperList = convertDomainToMapperList(resourcelist);
            } catch (RAException e) {
                e.getMessage();
            }
            if (null == mapperList || mapperList.size() == 0) {

                return new com.ojas.ra.response.Response(mapperList, allLists, pages, count, HttpStatus.OK,
                        "No records found");

            }

            return new com.ojas.ra.response.Response(mapperList, allLists, pages, count, HttpStatus.OK,
                    "records found");

        } catch (RAException e) {
            logger.error("No Records found" + e.getMessage());
            return new com.ojas.ra.response.Response(HttpStatus.CONFLICT, "records not found");
        }
    }

0 个答案:

没有答案