首页 > 编程语言 > 详细

springMvc发布restFull风格的URL

时间:2016-08-27 00:20:05      阅读:224      评论:0      收藏:0      [点我收藏+]

  

package zpark.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import zpark.entity.User;

/**
 * @controller 单例
 * @Scope("prototype") 多例
 */
@Controller
@RequestMapping("/restFul")
public class RestFulController {

    /**
     * 多个参数:
     *         @PathVariable 获取{}中的值
     *      若方法参数名称和{}中变量名称不一致,需要在@PathVariable("name")指定名称。
     *     
     * @param id
     * @param name
     * http://localhost:9999/restFul/find/123/aa
     */
    
    @RequestMapping(value="/find/{myId}/{name}",method=RequestMethod.GET)
    public String test(@PathVariable(value="myId") Integer id,@PathVariable String name){
        System.out.println(id);
        System.out.println(name);
        return  "index";
    }
    
    /**
     * 一个参数
     * @param id
     * @param name
     * http://localhost:9999/restFul/json/123
     */
    @RequestMapping(value="/json/{id}")
    public String test1(@PathVariable Integer id, String name){
        System.out.println(id);
        System.out.println(name);
        return  "index";
    }
    
    
}

 

springMvc发布restFull风格的URL

原文:http://www.cnblogs.com/liuconglin/p/5811918.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!