Tag: 请求映射

@RequestMapping的产生对值的顺序敏感吗?

这个问题是基于这个问题 。 通过提供的评论,我编写了三种不同的测试来validation正确设置的内容类型。 @Test public void testGetImageJpg_ShouldSucceed() throws Exception { File testImage = new File(TestConstants.TEST_IMAGE_JPG); byte[] expectedBytes = IOUtils.toByteArray(new FileInputStream(testImage)); when(service.getImage(anyString(), anyString())).thenReturn(testImage); mockMvc.perform(get(“/getImage/id/bla.jpg”).sessionAttrs(session)) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.IMAGE_JPEG)) .andExpect(content().bytes(expectedBytes)); } @Test public void testGetImagePng_ShouldSucceed() throws Exception { File testImage = new File(TestConstants.TEST_IMAGE_PNG); byte[] expectedBytes = IOUtils.toByteArray(new FileInputStream(testImage)); when(service.getImage(anyString(), anyString())).thenReturn(testImage); mockMvc.perform(get(“/getImage/id/bla.png”).sessionAttrs(session)) .andExpect(status().isOk()).andExpect(content().contentType(MediaType.IMAGE_PNG)) .andExpect(content().bytes(expectedBytes)); } @Test public void testGetImageGif_ShouldSucceed() throws Exception […]

Spring MVC引用RequestMapping中的params变量

我有以下方法: @RequestMapping(value = “/path/to/{iconId}”, params=”size={iconSize}”, method = RequestMethod.GET) public void webletIconData(@PathVariable String iconId, @PathVariable String iconSize, HttpServletResponse response) throws IOException { // Implementation here } 我知道如何使用@PathVariable从RequestMapping传递变量“webletId”,但是如何从params引用变量“iconSize”? 非常感谢。