SPRINGMVC RESTful style operation

Source: Internet
Author: User

SSM Framework

Controller

 PackageCom.sgcc.controller;Importjava.util.ArrayList;Importjava.util.List;ImportOrg.omg.CORBA.PUBLIC_MEMBER;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.ModelMap;Importorg.springframework.web.bind.annotation.PathVariable;Importorg.springframework.web.bind.annotation.RequestMapping;ImportCom.sgcc.entity.User, @Controller @requestmapping ("/user")//Narrow--sub-module development, team Collaboration--note page jump Plus/or view resolver Public classUsercontroller {Privatelist<user> list =NewArraylist<user>();  PublicUsercontroller () {List.add (NewUser (1, "Zhang San", "1111")); List.add (NewUser (2, "John Doe", "1111")); List.add (NewUser (3, "Harry", "3333")); }    //Query All Users@RequestMapping ("/list")     PublicString list (Modelmap map) {Map.addattribute ("List", list); //System.out.println (list.tostring ());        return"/list.jsp"; }    //Add User@RequestMapping ("/add")     PublicString Add (user user) {User.setid (List.get () list.size ()-1). GetId () +1);        List.add (user); //return "/user/list.do"        return"Redirect:list.do"; }    //Delete User@RequestMapping ("/delete")     PublicString Delte (intID) {         for(inti = 0; I < list.size (); i++) {            if(List.get (i). GetId () = =ID) {list.remove (i);  Break; }        }        return"Redirect:list.do"; }    //Traditional URL Delete? id=123;//the development of restful style delete/123//url/user/123/delete1@RequestMapping ("/{id}/delete1")     PublicString Delete1 (@PathVariableintID) {         for(inti = 0; I < list.size (); i++) {            if(List.get (i). GetId () = =ID) {list.remove (i);  Break; }        }        return"Redirect:/user/list.do"; }}

Front:

<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8"%><% @taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >

SPRINGMVC RESTful style operation

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.