跳到主要內容

發表文章

目前顯示的是有「Spring」標籤的文章

Spring Data JPA Transaction

Entity @Data @NoArgsConstructor @AllArgsConstructor @Entity(name = "messenger") @IdClass(MessengerPrimaryKey.class) public class Messenger implements Serializable { @Id @Column(name = "user_id", length = 64, nullable = false) private String userId; @Id @Column(name = "psid", length = 64, nullable = false) private String psId; @Column(name = "page_id", length = 64, nullable = false) private String pageId; } PrimaryKey @Data @NoArgsConstructor @AllArgsConstructor public class MessengerPrimaryKey implements Serializable { private String userId; private String psId; } Test1 transactionalTest1 是基本的 transactional, 在 transactionalTest1 結束後會做一個 commit import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; import tw.com.u...

RESTClient with Retrofit2 - OKHttp3

Taylor Durrer Line-bot-sdk-java 前一陣子都在研究 line-bot-sdk-java , 看到 Retrofit2 搭配 OKHttp3 , 媽媽就問我為什麼跪著寫程式。 Simsimi Simsimi 聽說背後是百度的 NLP 技術的東西, 啊災... 因為我接完後, 他都回我幹話跟髒話, 我就決定叫他 髒小雞 , 他會根據一些關鍵字或什麼 NLP 之類的 (太難了) 來回我話, 支援多國語言, 對剛接觸 bot 來說, 算是滿方便, 又不用傷腦力去處理 NLP 的好服務, 當然你送的資料有可能都送給百度啦, maybe Spring boot Framework Spring boot framework 算是對新手滿友善的框架?那文件的厚實度, 印出來當枕頭都沒問題。 俗話說, 在哪裡跌倒, 就在哪裡躺下 , 就在哪裡爬起來, Bean 很好用, 但有時候找不到文件就很雞掰。 從 Line-bot-sdk-java 的架構下了解一下 java 的注入, 營養真是滿分啊。 Purpose 包裝完後可以像這樣簡單俐落的使用。 Response simSimiResponse = simSimiService.chat("Hi~").execute(); RESTClient Service Retrofit2 的起手式就是先墊一個 interface ,透過 annonation 就可以很清楚的明暸 Resource, 滿符合 RESTful 的精神的啊, 在閱讀跟維護上也是好棒棒。 詳細的Retrofit2 Doc 請參閱這邊 https://square.github.io/retrofit/ public interface SimSimiService { /** * @param msg * @return ResponseBody {@link ResponseBody} * @see http://developer.simsimi.com/api */ @GET("request.p") Call chat(@Query("text") String msg); ...