react js java_react.js 获取 java 后台数据

react.js 获取 java 后台数据

发布时间:2018-11-01 17:56,

浏览次数:540

, 标签:

react

js

java

说明一下我是使用creat-react-app来创建的项目

1. 在package.json加上如下配置即可

"proxy": "http://localhost:8082",

{ "name": "my-app", "version": "0.1.0", "private": true, "proxy":

"http://localhost:8082", "dependencies": { "react": "^16.5.2", "react-dom":

"^16.5.2", "react-scripts": "2.0.4" }, "scripts": { "start": "react-scripts

start", "build": "react-scripts build", "test": "react-scripts test", "eject":

"react-scripts eject" }, "eslintConfig": { "extends": "react-app" },

"browserslist": [ ">0.2%", "not dead", "not ie <= 11", "not op_mini all" ] }

2.请求

// 请求后台数据 changeInputValue(){ /* 查询数据的格式 */ let filter={ object:{ object:{ } }

} var url ="/flightsInterfaceBLH_searchFlightsAndPersons.do"; var

getInformation ={ method:"POST", headers:{ "Content-Type":"application/json" },

/* json格式转换 */ body:JSON.stringify(filter) } fetch(url,getInformation)

.then(response => response.json()) .then(json =>{ // 返回的数据 根据自己返回的json格式取值

debugger; this.setState({ inputValue:json[0].searchDate }) }) }

我的json数据格式

[ { statusCode: "1", statusInfo: "success", searchDate: "2018-11-01",

searchAirport: null, confirmTime: null, data: [ ] } ]

3.结果

4.附上全部代码

import React, { Component } from 'react'; class HelloWorld extends

React.Component { /** * 初始化 * @param {*} props */ constructor(props){

super(props); this.state = { inputValue : '' } } // 请求后台数据 changeInputValue(){

/* 查询数据的格式 */ let filter={ object:{ object:{ } } } var url

="/flightsInterfaceBLH_searchFlightsAndPersons.do"; var getInformation ={

method:"POST", headers:{ "Content-Type":"application/json" }, /* json格式转换 */

body:JSON.stringify(filter) } fetch(url,getInformation) .then(response =>

response.json()) .then(json =>{ // 返回的数据 根据自己返回的json格式取值 debugger;

this.setState({ inputValue:json[0].searchDate }) }) } render() { return (

>

onClick={this.changeInputValue.bind(this)} >search

); } } export default HelloWorld;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值