我想从angular发送2个值到spring boot API,在spring boot API中,有一个查询正在接受一些我已经硬编码的参数,但是想在那个查询中从angular发送那个参数有两个参数,因此要将此参数从angular传递到API并根据传递的参数获取angular的数据,
这是daoimpl,其中查询具有2个参数
@Override
public List<ThingworxStoreDeviceConnStatusBean> getStoreDS() {
System.out.println("ThingworxDaoImp is runing" + "\\getStoreDS");
String Query = "select * from ncr_store_connectivity_info('28152','0002')";
System.out.println("Query getAllStores::" + Query);
List<ThingworxStoreDeviceConnStatusBean> thingworxModelList = jdbcTemplate.query(Query, new RowMapper<ThingworxStoreDeviceConnStatusBean>() {
@Override public ThingworxStoreDeviceConnStatusBean mapRow(ResultSet rs, int rowNum)throws SQLException {
ThingworxStoreDeviceConnStatusBean mThingworxStoreDeviceConnStatusBean = new ThingworxStoreDeviceConnStatusBean();
mThingworxStoreDeviceConnStatusBean.setConnected(rs.getInt("connected"));
mThingworxStoreDeviceConnStatusBean.setDisconnected(rs.getInt("disConnected"));
mThingworxStoreDeviceConnStatusBean.setTotal(rs.getInt("total"));
mThingworxStoreDeviceConnStatusBean.setConnected_per(rs.getString("connected_per"));
return mThingworxStoreDeviceConnStatusBean;
}
});
return thingworxModelList;
}
这是我从API获取数据的先验代码
getTotalDevice() {
this.users2 = this
._dataService
.getCustomerInfo()
.subscribe((result2) => {
this.users2 = result2
console.log("total subset1" + result2);
// LOGIC FOR SPLITING ARRAY
for (let i = 0; i < this.users2.length; i++) {
this.Jsonobj3 = this.users2[i];
console.log("json " + JSON.stringify(this.Jsonobj3));
this.Connect_Total = this.Jsonobj3['connected'];
console.log("inside loop connected" + this.Connect_Total[i]);
this.DisConnect_Total = this.Jsonobj3['disconnected'];
this.totalSubset = this.Jsonobj3['total'];
this.Connected_per = this.Jsonobj3['connected_per'];
this.Discoonected_per = 100 - this.Connected_per;
}
console.log("result array" + this.DisConnect_Total);
console.log("connected total" + this.Connect_Total);
console.log("total subset" + this.totalSubset);
console.log("Connected_per" + this.Connected_per);
console.log("disconnecetd per" + this.Discoonected_per)
this.ConnectMethod(this.Connect_Total);
// this.options.series[0]['data']=this.Connect_Total
Highcharts.chart('card', this.options);
Highcharts.chart('card', this.options1);
// console.log(result2)
// if (result2) {
// this.user2 = result2;
// console.log(this.user2[0].ncr_customer_info.split(','));
// var splittedArray = this.user2[0].ncr_customer_info.split(',');
// for (var i = 0; i < splittedArray.length; i++) {
// this.globalObj[i] = splittedArray[0].value;
// }
// console.log("connected" +this.globalObj);
// }
}, (error) => {})
答案 0 :(得分:0)
您可以发布是HttpClient this
getData(modalClass: YourModalClass): Observable<YourModalClass> {
return this.http.post<YourModalClass>("Your Url", modalClass, httpOptions)
.pipe(
catchError(this.handleError('addHero', hero))
);
}
第二个方法(如果是字符串)
如果您使用的是json-server
import { Http, Headers, RequestOptions } from '@angular/http';
const headers = new Headers({'Content-Type': 'application/json'});
const options = new RequestOptions({headers: headers});
this.http.post(this.url, JSON.stringfy(data), options)...