• SpringBoot接收前端参数


    SpringBoot接收前端参数的三种方法,首先第一种代码:
    @RestController public class ControllerTest { //访问路径:http://localhost:8080/hello/5 @GetMapping(value = "/hello/{id}") public String hello(@PathVariable("id") Integer id){ return "ID:" + id; } }

    第二种:

      可以通过注解@RequestParam("xxx")来绑定指定的参数,在这里声明的参数为ids,但是@RequestParam()注解中确实id,这个时候前端传的值就应该为id,如果前台传送的是ids的话,在这里是接收不到的。

    @RestController
    public class ControllerTest {
     //访问路径:http://localhost:8080/hello?id=1551
        @GetMapping(value = "/hello")
        public String hello(@RequestParam("id") Integer ids){
            return "ID:" + id;
        }
    }

    第三种像这种,如果传进来的参数为空的话,可以设置为默认的:

        //访问路径:http://localhost:8080/hello?id=1551
        @GetMapping(value = "/hello")   
        public String hello(@RequestParam(value = "id", required = false, defaultValue = "5") Integer id){       
               return "ID:" + id;
        }
  • 相关阅读:
    Mysql的相关命令
    设置数据窗口的过滤与排序
    org.springframework.web.servlet.DispatcherServlet noHandlerFound
    tomcatPluginV321.zip
    js获取modelandview的值
    cintanotes
    暗手机
    TASKCITY
    win commands
    book
  • 原文地址:https://www.cnblogs.com/wzb-liumangtu/p/12909821.html
Copyright © 2020-2023  润新知