두 번째 요청에 대해 ModelAttribute를 가져올 수 없습니다. 첫 번째 요청은 initForm() 메소드입니다. Command 객체를 준비했고 jsp에서 명령을 표시 할 수있었습니다.봄에 modelAttribute를 채울 수 없습니다.
initForm()을 통해 나는 ajax 호출을 수행 할 때 editForm에서 원하는 명령과 명령을 채 웁니다. 내가 컨트롤러의 editForm()
을 이동하는 방법 아약스 호출이
function editStudentDetails(studentId,index){
$.ajax(
{url:"editstudentdetails.htm",
method:"GET",
data:{"action":"edit","id":studentId,"index":index},
success: function(data) {
jQuery("#studentDetailsDiv").html(data)
}
}
)
}
방법 editStudentDetails()
에서 :
여기 내 봄 양식
<form:form method="POST" action="addstudentdetails.htm" commandName="command">
Ignore what is inside this
Name: Shoaib Age:23 <a href="#" onclick="editstudentdetails(1,0)">edit</a>
</form:form>
내 아약스 요청입니다.
@Controller
public class StudentDetailsController {
@Autowired
private StudentDetailsDAO studentDetailsDAO;
@RequestMapping(value="/studentdetails.htm",method = RequestMethod.GET)
public String initForm(HttpServletRequest request,ModelMap map){
String action=request.getParameter("action");
StudentDetailsCommand command=new StudentDetailsCommand();
System.out.println("in controller"+action);
command.setStudents(studentDetailsDAO.findAll());
map.addAttribute("command", command);
return "studentdetails";
}
@RequestMapping(value="/editstudentdetails.htm",method = RequestMethod.GET)
public String editForm(ModelMap map,HttpServletRequest request){
map.addObject("index", request.getParameter("index"));
StudentDetailsCommand command=(StudentDetailsCommand)map.get("command");
System.out.println(command);
System.out.println(command.getStudents());//NullPointerException here.
map.addObject("command", command);
return "studentdetails";
}
}
심지어 @ModelAttribute ("studentDetailsCommand")을 시도했지만 작동하지 않았다 :
여기 내 컨트롤러입니다.
저는 스프링 3.0을 처음 접했고 여기에 제공된 모든 해결책을 따랐지만 아무 것도 효과가 없었습니다. 아무도 도와 주실 수 없습니까?
두 번째 요청은 무엇입니까? 어떤 모델 속성에 대해 이야기하고 있습니까? –
editForm 메서드에서 오는 아약스 호출에 의해 두 번째 요청이 map.get ("xxx") –
통해 얻는 편집 링크를 클릭하면 아약스 요청을 내가 send.Let 날 그 아약스 메서드를 너무 추가 할 수 있습니다. –