1.RESTful
A. Definition: A software architecture style, design style rather than a standard, but provides a set of design principles and constraints. It is mainly used for client and server interaction classes of software. The design based on this style of software can be more concise, more layered, more easy to implement caching mechanisms.
B. Four ways:
GET:/BLOG/1 HTTP get = Id=1 blog is generally used to read
DELETE:/BLOG/1 HTTP delete = delete id=1 blog for deletion
PUT:/BLOG/1 HTTP PUT and update id=1 blog for updates
Post:/blog HTTP POST + Add blog for adding and deleting changes
2. Steps to use
A. Myrest the jar package into the
B. Configuring in Web. xml
< servlet-mapping > < Servlet-name >myrest</servlet-name> <Url-pattern >/</url-pattern> </ Servlet-mapping>
C. Configuring in Myspring-servlet.xml
<Mvc:annotation-driven/> <mvc:resourcesMapping= "/img/**" Location= "/img/" /> <mvc:resourcesMapping= "/js/**" Location= "/js/" /> <mvc:resourcesMapping= "/css/**" Location= "/css/" /> <mvc:resourcesMapping= "/html/**" Location= "/html/" /> <Mvc:default-servlet-handler/>
And
<BeanID= "Myresourcehandler"name= "Myresourcehandler"class= "Org.springframework.web.servlet.resource.ResourceHttpRequestHandler"> < Propertyname= "Locations"value="/" /> < Propertyname= "Supportedmethods"> <List> <value>GET</value> <value>DELETE</value> <value>PUT</value> <value>POST</value> </List> </ Property> </Bean>
D. Jian Sqlmapconfig.xml
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE configurationpublic "-//mybatis.org//dtd Config 3.0//en" "Http://mybatis.org/dtd/mybatis-3-config.dtd" ><Configuration> <typealiases> < Packagename= "Com.wode.bean"/> </typealiases></Configuration>
E. In HTML
$ ("button"). Bind ("click",function() { $.ajax ({ "put", "."). /USER/UPDATE/13 ", data: {name:" Zhangsan ", Location:" Chengdu "}, function (msg) { "Data Saved:" + msg); })
Writing in F.controller
@RequestMapping ("/user" public Span style= "COLOR: #0000ff" >class Hellocontroller { // http://127.0.0.1 :8080/MYRESTFUL/USER/UPDATE/3 @RequestMapping (path="/update/{id} ", Method=requestmethod.put) public void upuser (@PathVariable ("id") int id,string name,string Location,printwriter pt) { // user modified System.out.println ("User performed update" +id+ "" +name+ "" +location); Pt.println ( "Hello World"
G. Note: The Put method also needs to be configured in Web. xml
<Filter> <Filter-name>Httpputformfilter</Filter-name> <Filter-class>Org.springframework.web.filter.HttpPutFormContentFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Httpputformfilter</Filter-name> <Servlet-name>Myrest</Servlet-name> </filter-mapping>
The RESTful of Java EE