Tag: request mapping

Spring @RequestMapping

我一直在Spring的@RequestMapping注释中看到这种参数value = “/redirect/{id}” 。 我一直在想这里{id}是什么? 这是某种Expression Language吗? 我看到的示例代码: @RequestMapping( value = “/files/{id}”, method = RequestMethod.GET ) public void getFile( @PathVariable( “id” ) String fileName, HttpServletResponse response ) { try { // get your file as InputStream InputStream is = new FileInputStream(“/pathToFile/”+ fileName); // copy it to response’s OutputStream IOUtils.copy( is, response.getOutputStream() ); response.flushBuffer(); } catch( […]

找到Spring mvc Ambiguous mapping。 无法映射控制器bean方法

我正在尝试构建一个应用程序,它可以列出数据库中的一些值,并在必要时使用Spring 4进行修改,添加,删除,并且我收到以下错误(仅当我的两个控制器文件中都存在“@Controller”注释时,如果我从其中一个文件中删除注释,但我在控制台中收到一条消息“找不到映射…在带有名称的dispatcherservlet中…”: INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping – Mapped “{[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}” onto public java.lang.String com.bookReview.app.BookController.editBook(int,org.springframework.ui.Model) WARN : org.springframework.web.context.support.XmlWebApplicationContext – Exception encountered during context initialization – cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0’: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map ‘reviewController’ bean method public java.lang.String com.bookReview.app.ReviewController.editReview(int,org.springframework.ui.Model) to {[/edit/{id}],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There […]

请求参数的自定义Spring注释

我想编写自定义注释,根据注释修改Spring请求或路径参数。 例如,代替此代码: @RequestMapping(method = RequestMethod.GET) public String test(@RequestParam(“title”) String text) { text = text.toUpperCase(); System.out.println(text); return “form”; } 我可以制作注释@UpperCase: @RequestMapping(method = RequestMethod.GET) public String test(@RequestParam(“title”) @UpperCase String text) { System.out.println(text); return “form”; } 它是否可能,如果是,我怎么能这样做?