包依赖
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
写一个Book类
public class Book implements Serializable {
private Integer bid;
private String bname;
private String bauthor;
private String publisher;
private Double price;
private Integer cid;
private String cname;
}
使用BeanUtils将获取到的参数Map转化为Book 实体类
private void addBook(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
Map<String, String[]> parameterMap = req.getParameterMap();
Book book = new Book();
//
BeanUtils.populate(book, parameterMap);
System.out.println(book);
bookServi