zoukankan      html  css  js  c++  java
  • RestTemplate的异常:Not enough variables available to expand

    原因:RestTemplate使用出错,我的情况是不知道这里要求用RestTemplate的使用格式,应该很多人都是这样吧?不过,看了下RestTemplate,感觉其实还是很好用的。

    RestTemplate是一种使用格式,正确的格式为

    mockMvc.perform(MockMvcRequestBuilders
                    .post("/lookRecord/delete/{collectId}", "8")
                    .accept(MediaType.APPLICATION_JSON))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andDo(MockMvcResultHandlers.print())
                    .andReturn();
    
    直接传值
    mockMvc.perform(MockMvcRequestBuilders .post("/lookRecord/delete/8") .accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()) .andReturn();

     错误的格式,不要使用转义符

    mockMvc.perform(MockMvcRequestBuilders
                    .post("/lookRecord/delete/{"collectId"}","8")
                    .accept(MediaType.APPLICATION_JSON))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andDo(MockMvcResultHandlers.print())
                    .andReturn();
    

     不要忘记传值

     mockMvc.perform(MockMvcRequestBuilders
                    .post("/lookRecord/delete/{collectId}")
                    .accept(MediaType.APPLICATION_JSON))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andDo(MockMvcResultHandlers.print())
                    .andReturn();
    

     错误的直接传值

     mockMvc.perform(MockMvcRequestBuilders
                    .post("/lookRecord/delete/{8}")
                    .accept(MediaType.APPLICATION_JSON))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andDo(MockMvcResultHandlers.print())
                    .andReturn();

    简易理解的方式为

    String data= {""name":"jack","age":18"};
    String url = "http://localhost:8080/search?people={data}";
     mockMvc.perform(MockMvcRequestBuilders
                    .post(url,data)
                    .accept(MediaType.APPLICATION_JSON))
                    .andExpect(MockMvcResultMatchers.status().isOk())
                    .andDo(MockMvcResultHandlers.print())
                    .andReturn();
    
  • 相关阅读:
    Codeforces 1528E Mashtali and Hagh Trees
    Codeforces Round #709 (Div. 1, based on Technocup 2021 Final Round)
    Codeforces 1517G Starry Night Camping
    Codeforces 1508E Tree Calendar
    Codeforces 1508D Swap Pass
    Codeforces 1511G Chips on a Board
    Codeforces 1511F Chainword
    Codeforces 1516E Baby Ehab Plays with Permutations
    CF1539A Contest Start 题解
    关于 manacher
  • 原文地址:https://www.cnblogs.com/ydymz/p/8462581.html
Copyright © 2011-2022 走看看