controller接收httpclient请求

来源:互联网 发布:ios 仿淘宝详情页 编辑:程序博客网 时间:2024/04/30 14:47
  1. 如果controller放在现有的项目中, 要绕过登录验证
  2. 要responseBody返回xml需要配置applicationContext-mvc配置文件增加<mvc:annotation-driven/>
  3. 实体类加xml注解
@Controller@RequestMapping("appTestVpn")public class AppTestVpnController  extends BaseController{    @RequestMapping(value="testVpn",method=RequestMethod.POST)      @ResponseBody          public Coffee testVpn() {        try {            BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(),Charset.forName("GBK")));            StringBuilder sb1 = new StringBuilder();            String line = null;            while ((line = in.readLine()) != null) {               sb1.append(line);            }            String jstr=sb1.toString();             //读取客户端发送来的信息            System.err.println(jstr);        } catch (IOException e) {            e.printStackTrace();        }        System.err.println("ssss");        Coffee coffee = new Coffee("蓝山", 100);        return coffee;    }}
import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;@XmlRootElement(name = "coffee")public class Coffee {    String name;    int quanlity;    public String getName() {        return name;    }    @XmlElement    public void setName(String name) {        this.name = name;    }    public int getQuanlity() {        return quanlity;    }    @XmlElement    public void setQuanlity(int quanlity) {        this.quanlity = quanlity;    }    public Coffee(String name, int quanlity) {        this.name = name;        this.quanlity = quanlity;    }    public Coffee() {    }}
原创粉丝点击