Java @提交后的RequestMapping(method=RequestMethod.POST)获得HTTP状态405-请求方法';邮政';

Java @提交后的RequestMapping(method=RequestMethod.POST)获得HTTP状态405-请求方法';邮政';,java,spring,spring-mvc,Java,Spring,Spring Mvc,嗨,我在这个控制器里有一个有线行为。我有两种方法获取准备以html形式显示的信息和发布以获取反提交: 控制器: @Controller public class NotificationController { final String JSP_NOTIFICATION_01="pages/sendPush/createNotification"; final String JSP_NOTIFICATION_02="pages/sendPush/createNotifica

嗨,我在这个控制器里有一个有线行为。我有两种方法获取准备以html形式显示的信息和发布以获取反提交:

控制器:

@Controller
public class NotificationController {

    final String  JSP_NOTIFICATION_01="pages/sendPush/createNotification";
    final String  JSP_NOTIFICATION_02="pages/sendPush/createNotificationStep2";


    @RequestMapping(value ="/admin/notification/newNotification",method = RequestMethod.GET)
    public String newNotification( Map<String, Object> model, HttpServletRequest request) {

        //prepare  info to fill html form

        request.getSession().setAttribute("notificacion", notification);
        return JSP_NOTIFICATION_01;
    }


    @RequestMapping( value ="/admin/notification/sendNotification", method = RequestMethod.POST)
    public String saveNotification(@ModelAttribute("notForm") SendNotificationModel notForm,
                                      Map<String, Object> model,HttpServletRequest request) {


        //Get all information from HTML form

        System.out.println("llego.."+resultado);

        model.put("resultado", resultado);

        return JSP_NOTIFICATION_02;
    }   
}
我正在使用Spring4.1.3和tomcat8


谢谢

从控制器中删除@RequestMapping(value=“/admin/notification/sendNotification”)

从控制器中删除@RequestMapping(value=“/admin/notification/sendNotification”)

注释@RequestMapping可以在类和方法级别使用。在类级别使用时,它将应用于所有方法。例如,请参见下面的代码

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
    private final AppointmentBook appointmentBook;
    @RequestMapping(method = RequestMethod.GET)
    public Map<String, Appointment> get() {
        return appointmentBook.getAppointmentsForToday();
    }
    @RequestMapping(path = "/{day}", method = RequestMethod.POST)
    public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
        return appointmentBook.getAppointmentsForDay(day);
    }
}
@控制器
@请求映射(“/appoints”)
公共类任命控制人{
私人最终任命书任命书;
@RequestMapping(method=RequestMethod.GET)
公共地图获取(){
返回AppointBook.GetAppointsFortoday();
}
@RequestMapping(path=“/{day}”,method=RequestMethod.POST)
公共地图getForDay(@PathVariable@DateTimeFormat(iso=iso.DATE)日期日,模型){
返回任命书。GetAppointsForday(天);
}
}
如上所述,控制器代码/预约是相对的,适用于以下所有方法。方法开头的任何@RequestMapping都会添加到相对路径中。但是请注意,@RequestMapping在类级别不是必需的。查阅以下官方文件以进一步了解。

注释@RequestMapping可以在类和方法级别使用。在类级别使用时,它将应用于所有方法。例如,请参见下面的代码

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
    private final AppointmentBook appointmentBook;
    @RequestMapping(method = RequestMethod.GET)
    public Map<String, Appointment> get() {
        return appointmentBook.getAppointmentsForToday();
    }
    @RequestMapping(path = "/{day}", method = RequestMethod.POST)
    public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
        return appointmentBook.getAppointmentsForDay(day);
    }
}
@控制器
@请求映射(“/appoints”)
公共类任命控制人{
私人最终任命书任命书;
@RequestMapping(method=RequestMethod.GET)
公共地图获取(){
返回AppointBook.GetAppointsFortoday();
}
@RequestMapping(path=“/{day}”,method=RequestMethod.POST)
公共地图getForDay(@PathVariable@DateTimeFormat(iso=iso.DATE)日期日,模型){
返回任命书。GetAppointsForday(天);
}
}
如上所述,控制器代码/预约是相对的,适用于以下所有方法。方法开头的任何@RequestMapping都会添加到相对路径中。但是请注意,@RequestMapping在类级别不是必需的。查阅以下官方文件以进一步了解。

