文章目录
数据回写
- 数据回写:在做数据更新的时候服务端查询的数据自动填充到表单中。
默认方式
- 通过前面讲解的 Map Mode ModelMap绑定数据
通过Model方式
如果使用对象去接收客户端传来的数据,那么对象默认会被自动放到model中,在前端页面可以直接使用对象中的数据。
Book.java
package com.sxt.pojo;
public class Book {
private Integer bookId;
private String bookName;
private String author;
private int publicYear;
public Integer getBookId() {
return bookId;
}
public void setBookId(Integer bookId) {
this.bookId = bookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getPublicYear() {
return publicYear;
}
public void setPublicYear(int publicYear) {
this.publicYear = publicYear;
}
@Override
public String toString() {
return "Book [bookName=" + bookName + ", author=" + author + ", publicYear=" + publicYear + "]";
}
}
HelloController.java
package com.sxt.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind