spring-boot-mybatis-rest-service-demo

本示例展示如何将Spring Boot与MyBatis结合使用来创建RESTful服务。项目特点包括使用单一可执行JAR文件、内嵌Tomcat服务器、减少配置,并通过实例演示了基本的CRUD操作与分页功能。此外还介绍了如何实现网站API的安全认证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源码传送: https://github.com/chenkezhao/spring-boot-mybatis-rest-service-demo

特点

  1. 把所有东西都封装在一个单独的,可执行的JAR文件中,由Java main()方法驱动,无须打包传统WAR文件;
  2. 直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件);
  3. 较少配置;

参考:

https://projects.spring.io/spring-boot/

http://spring.io/guides/gs/consuming-rest/

http://www.mybatis.org/spring/index.html#Requirements

Mybatis简单的增删改查及分页使用demo

访问:
http://localhost:8081/category/queryForManage?page=2&rows=1

得到结果:

{"list":[{"id":2,"parentid":0,"name":"name2","code":"code2","remark":"p"}],"pagination":{"total":2,"current":2,"pageSize":2}}

代码生成模板,批量生成枯燥重复的代码

连接数据库 - 指定数据字典 - 根据模板生成提前预订好的逻辑代码!

详情查看doc/Code-Generator

更多详情 http://blog.youkuaiyun.com/u013474104/article/details/78547017

网站api接口请求安全认证,集成spring-security-oauth2

效果:

直接访问:

请求 http://localhost:8081/clientinf/category/queryForManage?rows=1&page=1

返回:
Full authentication is required to access this resourceunauthorized

获取token再访问:

C:\Users\aaron>curl localhost:8081/oauth/token -d "grant_type=password&scope=read&username=greg&password=turnquist" -u foo:bar

{"access_token":"8f5ef7e2-4da8-42a3-9968-df564f346ddc","token_type":"bearer","refresh_token":"a01d91c9-45b0-4913-9461-0573b3b26a1a","expires_in":42635,"scope":"read"}

C:\Users\aaron>curl -H "Authorization: bearer 8f5ef7e2-4da8-42a3-9968-df564f346ddc" "localhost:8081/clientinf/category/queryForManage?rows=1&page=1"

{"list":[{"id":1,"parentid":null,"name":"name","code":"code","remark":"pp"}],"pagination":{"total":2,"current":1,"pageSize":2}}

C:\Users\aaron>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值