0.前言

利用  SpringBoot ,串接 MySQL 實作API 資料串接 .

1.準備

MAMP – Apache,MySQL Server :  https://www.mamp.info/en/

IntelliJ CE plugin : Spring Assistant

Spring Doc : https://spring.io/guides/gs/accessing-data-mysql/

API Test tool : https://www.getpostman.com/downloads/

phpMyAdmin url :  http://localhost/phpmyadmin (use MAMP Set your mysql port & web port)

 

2.Code

select “Gradle Project”

Dependencies “web”

JPA , use SpringDoc Url

Remember click “Use auto-import”

 

Copy SpringDoc Gradle , Paste to your Gradle

add some code to properties ,

hibernate.ddl-auto  = none (when server started  , if create db will drop , other action google it).

MyServer port is 3306.

Username , Password , need add from mysql.user table .

And Create a Interface extend CrudRepository.

“UserRepository.java” (interface)

Create Model “User.java”.

Create Controller “UserController.java”.

if Post Action -> @PostMapping()

if Get Action ->  @GetMapping() , avoid wrong code.

All functions  CrudRepository have . We just need create interface extend CrudRepository.

Use PostMan Test API .

Add

Select

Delete , need set Header

Content-Type , application/json

3.Git

https://github.com/encorex32268/blogthing/tree/master/demo2

4.Reference

https://spring.io/guides/gs/accessing-data-mysql/

 

 

最後修改日期: 2019-05-06 11:36:21

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料