SpringMVC之ModelAttribute的使用。

一、:

controller.java:

@ModelAttribute
	public void queryStudentById(Map<String,Object> map){
		Student student = new Student();
		student.setId(33);
		student.setName("靳晨晨");
		student.setAge(22);
		map.put("student",student);
	}
	
	
	
	@RequestMapping(value="testModelAttribute")
	public String testModelAttribute(Student student){
		student.setName("ls");
		System.out.println(student.getId()+","+student.getName()+","+student.getAge());
		return "success";
	}

  先查后更新。通过@ModelAttribute修饰的方法会在每次请求前先执行。并且该方法的参数map.put()可以将对象放入即将查询的参数中。

原文地址:https://www.cnblogs.com/jccjcc/p/14045250.html