Introduction to Spring MVC annotated Development

Source: Internet
Author: User
Tags lenovo

Java class

Package Com.cloud.po;import Java.util.date;public class Items {private Integer ID;    private String name;    Private Float Price;    Private String pic;    Private Date Createtime;    Private String detail;    Public Integer getId () {Returnid;    } public void SetId (Integer id) {this.id = ID;    } public String GetName () {return name;    } public void SetName (String name) {this.name = name = = null? Null:name.trim ();    } public Float GetPrice () {return price;    } public void Setprice (Float price) {this.price = Price;    } public String Getpic () {return pic;    } public void Setpic (String pic) {this.pic = pic = null? Null:pic.trim ();    Public Date Getcreatetime () {return createtime;    } public void Setcreatetime (Date createtime) {this.createtime = Createtime;    } public String Getdetail () {return detail;   } public void Setdetail (String detail) {     This.detail = detail = = null?    Null:detail.trim (); }}

 spring MVC configuration file

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:mvc=" Http://www.springframework.org/schema/mvc "xmlns:context="/HTTP/ Www.springframework.org/schema/context "xmlns:aop=" HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP "xmlns:tx="/HTTP/ Www.springframework.org/schema/tx "xsi:schemalocation=" Http://www.springframework.org/schema/beans/http Www.springframework.org/schema/beans/spring-beans-3.2.xsd Http://www.springframework.org/schema/mvc HTTP://WWW.S Pringframework.org/schema/mvc/spring-mvc-3.2.xsd Http://www.springframework.org/schema/context http://www.spring Framework.org/schema/context/spring-context-3.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP HTTP://WWW.SPRINGF Ramework.org/schema/aop/spring-aop-3.2.xsd Http://www.springframework.org/schema/tx HTTP://WWW.SPRINGFRAMEWORK.O Rg/schema/tx/spring-tx-3.2.xsd "> <!--Annotation development SPRINGMVC mode--<!--annotation map--<bean class= "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> <!--Note Adapter--<bean class= "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAd Apter "/> <!--can replace the above 2 configurations: There will also be a default load of many parameter bindings, the actual development of the selection--<!--&LT;MVC:ANNOTATION-DRIVEN&GT;&LT;/MV         C:annotation-driven>-<!--can scan controller, service 、... Here let scan controller, specify controller's package--<context:component-scan base-package= "Com.cloud.ctroller" ></conte Xt:component-scan></beans>

  writing hander

Package Com.cloud.ctroller;import Java.util.arraylist;import Java.util.list;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.servlet.modelandview;import Com.cloud.po.Items; @Controllerpublic class itemcontroller2{@ Requestmapping ("/queryitems") public Modelandview Queryitems (httpservletrequest request, HttpServletResponse Res      Ponse) throws Exception {//create several static data list<items> itemslist = new arraylist<items> ();      Populate the list with static data items Items_1 = new items ();      Items_1.setname ("Lenovo Notebook");      Items_1.setprice (6000F); Items_1.setdetail ("ThinkPad T430 Lenovo notebook PC!        ");      Items items_2 = new items ();      Items_2.setname ("Apple mobile");      Items_2.setprice (5000F); Items_2.setdetail ("Iphone6 Apple phone!      ");      Itemslist.add (Items_1);      Itemslist.add (items_2); ReturnBack to Modelandview modelandview Modelandview = new Modelandview ();      Modelandview.addobject ("Itemslist", itemslist);      Specifies an attempt to modelandview.setviewname ("/web-inf/jsp/items/itemslist.jsp");   return modelandview; }}

Front-End Presentation page

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%@ taglib uri=" Http://java.sun.com/jsp/jstl/core "prefix=" C "%><% @ taglib uri= "http://java.sun.com/jsp/jstl/fmt" prefix= "FMT"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Introduction to Spring MVC annotated Development

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.