-
@RequestMapping(value = "/reset", method = RequestMethod.POST) 访问方式5
如题,@RequestMapping(value = "/reset", method = RequestMethod.POST)设置了POST访问方式,但是如果用GET访问会有异常,请问我该怎么捕捉这个异常呢?
偶是新手,请有知道的尽量说的详细点,谢谢~2013年5月16日 11:28
1个答案 按时间排序 按投票排序
-
使用@ExceptionHandler(RuntimeException.class)这个注解,定义一个捕获异常并且处理的方法。括号内的是异常类型,修改成你的异常类型就行了
。
例如:
@Controller
public class AccessController {
/**
* 异常页面控制
*
* @param runtimeException
* @return
*/
@ExceptionHandler(RuntimeException.class)
public String runtimeExceptionHandler(RuntimeException runtimeException,
ModelMap modelMap) {
logger.error(runtimeException.getLocalizedMessage());
modelMap.put("status", IntegralConstant.FAIL_STATUS);
return "exception";
}
}2013年5月16日 16:10
相关推荐
Spring HATEOAS 是一个用于支持实现超... @RequestMapping(value = "/{person}", method = RequestMethod.GET) public HttpEntity<PersonResource> show(@PathVariable Long person) { … } } 标签:Spring
@RequestMapping(path="/check",method = RequestMethod.POST) public ModelAndView createUser(User user){ … } } @RequestMapping注解也可以单独定义在方法上,此时的url相对于应用根目录,例如: 类上未注解@ ...
@RequestMapping(value = "${path}",method = RequestMethod.POST) String sendBaiduPost(@PathVariable(value = "path") String path, @RequestBody Map,Object> param, @Header(key="token") String token); }
@RequestMapping(value="/delUser.do",method={RequestMethod.POST,RequestMethod.GET},consumes="application/json; charset=UTF-8") @ResponseBody public ModelAndView delUser(@RequestParam(required = true...
@RequestMapping(value="/list",method = RequestMethod.GET) public String list(Model model){ //获取列表页 List<Seckill> list=seckillService.getSeckillList(); model.addAttribute("list",list); //...
@RequestMapping(value = "ViewController") class ViewController { //@Resource //private ComboPooledDataSource comboPooledDataSource; //@Resource //private JdbcTemplate jdbcTemplate; @RequestMapping("/...
%=request.getContextPath()%>/login2.do"提交表单页面发送login2.do请求,而LoginControlle类中r的@RequestMapping("/login2.do")注解请求映射路径login2.do进行转发;前提是页面表单提交那个请求路径,就要在...
@RequestMapping(value="/userList1.do") public String geUserList1(HttpServletRequest request ,HttpServletResponse response) throws Exception { List<User> lists=userService.getListUsers(); if...
@RequestMapping(params = "method=createTopic",method = RequestMethod.POST) public String createTopic(){ System.out.println("call createTopic method."); return "createTopic"; } }
@RequestMapping(value="/dologin",method=RequestMethod.POST) public String doLogin(@RequestParam String devCode,@RequestParam String devPassword,HttpServletRequest request,HttpSession session){ ...
@RequestMapping(value="/file") public class FileController { @Resource private User user; @RequestMapping(value="/toUpload") public String toUpload(){ return "/upload"; } @RequestMapping...
根据读@requestmapping源码,理解实现原理后,自己写的简单的仿@requestmapping的代码,将该代码放置到自己的工程中就可以用。
SpringMVC@RequestMapping(重点)@RequestParam@PathVariable示例
@RequestMapping("/toUserEdit") public String toUserEdit(Integer user_id, Model model){ //放进model User user = userService.findUserById(user_id); model.addAttribute("user", user); // model....
@RequestMapping("/jpatest") public String jpaTest(ModelMap modelMap){ userRepository.save(new User("python","123456","xxxxx@126.com")); List<User> users = userRepository.findAll(); modelMap.put(...
前段时间项目中用到了REST风格来开发程序,但是当用POST、PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为application/json, 而且服务器端通过request....
利用反射获取requestMapping注解的value,springMvc实现路径映射功能的逻辑
性能:示例代码:@RequestMapping("/adder-service") public class AdderService { @RequestMapping("/add/{0}/{1}") public int add(@PathVariable int a, @PathVariable int b) {... } ...
public String method3(@RequestParam(value="username",defaultValue="",required=false) String username, @RequestParam(value="",defaultValue="",required=false)String password , HttpSession session ){...