摘要

该文章只为了说明如何整合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. Go 修改map slice array元素值

    在“range”语句中生成的数据的值其实是集合元素的拷贝.它们不是原有元素的引用.这就意味着更新这些值将不会修改原来的数据.我们来直接看段示例: package main import "f ...

  2. 【HttpClient】使用学习

    HttpClient使用学习 HttpClient Tutorial:http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/in ...

  3. 最新115道华为、京东、滴滴、美团精选Java面试题整理

    京东面试题 1. 一般sql注入怎么发现触点的,从源码阐述sqlmap如何测试注入点的. 2. masscan扫描端口时靠什么检测,为什么这么快? 请详述. 3. 你写过哪些小工具,你为你使用过的工具 ...

  4. python学习-price

    """登录功能:用户名和密码存在{'name':'huahua','pwd':'123456'}字典中,通过控制台输入用户名和密码判读是否正确,然后给出对应的提示消息:登 ...

  5. deconstructSigs|探寻cosmic的独特“气质”-mutation signature !

    deconstructSigs-mutation signature看一下你的数据是什么“气质”的? 本文首发于“生信补给站” https://mp.weixin.qq.com/s/k7yzk9hPX ...

  6. win10: 搭建FTP服务器

    新建用户,可以设置多个用户,给予不同的权限 ftp创建完成后,新用户创建完成后,我们回到计算机管理-Internet Information Services(IIS)管理器来管理我们的FTP站点,点 ...

  7. .netcore实现一个读写分离的数据库访问中间件

    在实际业务系统中,当单个数据库不能承载负载压力的时候,一般我们采用数据库读写分离的方式来分担数据库负载.主库承担写以及事务操作,从库承担读操作. 为了支持多种数据库我们先定义一个数据类型字典.key为 ...

  8. BIM工程信息管理系统搭建-系统功能需求

    BIM工程信息管理系统功能需求 该系统是真实存在项目,项目于2013年开始研发到2014年初完成,按照当时技术能力和国内BIM现状,现在BIM技术已比之前好多了,不管是建模.展示等.均提高了不少,本博 ...

  9. oracle数据库解决system表空间已爆满的问题

    有时会发现数据库system表空间增长很快,使用以下语句查看system表空间使用量.也可以使用toad直接看. select b.tablespace_name "表空间", b ...

  10. 局域网地址为什么是192.168.X.X?为什么连上公司的VPN就上不了网?

    注:本文主要目的是给程序员讲述一些局域网/VPN的基本知识,并不涉及到具体的实操.关于如何安装VPN服务器.配置VPN客户端及修改Windows路由表等具体实操内容,请自行搜索. RFC 局域网地址为 ...