基本Spring项目中找不到404错误

时间:2015-08-18 13:49:53

标签: java spring

我有一个项目,我在没有xml文件的情况下工作:

这是我的控制者:

@Controller
public class ContactController {

    private static List<Contact> contacts = new ArrayList<>();

    static {
        contacts.add(new Contact("Barack", "Obama", "barack.o@wh.com", "147-852-965"));
        contacts.add(new Contact("George", "Bush", "george.b@wh.com", "785-985-652"));
        contacts.add(new Contact("Bill", "Clinton", "bill.c@wh.com", "236-587-412"));
        contacts.add(new Contact("Ronald", "Reagan", "ronald.r@wh.com", "369-852-452"));
    }

    @RequestMapping(value = "hello", method = RequestMethod.GET)
    public String get(Model model) {

        ContactForm contactForm = new ContactForm();
        contactForm.setContacts(contacts);
        model.addAttribute( "contactForm", contactForm);
        return "add_contact";
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(@ModelAttribute ContactForm contactForm, Model model) {

        List<Contact> contactList = contactForm.getContacts();
        if(contactList != null && contactList.size() > 0) {
            contacts = contactList;
        }

        return "show_contact";
    }
}

这是我的WebConfig.java文件:

@Configuration
@EnableWebMvc
@ComponentScan("controller")
public class WebConfig extends WebMvcConfigurerAdapter {

    @Bean
    public ViewResolver viewResolver() {

        InternalResourceViewResolver resolver
                = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        return resolver;

    }
}

我已正确编辑项目属性:

Project properties

这是我的项目结构:

Project structure

当我尝试运行项目时,我收到404未找到错误,是什么导致了这个?

0 个答案:

没有答案