摘要

该文章只为了说明如何整合REST服务,并不介绍如何使用,当做笔记吧。

MongoDB

以MongoDB为例

maven 依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

properties配置

spring.data.mongodb.host=127.0.0.1
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=johnson
spring.data.mongodb.password=123456
spring.data.mongodb.port=27017
spring.data.mongodb.database=mydatabase

实体类

public class Book {

    private Integer id;

    private String name;

    private String author;

    public Integer getId() {return id;}

    public void setId(Integer id) { this.id = id; }

    public String getName() { return name; }

    public void setName(String name) { this.name = name; }

    public String getAuthor() { return author; }

    public void setAuthor(String author) { this.author = author; }
}

接口类

public interface BookDao extends MongoRepository<Book, Integer> {}

测试

启动项目后浏览器打开http://localhost:8080/,可以看到如下信息:

{
"_links" : {
"books" : {
"href" : "http://localhost:8080/books{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://localhost:8080/profile"
}
}
}

可以输入http://localhost:8080/books,即可看到返回Book的分页数据。

SpringBoot 构建 REST 服务的更多相关文章

  1. Springboot 构建http服务,返回的http行是'HTTP/1.1 200' 无状态码描述 客户端解析错误

    ————————————————————————————————————————— *** 响应的数据格式  HTTP/1.1 200 OK  Server: Apache-Coyote/1.1  A ...

  2. 使用SpringBoot构建REST服务-什么是REST服务

    前言: 本文按照Spring官网构建REST服务的步骤测试,可以得到结论: 到底什么样的风格才是RESTful风格呢? 1,约束请求命令如下: GET,获取资源.例如:/employees表示获取列表 ...

  3. SpringBoot 快速构建微服务体系 知识点总结

    可以通过http://start.spring.io/构建一个SpringBoot的脚手架项目 一.微服务 1.SpringBoot是一个可使用Java构建微服务的微框架. 2.微服务就是要倡导大家尽 ...

  4. Spring-Boot:Spring Cloud构建微服务架构

    概述: 从上一篇博客<Spring-boot:5分钟整合Dubbo构建分布式服务> 过度到Spring Cloud,我们将开始学习如何使用Spring Cloud 来搭建微服务.继续采用上 ...

  5. Springboot & Mybatis 构建restful 服务五

    Springboot & Mybatis 构建restful 服务五 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务四 2 restful ...

  6. Springboot & Mybatis 构建restful 服务四

    Springboot & Mybatis 构建restful 服务四 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务三 2 restful ...

  7. Springboot & Mybatis 构建restful 服务三

    Springboot & Mybatis 构建restful 服务三 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务二 2 restful ...

  8. Springboot & Mybatis 构建restful 服务二

    Springboot & Mybatis 构建restful 服务二 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务一 2 restful ...

  9. Springboot & Mybatis 构建restful 服务

    Springboot & Mybatis 构建restful 服务一 1 前置条件 jdk测试:java -version maven测试:命令行之行mvn -v eclipse及maven插 ...

随机推荐

  1. C#字符串与时间格式化

    需要将其它类型的变量,转换为字符串类型的一些常见方法与属性. 字符型转换为字符串 // C 货币 2.5.ToString("C"); // ¥2.50 // D 10进制数 .T ...

  2. SAP S4HANA TR传输之操作

    SAP S4HANA TR传输之操作 事务代码: STMS_IMPORT, 选中请求,点击漏斗按钮, 输入要传输的TR(可以多个),然后回车, 鼠标单击请求号,按F9, 然后传输, 点击按钮'是',系 ...

  3. oopday02(面向对象-构造方法&静态static)

    面向对象之封装 01_面向对象(构造方法Constructor概述和格式) * A:构造方法概述和作用 * 给对象的数据(属性)进行初始化 * B:构造方法格式特点 * a:方法名与类名相同(大小也要 ...

  4. centos7搭建ftp服务器并配置匿名用户

    什么是FTP? FTP(File Transfer Protocol,文件传输协议),是TCP/IP网络和Internet上最早使用的协议之一.用来将实现从一台电脑传送文件到另一台电脑,或者接收和查看 ...

  5. 【30天自制操作系统】day04:C语言与目前执行流程图

    用 C 语言直接写入内存 原来依靠汇编 void io_hlt(void); void write_mem8(int addr, int data); void HariMain(void){ int ...

  6. IT兄弟连 HTML5教程 CSS3属性特效 文字排版

    direction定义文字排列方式,所有浏览器都兼容这个属性,有两个可选值rtl和ltr.文字排版的参数说明如表1所示. 表1  CSS3文字排版参数说明 上表所示,ltr是初始值,表示left-to ...

  7. java map在JSTL EL中的小应用--<c:forEach>遍历Map<>泛型

    准 备 数 据 :(自己准备吧少年,考验你时候到了!!) /** 结构示意图: 类型: List集合 map对象 LIst集合 Person类对象 String name : int age mLis ...

  8. Docker异常:/lib/x86_64-linux-gnu/libnss_files.so.2: symbol __libc_readline_unlocked, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference

    当使用docker cp 将容器内数据拷贝至主机时,或是使用docker export 命令归档容器文件时,出现下述异常: Error response from daemon: error proc ...

  9. python中time.strftime不支持中文,报错UnicodeEncodeError: 'locale' codec can't encode character '\u5e74' in position 2: encoding error

    使用time.strftime将 "2020-10-10 10:10:10" 转化为  2020年10月10日10时10分10 报错: import time timestr=&q ...

  10. tornado框架中redis使用

    一.安装依赖 pip3 install tornado-redis 二.导入模块 import tornadoredis 三.创建redis对象 import tornadoredis CONNECT ...