iot前台开发环境:请求示例
参考链接:http://www.cnblogs.com/keatkeat/category/872790.html
编辑-》update保存

一、typescipt
import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import { RequestOptions } from '@angular/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class SubnetService {
constructor(private http: Http) {}
getDatas(): Promise<any> {
return this.http.get("/devices")
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}
getData(): Promise<any> {
return this.http.get("/devices/")
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}
update(id, data): Promise<any>{
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post("/devices/"+ id +"/update", JSON.stringify(data),options)
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}
delete(id): Promise<any> {
return this.http.delete("/devices/"+ id)
.toPromise()
.then(response => response)
.catch(this.handleError);
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
}
二、java代码
package com.inspur.iot.iot_hub.controller;
import com.inspur.iot.iot_hub.entity.DmDevicetype;
import com.inspur.iot.iot_hub.service.DeviceService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
@RequestMapping(value="/devices") // 通过这里配置使下面的映射都在/devices下,可去除
public class DeviceTypeController {
@Autowired
DeviceService deviceServer;
@ApiOperation(value="获取设备类型列表", notes="")
@RequestMapping(value={""}, method= RequestMethod.GET)
public List<DmDevicetype> getDeviceList() {
List<DmDevicetype> devices = deviceServer.getDevice();
return devices;
}
@ApiOperation(value="查询设备类型", notes="")
@ApiImplicitParam(name = "device", value = "设备查询", required = true, dataType = "Device")
@RequestMapping(value="/code", method=RequestMethod.GET)
public List<DmDevicetype> getDevicesByCode(@PathVariable String code) {
List<DmDevicetype> devices = deviceServer.getDeviceByCode(code);
return devices;
}
@ApiOperation(value="创建设备类型", notes="")
@ApiImplicitParam(name = "device", value = "设备详细实体device", required = true, dataType = "Device")
@RequestMapping(value="", method=RequestMethod.POST)
public DmDevicetype createDevice(@RequestBody DmDevicetype device) {
deviceServer.create(device);
return device;
}
@ApiOperation(value="获取设备详细信息", notes="根据url的id来获取设备详细信息")
@ApiImplicitParam(name = "id", value = "设备ID", required = true, dataType = "String")
@RequestMapping(value="/{id}/detail", method=RequestMethod.GET)
public DmDevicetype getDevice(@PathVariable String id) {
return deviceServer.queryDevice(id);
}
@ApiOperation(value="更新设备详细信息", notes="根据url的id来指定更新对象,并根据传过来的device信息来更新用户详细信息")
@RequestMapping(value="/{id}/update", method=RequestMethod.POST)
public DmDevicetype updateDevice(@PathVariable String id, @RequestBody DmDevicetype device){
deviceServer.updateDevice(id,device);
return device;
}
@ApiOperation(value="删除设备", notes="根据url的id来指定删除对象")
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
public String deleteDevice(@PathVariable String id) {
deviceServer.deleteDevice(id);
return "success";
}
}
iot前台开发环境:请求示例的更多相关文章
- iot前台开发环境:搭建 SpringBoot+angularJs2
参考网站 Angular 中文官网:https://angular.cn/ 参考代码:https://ng.ant.design/#/components/dropdown npm install ...
- iot前台开发环境:前后台访问映射
一.前端映射- java代码 二.路由设置 -前台代码 三.访问应用
- Halcon开发环境和数据结构介绍——第1讲
1.Halcon是什么?如何初步了解Halcon? 这点我讲得不太好,不如给大家看看三个链接: ① Halcon官方网站:https://www.mvtec.com/products/halcon/ ...
- 《ArcGIS Runtime SDK for Android开发笔记》——(4)、基于Android Studio构建ArcGIS Android开发环境
1.前言 2015年1月15日,发布ArcGIS Runtime SDK for Android v10.2.5版本.从该版本开始默认支持android studio开发环境,示例代码的默认开发环境也 ...
- Salesforce Apex 开发环境设置和Hello World示例
本文介绍了Salesforce Apex开发环境的设置以及一个简单的Hello World示例的实现过程. Salesforce开发环境 Salesforce通过http://developer.fo ...
- Windows 10 IoT Serials 1 - 针对Minnow Board MAX的Windows 10 IoT开发环境搭建
目前,微软针对Windows IoT计划支持的硬件包括树莓派2,Minnow Board MAX 和Galileo (Gen 1和Gen 2).其中,Galileo (Gen 1和Gen 2)运行的是 ...
- Win10 IoT C#开发 1 - Raspberry安装IoT系统及搭建开发环境
Windows 10 IoT Core 是微软针对物联网市场的一个重要产品,与以往的Windows版本不同,是为物联网设备专门设计的,硬件也不仅仅限于x86架构,同时可以在ARM架构上运行. The ...
- 【笔记】vue-cli 开发环境中跨域连接后台api(vue-resource 跨域post 请求)
在vue-cli 项目中很多人会用到mock 数据(模拟数据),但是我觉得如果在真实的数据库交互中开发会更有安全感一些,所以查了一下百度很多人推荐的就是: 跨域! 跨域是什么概念?不同的主机名,同主机 ...
- activiti实战--第二章--搭建Activiti开发环境及简单示例
(一)搭建开发环境 学习资料:<Activiti实战> 第一章 认识Activiti 2.1 下载Activiti 官网:http://activiti.org/download.html ...
随机推荐
- 【BSGS】BZOJ3239 Discrete Logging
3239: Discrete Logging Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 729 Solved: 485[Submit][Statu ...
- JDBC存在的问题
1.数据库连接频繁的创建和关闭,缺点是浪费数据库资源,影响操作效率. 设想:使用数据库连接池 2.sql语句是硬编码,如果需求变更需要修改sql,就需要修改java代码,需要重新编译,系统不易维护. ...
- JVM垃圾收集器&对象的引用回收
1.介绍垃圾收集器 垃圾收集器(Garbage Collection,GC)就是用于回收方法区和堆区,其他程序计数器.虚拟机栈.本地方法栈这3个区域都是随线程而生,随线程而灭,栈中的栈帧会随着方法的进 ...
- CSS备战春招の二
CSS:层叠样式表 CSS注释形式:/* */ class 选择器有别于id选择器,class可以在多个元素中使用 id属性不要以数字开头,以数字开头在特定浏览器中不起作用 类名的第一个字符不要使用 ...
- 基于新浪SAE平台的微信开发
自己的微信公众平台开发差不多了,欢迎关注试用哦,我会不定期在那里分享技术文章! 主要功能: 输入t+中文或者英文返回对应的英中翻译 输入[m]随机来首音乐听,建议在wifi下听 输入[ly+你的留 ...
- 2018-3 WebStorm最新版本破解方法
今天重新打开WebStorm发现之前输入的License Server没法用了,不能通过WebStorm的检测,搜索良久,终于找到了最新版本WebStorm的破解方法. 在激活页面选择License ...
- delphi GDI 图片压缩代码 据说是位图缩放保持原图视觉效果最好的算法
delphi 图片压缩代码 据说是位图缩放保持原图视觉效果最好的算法 若有更好的,请大神留言我也学习下,感谢! uses WinAPI.GDIPAPI, WinAPI.GDIPOBJ; var Bi ...
- numpy用法小结
前言 个人感觉网上对numpy的总结感觉不够详尽细致,在这里我对numpy做个相对细致的小结吧,在数据分析与人工智能方面会有所涉及到的东西在这里都说说吧,也是对自己学习的一种小结! numpy用法的介 ...
- 自动化运维工具---expec
作为运维经常操作Linux服务器是不可避免的事情的,那么你们都是怎么管理的呢? 我们管理的方式较为复杂了,我说一下: 有一套服务器资产管理系统,所有服务器都记录在上面,包括用户名密码,内外网地址都会有 ...
- 网络通信 --> socket通信
socket通信 socket是应用层与TCP/IP协议族通信的中间软件抽象层,是一组接口.工作原理如下: 具体过程:服务器端先初始化socket,然后与端口绑定(bind),对端口进行监听(list ...
