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 <formAction= "Addcategory">5 6Storage Product Name:<inputtype= "text"name= "Name"value=""><BR/>7Number of inbound Products:<inputtype= "text"name= "Number"value=""><BR/>8 9 <inputtype= "Submit"value= "Add Product">Ten </form>
2. Design a category of Pojo class
1 PackagePojo;2 3 Public classCategory {4 Private intID;5 PrivateString name;6 Private intNumber ;7 8 Public intgetId () {9 returnID;Ten } One Public voidSetId (intID) { A This. ID =ID; - } - the PublicString GetName () { - returnname; - } - Public voidsetName (String name) { + This. Name =name; - } + A Public intGetNumber () { at returnNumber ; - } - Public voidSetnumber (intNumber ) { - This. Number =Number ; - } -}
3. Add a requestmapping map "/addcategory"
1 PackageController;2 3 ImportOrg.springframework.stereotype.Controller;4 Importorg.springframework.web.bind.annotation.RequestMapping;5 ImportOrg.springframework.web.servlet.ModelAndView;6 7 ImportPojo. Category;8 9 @ControllerTen Public classCategorycontroller { One@RequestMapping ("/addcategory") A PublicModelandview Add (category category) { -Modelandview Mav =NewModelandview ("Showcategory"); - returnMav; the } - -}
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 4Inbound Product Name: ${category.name}<BR>5Number of inbound products: ${category.number}
During the actual operation, the "Category.number" found in the final result is not brought out. The check was found to be because the Setnumber method in Pojo did not pass in the parameter (int number).
Springmvc-pojo Simple Mapping