這是我的問題,我需要用spring來映射AJAX請求。現在,我知道我需要這兩個傢伙:用spring處理ajax請求
HttpServletRequest,獲取客戶端發送給我的消息,並將其從JSON(最有可能)解析爲Map和HttpServletResponse以將消息發送到客戶端。 什麼我不知道的是正確的(簡單,簡潔)的方式來做到這一點...
下面是從springframework的網站代碼示例:
/**
* Normal comments here
*
* @@org.springframework.web.servlet.handler.metadata.PathMap("/foo.cgi")
* @@org.springframework.web.servlet.handler.metadata.PathMap("/baz.cgi")
*/
public class FooController extends AbstractController {
private Cruncher cruncher;
public FooController(Cruncher cruncher) {
this.cruncher = cruncher;
}
protected ModelAndView handleRequestInternal (
HttpServletRequest request, HttpServletResponse response) throws Exception {
return new ModelAndView("test");
}
}
這是很好的。除此之外,據我所看到的,我不能映射每個方法的URL在類中我會用這種同步請求做:
@Controller
@RequestMapping("/test")
public class ControllerTest {
@RequestMapping(value = "/test.htm", method = RequestMethod.GET)
public void showSearchView(Model model) {...}
...
}
我可以做一些簡單的AJAX請求?