在春季启动时休息api过滤

时间:2018-04-12 16:00:49

标签: spring-boot

我有一个春季启动项目,在我的控制器中我有很多具有类似功能的方法。

搜索帖子,热门,最新等的方法以及略有变化的网址,如

url 1 - search / {topicId}

url 2 - search / popular / {topicId}

url 3 - search / latest / {topicId}

我想要的是,在搜索/ {topicId}这样的网址中设置一个带过滤器的方法?filter = popular

如何在春季靴子中实现这一目标?

1 个答案:

答案 0 :(得分:1)

OOPs... it does not depend on SpringBoot. It is simply a URL mapping...You can accept the type as a request param and can process as per business.....

@Controller
public class BookController {

        @GetMapping(value = "/search/{topicId}")
        @ResponseBody
        public List<Object> getBooksByType(@RequestParam String type) {
            try{
                if("popular".equalsIgnoreCase(type)){
                    //do your business stuffs                   
                }else if ("latest".equalsIgnoreCase(type)){
                    //do your business stuffs
                }
            }catch(Exception e){
                e.printStackTrace();
            }

            return new ArrayList<>();

        }
}