简体   繁体   中英

Restrict method on MultiActionController action

I have a MultiActionController with an action that I would only like to be reachable if the POST method is used.

public class MyController extends MultiActionController {

  public ModelAndView myAction(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    // I don't want to hit this code unless POST was used
  }

}

Is there a way to achieve this through annotations or am I stuck checking request.getMethod() ?

Use:

@RequestMapping(value={"action1","action2","action3"}, 
    method = RequestMethod.POST)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM