利用PostMan开发调试Restful API
下边的图片是postman发送不同类型的请求,注意url和参数的变化:

get

get


delete

delete


post

post


put

put


利用spring mvc实现restful api ,需要修改的部分:

@RestController
还有就是要注意参数获取的方式,

参考后端代码:

/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.sys.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.service.SystemService;
/**
 * 用户Controller
 * @author jeeplus
 * @version 2013-8-29
 */
@RestController
@RequestMapping(value = "/user")
public class UserController2 extends BaseController {
	@Autowired
	private SystemService systemService;
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public User viewGET(@PathVariable("id") String id) {
        User user = new User();
        user = systemService.getUser(id);
        System.out.println("get method");
        return user;
    }
	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public User viewDELETE(@PathVariable("id") String id) {
        User user = new User();
        user = systemService.getUser(id);
        System.out.println("delete method");
        return user;
    }
	@RequestMapping(value = "", method = RequestMethod.POST)
    public User viewPOST(@ModelAttribute("user")User users) {
        User user = new User();
        user = systemService.getUser(users.getId());
        System.out.println("post method");
        return user;
    }
	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public User viewPUT(@ModelAttribute("user")User users) {
        User user = new User();
        user = systemService.getUser(users.getId());
        System.out.println("put method");
        return user;
    }
}