概述
該項目包含springBoot-example-ui 和 springBoot-example,分別爲前端與後端,先後端分離,利用ajax交互。css
springBoot-example-ui
- 前端html
- 技術:
BootStrap
+layer
+jquery
+css
+html
- 該項目git地址:https://github.com/jiangcaijun/springBoot-example-ui
springBoot-example
- 後端服務器側
- 該項目git地址:https://github.com/jiangcaijun/springBoot-example
注意:涉及跨域,故springBoot-example
在 controller
類上添加類了@CrossOrigin
,以此支持跨域請求html
springBoot-example-ui(前端)
-
首頁(路徑爲springBoot-example-ui\index.html)(這裏項目名稱爲zeus-ui,下同)
前端
-
首頁請求分析java
以刪除爲例:mysql
- Request Method:DELETE (RESTFUL風格)
- 後端地址爲Request URL:http://localhost:7500/zeus/specialManagements?idSelections=B3C36EAEC69243B7A9723EAB90150512
springBoot-example(後端)
一、技術架構
後端以springboot、maven多模塊爲基礎框架,數據庫爲mysql+redis,實現簡單的CRUD功能。先後端以RESTFUL風格的ajax請求來進行交互。jquery
二、項目分層
-
springBoot-api 控制層,主要是各種controllergit
- 實現對mysql常見的CRUD請求(PUT、DELETE、PATCH、POST、GET等),以自定義的Response來返回至客戶端(主要體如今 RedisExampleController.java類中)
- 實現SpringBoot下redis的set與get(主要體如今 RedisExampleController.java類中)
-
springBoot-base 接口層,包含service接口和entiy實體類github
-
springBoot-util 工具類層web
-
項目代碼整體結構以下:ajax
三、項目啓動
項目成功啓動時,控制檯:
四、springboot + redis 相關
- 代碼以下:
@RestController public class RedisExampleController { @Autowired private IRedisService redisService; @RequestMapping("/redis/set") public Object redisSet(@RequestParam("value")String value){ boolean isOk = redisService.setString("name", value); if(isOk){ return new XPFSingleResponse("redis新增成功"); }else{ return new XPFBadRequestException("redis新增失敗"); } } @RequestMapping("/redis/get") public Object redisGet(){ String name = redisService.getString("name"); return new XPFSingleResponse("redis獲取:" + name); } }
- 配置以下(路徑在 springBoot-api\src\main\resources\application-dev.properties):
#REDIS # Redis數據庫索引(默認爲0) spring.redis.database=0 # Redis服務器地址 spring.redis.host=127.0.0.1 # Redis服務器鏈接端口 spring.redis.port=6379 # Redis服務器鏈接密碼(默認爲空) spring.redis.password= # 鏈接池最大鏈接數(使用負值表示沒有限制) spring.redis.pool.max-active=8 # 鏈接池最大阻塞等待時間(使用負值表示沒有限制) spring.redis.pool.max-wait=-1 # 鏈接池中的最大空閒鏈接 spring.redis.pool.max-idle=8 # 鏈接池中的最小空閒鏈接 spring.redis.pool.min-idle=0 # 鏈接超時時間(毫秒) spring.redis.timeout=0
- redis賦值測試(項目名這裏定義成 zeus ,下同): http://localhost:7500/zeus/redis/set?value=vic
- redis取值測試: http://localhost:7500/zeus/redis/get