springmvc-pojo simple mapping

1. First use a jsp page to accept the input data.

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8" import="java.util.*" isELIgnored="false"%>
 3  
 4 <form action="addCategory">
 5  
 6     入库产品名称 :<input type="text" name="name" value=""><br />
 7     入库产品数量: <input type="text" name="number" value=""><br />
 8  
 9     <input type="submit" value="增加商品">
10 </form>

2. Design a pojo class for a category

 1 package pojo;
 2 
 3 public class Category {
 4     private int id;
 5     private String name;
 6     private int number;
 7     
 8     public int getId() {
 9         return id;
10     }
11     public void setId(int id) {
12         this.id = id;
13     }
14     
15     public String getName() {
16         return name;
17     }
18     public void setName(String name) {
19         this.name = name;
20     }
21     
22     public int getNumber() {
23         return number;
24     }
25     public void setNumber(int number) {
26         this.number = number;
27     }
28 }

3. Add a RequestMapping mapping "/addCategory"

 1 package controller;
 2 
 3 import org.springframework.stereotype.Controller;
 4 import org.springframework.web.bind.annotation.RequestMapping;
 5 import org.springframework.web.servlet.ModelAndView;
 6 
 7 import pojo.Category;
 8 
 9 @Controller
10 public class CategoryController {
11     @RequestMapping("/addCategory")
12     public ModelAndView add(Category category) {
13         ModelAndView mav = new ModelAndView("showCategory");
14         return mav;
15     }
16 
17 }

4. Display the results on the showCategory.jsp page

1  <% @ page language = " java " contentType = " text/html; charset=UTF-8 " 
2      pageEncoding = " UTF-8 " isELIgnored = " false " %> 
3   
4 Inventory product name: ${category.name } < br > 
5Number of products in stock: ${category.number}

 

During the actual operation, it was found that the "category.number" of the final result was not brought out. After inspection, it was found that the setNumber method in pojo did not pass in a parameter (int number).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325154261&siteId=291194637