The RESTful of Java EE

Source: Internet
Author: User
Tags http post

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

Related Article

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.