Springmvc-pojo Simple Mapping

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.