我修正了添加一个方法,success(GET)。在POST方法中,我放置了一个重定向并运行

参考文献

@RequestMapping(value=“/admin/notification/sendNotification”,method=RequestMethod.POST)
公共字符串saveNotification(@modeldattribute(“notForm”)SendNotificationModel notForm,
映射模型,HttpServletRequest(请求){
NotificationDetails newNot=newNotificationDetails();/(NotificationDetails)request.getSession().getAttribute(“NotificationDetails”);
字符串resultado=“Probando”;
System.out.println(“llego..”+resultado);
模型放置(“resultado”,resultado);
返回“重定向:/admin/notification/sendNotification/success”;
}
@RequestMapping(value=“/admin/notification/sendNotification/success”,method=RequestMethod.GET)
公共字符串成功(模型)
{
返回JSP_通知_02;
}

我修正了添加一个方法,success(GET)。在POST方法中,我放置了一个重定向并运行

参考文献

@RequestMapping(value=“/admin/notification/sendNotification”,method=RequestMethod.POST)
公共字符串saveNotification(@modeldattribute(“notForm”)SendNotificationModel notForm,
映射模型,HttpServletRequest(请求){
NotificationDetails newNot=newNotificationDetails();/(NotificationDetails)request.getSession().getAttribute(“NotificationDetails”);
字符串resultado=“Probando”;
System.out.println(“llego..”+resultado);
模型放置(“resultado”,resultado);
返回“重定向:/admin/notification/sendNotification/success”;
}
@RequestMapping(value=“/admin/notification/sendNotification/success”,method=RequestMethod.GET)
公共字符串成功(模型)
{
返回JSP_通知_02;
}

确保您为您的帖子提供了准确的参数method@koutuk那会有什么不同呢?为什么错误的参数会导致405?请确保为您的帖子提供准确的参数method@koutuk那会有什么不同呢?为什么错误的参数会导致405?对不起,我尝试在类中使用全局RequestMapping,在每个类中使用单独的method@kuhajeyan先生,你是个救命恩人,我花了好几个小时试图找到解决办法,这个简单的小把戏成功了,非常感谢!抱歉,我尝试在类中使用全局RequestMapping,并在每个method@kuhajeyan先生,你是个救命恩人,我花了好几个小时试图找到解决办法,这个简单的小把戏成功了,非常感谢!
@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
    private final AppointmentBook appointmentBook;
    @RequestMapping(method = RequestMethod.GET)
    public Map<String, Appointment> get() {
        return appointmentBook.getAppointmentsForToday();
    }
    @RequestMapping(path = "/{day}", method = RequestMethod.POST)
    public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) {
        return appointmentBook.getAppointmentsForDay(day);
    }
}
@RequestMapping( value ="/admin/notification/sendNotification", method = RequestMethod.POST)
public String saveNotification(@ModelAttribute("notForm") SendNotificationModel notForm,
                                  Map<String, Object> model,HttpServletRequest request) {

    NotificationDetails newNot = new NotificationDetails();//(NotificationDetails)request.getSession().getAttribute("notificacion");

    String resultado= "Probando" ;
    System.out.println("llego.."+resultado);

    model.put("resultado", resultado);

    return "redirect:/admin/notification/sendNotification/success";
}


@RequestMapping(value = "/admin/notification/sendNotification/success", method = RequestMethod.GET)
public String success(Model model)
{
    return JSP_NOTIFICATION_02;
}