一、依赖SpringMVC
package com.lava.lavafaq.controller; import java.io.BufferedReader; import java.io.IOException; import javax.annotation.Resource; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.lava.lavafaq.servic.IPersonService; import com.lava.lavafaq.utils.BaseHttpRequest; import com.lava.lavafaq.utils.HttpRequest; @Controller @RequestMapping("/api") public class ApiController { private static Logger logger = Logger.getLogger(UserController.class); @RequestMapping(value="get", method = RequestMethod.GET) @ResponseBody public String get(int id) { return "{"id":"1","name":"1111111111"}"; } @RequestMapping(value="post", method = RequestMethod.POST) @ResponseBody public String post(int id,HttpServletRequest request) throws Exception { String username=request.getParameter("username"); return "{"id":"1","name":"1111111111"}"; } }