我一直在从this website构建一个Spring webapp。当我运行教程代码时,应用程序运行完美。但是,当我运行我的改编版代码时,我收到以下错误:
我不知道为什么会这样;我已经有效地复制并粘贴了整个代码库,只是将数据更改为Campaign而不是Strategy。
这是我的配置类:
package com.bridge.campaignspring.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.bridge.campaignspring.model.Campaign;
import com.bridge.campaignspring.service.CampaignService;
@Controller
@RequestMapping(value="/campaign")
public class CampaignController {
@Autowired
private CampaignService campaignService;
@RequestMapping(value="/add", method=RequestMethod.GET)
public ModelAndView addCampaignPage() {
ModelAndView modelAndView = new ModelAndView("campaign-add");
modelAndView.addObject("campaign", new Campaign());
return modelAndView;
}
@RequestMapping(value="/add", method=RequestMethod.POST)
public ModelAndView addingCampaign(@ModelAttribute Campaign campaign) {
ModelAndView modelAndView = new ModelAndView("home");
campaignService.addCampaign(campaign);
String message = "Campaign was added sucessfully";
modelAndView.addObject("message", message);
return modelAndView;
}
@RequestMapping(value="/list")
public ModelAndView listOfCampaigns() {
ModelAndView modelAndView = new ModelAndView("campaign-list");
List<Campaign> campaigns = campaignService.getCampaigns();
modelAndView.addObject("campaigns", campaigns);
return modelAndView;
}
@RequestMapping(value="/edit/{id}", method=RequestMethod.GET)
public ModelAndView editCampaignPage(@PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("campaign-edit");
Campaign campaign = campaignService.getCampaign(id);
modelAndView.addObject("campaign", campaign);
return modelAndView;
}
@RequestMapping(value="/edit/{id}", method=RequestMethod.POST)
public ModelAndView editingCampaign(@ModelAttribute Campaign campaign, @PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("home");
campaignService.updateCampaign(campaign);
String message = "Campaign edited successfully";
modelAndView.addObject("message", message);
return modelAndView;
}
@RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
public ModelAndView deleteCampaign(@PathVariable Integer id) {
ModelAndView modelAndView = new ModelAndView("home");
campaignService.deleteCampaign(id);
String message = "Campaign deleted successfully";
modelAndView.addObject("message", message);
return modelAndView;
}
}
我无法访问我创建的任何已创建的.jsp。我只看到404错误。如果需要更多代码来解决此问题,请询问;我可以发布任何必要的东西。
编辑:这是我的CampaignController类:
onbeforeunload
答案 0 :(得分:0)
您的网址应包含 class Program
{
static void Main(string[] args)
{
Test a = Test.A;
}
}
enum Test
{
A = 1,
B = 1,
}
,...
网址由/campaign/add
@RequestMapping
答案 1 :(得分:0)
不完全确定发生了什么,但它可能是我的Tomcat配置中的内容。我删除了服务器然后重新添加它并且它有效。