guyeuro
V2EX  ›  问与答

SpringMVC 能把 url 上的一组 parameter 参数转成 pojo 吗?

  •  
  •   guyeuro · Jul 17, 2017 · 1918 views
    This topic created in 3246 days ago, the information mentioned may be changed or developed.

    譬如 @RequestMapping(value = "/userjudge") public String order(HttpServletResponse response,HttpServletRequest request, User user)

     class User{
         String id;
         int age;
         String name;
     }
     
     然后
     url 是 /userjudge?id="3fslajfdljf"&age=43
     
    这样,控制器匹配的时候能自动把 id="3fslajfdljf"&age=43 的信息转成一个 user 实例吗?
    
    5 replies    2017-07-17 15:36:08 +08:00
    raycloud
        1
    raycloud  
       Jul 17, 2017
    能,你试下不就知道了
    zhuyao
        2
    zhuyao  
       Jul 17, 2017
    难道你这样请求的时候,你的 user 是 null ?字段名相同应该 user 就是有值的
    viakiba
        3
    viakiba  
       Jul 17, 2017
    可以的 get 和 post 都试一试
    luban
        4
    luban  
       Jul 17, 2017
    可以
    Ouyangan
        5
    Ouyangan  
       Jul 17, 2017
    发帖的时间已经测试好了...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   887 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 21:55 · PVG 05:55 · LAX 14:55 · JFK 17:55
    ♥ Do have faith in what you're doing.