Spring 2.5 에서 커맨드 클래스를 사용하는 예
package annotation;
import org.springframework.stereotype.*;
import org.springframework.validation.*;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.*;
import command.LoginCommand;
@Controller
public class AnnotationCmdController {
@RequestMapping("/annotation/login.htm")
public ModelAndView login(@ModelAttribute("lc")LoginCommand lc, BindingResult errors){
/*위의 @ModelAttribute("lc")부분을 생략해도 커맨드 객체는 뷰까지 전달된다.
*그러나 객체의 이름은 'loginCommand' 으로 자동으로 설정된다.
*위의 경우, 객체의 이름은 'lc' 으로 설정된다
*/
ModelAndView mav = new ModelAndView("annotation/loginSuccess");
mav.addAllObjects(errors.getModel());
return mav;
}
}