Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot springboot中的restapi过滤_Spring Boot - Fatal编程技术网

Spring boot springboot中的restapi过滤

Spring boot springboot中的restapi过滤,spring-boot,Spring Boot,我在SpringBoot中有一个项目,在我的控制器中有许多具有类似功能的方法 搜索帖子、流行、最新等的方法,以及略有变化的URL,如- url 1-搜索/{topicId} url 2-搜索/popular/{topicId} url 3-搜索/最新/{topicId} 我想要的是在url中有一个带过滤器的方法,比如search/{topicId}?filter=popular 如何在spring boot中实现这一点?OOPs。。。它不依赖于SpringBoot。它只是一个URL映射…您可以接

我在SpringBoot中有一个项目,在我的控制器中有许多具有类似功能的方法

搜索帖子、流行、最新等的方法,以及略有变化的URL,如-

url 1-搜索/{topicId}

url 2-搜索/popular/{topicId}

url 3-搜索/最新/{topicId}

我想要的是在url中有一个带过滤器的方法,比如search/{topicId}?filter=popular

如何在spring boot中实现这一点?

OOPs。。。它不依赖于SpringBoot。它只是一个URL映射…您可以接受该类型作为请求参数,并可以根据业务进行处理。。。。。
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<>();

        }
}
@控制器 公共类图书管理员{ @GetMapping(value=“/search/{topicId}”) @应答器 公共列表getBooksByType(@RequestParam字符串类型){ 试一试{ 如果(“流行”。相等信号案例(类型)){ //做你的生意 }else if(“最新”。等效信号案例(类型)){ //做你的生意 } }捕获(例外e){ e、 printStackTrace(); } 返回新的ArrayList(); } }
使用