使用注释会很容易:
@Controller
public class MyController {
@RequestMapping(value="/hitmycontroller", method= RequestMethod.OPTIONS)
public static void options(HttpServletRequest req,HttpServletResponse resp){
//Do options
}
@RequestMapping(value="/hitmycontroller", method= RequestMethod.GET)
public static void get(HttpServletRequest req,HttpServletResponse resp){
//Do get
}
}
但我找不到如何在 XML 中执行此操作。是否有一些映射处理程序会执行以下操作:
<bean id="handlerMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<mapping>
<url>/hitmycontroller</url>
<httpMethod>GET</httpMethod>
<method>get</method>
<controller>MyController</controller>
</mapping>
<mapping>
<url>/hitmycontroller</url>
<httpMethod>OPTIONS</httpMethod>
<method>options</method>
<controller>MyController</controller>
</mapping>
</property>
</bean>
任何指针将不胜感激。