Spring框架中接收Http客户端的Post和Get请求
来源:互联网 发布:win10网络图标不显示 编辑:程序博客网 时间:2024/05/29 16:15
本文主要是介绍了在Spring框架中接收Http客户端所传输的参数以及请求
由于Spring框架可以与数据库mybatis以及Hibernate较好的集成,使用接收的数据更易储存到数据库中
同时能够通过HTTP请求从数据库中查询获取需要的信息
因为Http的请求和Web请求一样都是通过URL来访问,所以也将其放在Controller层
在方法结束后加入Return可以直接向Client端发送返回信息
以下是具体的实现代码:
package com.firstdata.opensystem.action;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import org.apache.log4j.Logger;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;import com.firstdata.opensystem.service.FileConfigService;import com.firstdata.opensystem.service.FileReportService;import com.firstdata.opensystem.vo.FileConfig;import net.sf.json.JSONObject;@Controller@RequestMapping("/MsgReceive")public class MsgReceiveAction {private static Logger logger = Logger.getLogger(MsgReceiveAction.class);@Resource private FileReportService fileReportService;@Resourceprivate FileConfigService fileConfigService;@RequestMapping(value = "", method = RequestMethod.POST)@ResponseBody public String msgReceive(@RequestBody String Msg) {System.out.println(Msg);JSONObject obj = JSONObject.fromObject(Msg);fileReportService.addNewFileReport(obj);logger.info("Receive File Report request for " + obj.getString("fileCode"));return "000"; }
与Post方法不同的是Get方法还是使用HttpServletRequest的方式获取到URL的参数
由于Get的请求方式是将参数放在URL/后面
@RequestMapping(value = "", method = RequestMethod.GET)@ResponseBody public String recordInquiry(HttpServletRequest request) {String fileCode = request.getParameter("fileCode");String bizDate = request.getParameter("bizDate");boolean inquiryFlag = fileReportService.inquiryFileReport(fileCode, bizDate);FileConfig fileConfig = fileConfigService.getFileConfigByFileCode(fileCode);String respMsg = String.valueOf(inquiryFlag)+" = "+fileConfig;logger.info("Inquire whether " + fileCode + " has existed. Result: " + respMsg);return respMsg; }}
阅读全文
0 0
- Spring框架中接收Http客户端的Post和Get请求
- Node.js中http 接收get请求、接收post请求、发送get请求、发送post请求
- HTTP客户端发送Post和Get请求
- HTTP中GET请求和POST请求的区别
- http协议中,get请求和post请求的区别
- Volley框架实现Http的get和post请求
- HTTP的GET请求和POST请求
- HTTP请求的GET和POST请求
- HTTP的GET请求和POST请求
- python通过get,post方式发送http请求和接收http响应的方法
- python通过get,post方式发送http请求和接收http响应的方法
- python通过get,post方式发送http请求和接收http响应的方法
- HTTP中GET和POST请求区别
- http中get和post请求差别
- http中get和post请求
- Android中HTTP Post和Get请求
- Http中get和post请求
- HTTP请求中GET和POST的不同
- 《neural network and deep learning》题解——ch03 如何选择神经网络的超参数
- bootstrap-suggest 源代码修改 实现二级联动
- 获得url地址?后的参数
- 初识Java 输出Hello world!
- UNIX环境编程学习笔记(3)——文件I/O之内核 I/O 数据结构
- Spring框架中接收Http客户端的Post和Get请求
- TextView颜色渐变,特殊字颜色
- Java关键字final、static使用总结
- POI实现大数据EXCLE导入导出,解决内存溢出问题
- Angular:$locationProvider:$locationProvider.html5Mode
- hadoop 在linux中的搭建
- 夏季养生知识为居民提供健康指导
- C++矩阵运算库推荐
- vue 和animate.css 的动画使用