안녕하세요, 저는 봄 mvc 응용 프로그램을 만들고 있습니다. 스프링 컨텍스트는 컨트롤러 메서드를 잘못된 URL에 매핑하는 것 같습니다.봄 MVC URL 매핑
I했습니다 다음 컨트롤러 :
HelloWorldController
package com.springapp.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/hello")
public class HelloWorldController {
@RequestMapping(method = RequestMethod.GET)
public ModelAndView helloWorld() {
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
ContactsController
package com.springapp.controller;
import com.springapp.form.Contact;
import com.springapp.service.ContactService;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
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.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/contacts")
public class ContactsController {
@Autowired
private ContactService contactService;
@RequestMapping(method = RequestMethod.GET)
public String listContacts(Model map) {
map.addAttribute("contact", new Contact());
map.addAttribute("contactList", contactService.listContacts());
return "contact";
}
@RequestMapping(value="{contactId}", method=RequestMethod.GET)
public String showContact(@PathVariable("contactId") Integer contactId) {
contactService.getContact(contactId);
return "redirect:/contacts";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addContact(@ModelAttribute("contact") Contact contact, BindingResult result) {
contactService.addContact(contact);
return "redirect:/contacts";
}
@RequestMapping("/{contactId}/delete")
public String deleteContact(@PathVariable("contactId") Integer contactId) {
contactService.removeContact(contactId);
return "redirect:/contacts";
}
}
스프링 컨텍스트로 매핑됩니다 그러나 :
INFO: Mapped URL path [/contacts/new] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/new.*] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/new/] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/addContact] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/addContact.*] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/addContact/] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/delete/{contactId}] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/delete/{contactId}.*] onto handler 'contactsController'
INFO: Mapped URL path [/contacts/delete/{contactId}/] onto handler 'contactsController'
INFO: Mapped URL path [/hello] onto handler 'helloWorldController'
INFO: Mapped URL path [/hello.*] onto handler 'helloWorldController'
INFO: Mapped URL path [/hello/] onto handler 'helloWorldController'
이것들은 어디서 얻고 있습니까? new
과 addContact
패턴이 있습니까? 또한 /contacts
매핑이 없습니다.
당신의 질문에있는 로그는 당신의'ContactsController'에있는 맵핑과 일치하지 않기 때문에 매우 이상합니다. 같은 버전의 코드와 로그를 올리셨습니까? – davioooh
@ davioooh 덧붙여서 ContactsController에 이전에'addContact' 매핑을했는데, 나중에'add'만으로 업데이트했습니다. 보시다시피 나는'deleteContact'에 대한 매핑을 변경했지만 효과가 없습니다. –
Eclipse를 사용하여 프로젝트를 개발/실행하고 있습니까? – davioooh