2017-04-08 76 views
0

我是Spring REST的新手。我必須使用Spring REST來實現下面提到的要求。我必須使用JPA Repository進行數據庫交互創建一個唯一的ID並將其保存在數據庫中

我有2個表,Application和App_Config。應用程序表具有以下行:

id(主鍵),ApplicationId,Status,Source_System。 App_config表具有以下行:ApplicationId(外鍵),HeaderText,FooterText。每當新應用程序發送HTTP POST請求時,我需要使用java UUID爲應用程序生成一個唯一的ID。基於生成的ApplicationId,我需要將數據保存在App_Config表中。有可能相同的應用程序出現兩次。在這種情況下,我必須檢索已經生成的ApplicationId並從App_Config表中加載Header和Footer。 請告知如何通過POST方法實現此目的。我只需要所產生的applicationID關於發送帶有UUID休息和REST API將服務器+ /發電機/ UUID發回給用戶

回答

0

你的問題的部分解決方案(另一部分是不理解)

import org.springframework.http.HttpStatus; 
import org.springframework.http.MediaType; 
import org.springframework.http.ResponseEntity; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.RestController; 

import java.util.UUID; 

@RestController 
@RequestMapping("/generator") 
public class UuidGeneratorRestController { 

@RequestMapping(value = "/uuid", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) 
public ResponseEntity<UUID> getUUID() { 
    UUID generated = UUID.randomUUID(); 
    return new ResponseEntity(generated, HttpStatus.OK); 
} 

}

+0

請告訴我哪一部分,你不明白......... – Amateur

+0

嘿,「有是相同的應用程序出現了兩次的可能性。在這種情況下,我需要檢索已經生成ApplicationId並從App_Config表中加載頁眉和頁腳。「 如果試圖修改一個持久對象,然後我假設「把」請求被髮送,但在這種情況下,PUT請求將對象標識爲重點,以查找和更新的對象。 但是你說的對象需要尋找其他項目第一或看是否存在那些東西不是,這是稍微有一些混亂給我。 – Masud

+0

謝天謝地,我解決了上述問題!道歉不能清楚地解釋疑問 – Amateur

相關問題