溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Java微服務(wù)應(yīng)用測(cè)試的示例分析

發(fā)布時(shí)間:2022-01-15 10:42:12 來(lái)源:億速云 閱讀:95 作者:小新 欄目:大數(shù)據(jù)

小編給大家分享一下Java微服務(wù)應(yīng)用測(cè)試的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

package com.jeanron.licensesservice.domain; public class License{ private String licenseId; private String organizationId; private String productName; private String licenseType; public String getLicenseId() { return licenseId; } public void setLicenseId(String licenseId) { this.licenseId = licenseId; } public String getOrganizationId() { return organizationId; } public void setOrganizationId(String organizationId) { this.organizationId = organizationId; } public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public String getLicenseType() { return licenseType; } public void setLicenseType(String licenseType) { this.licenseType = licenseType; } public License withLicenseId(String licenseId){ this.setLicenseId( licenseId ); return this; } public License withOrganizationId(String organizationId){ this.setOrganizationId(organizationId); return this; } public License withProductName(String productName){ this.setProductName(productName); return this; } public License withLicenseType(String licenseType){ this.setLicenseType(licenseType); return this; } }

package com.jeanron.licensesservice.controller; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import com.jeanron.licensesservice.domain.License; /** * 該注解相當(dāng)于@ResponseBody + @Controller合在一起的作用 * 會(huì)將request/response序列化/反序列化為JSON格式 */ @RestController @RequestMapping(value="v1/organizations/{organizationId}/licenses") public class LicenseServiceController { @RequestMapping(value="/{licenseId}",method = RequestMethod.GET)
public License getLicenses( @PathVariable("organizationId") String organizationId, @PathVariable("licenseId")
String licenseId) { //@PathVariable能將URL中{organizationId}、{licenseId}映射到方法的變量organizationId、licenseId return new License() .withLicenseId(licenseId) .withOrganizationId(organizationId) .withProductName("OpsAPI") .withLicenseType("Database"); }
@RequestMapping(value="{licenseId}",method = RequestMethod.PUT) public String updateLicenses( @PathVariable("licenseId") String licenseId) { return String.format("This is the put"); }
@RequestMapping(value="{licenseId}",method = RequestMethod.POST) public String saveLicenses( @PathVariable("licenseId") String licenseId) { return String.format("This is the post"); }
@RequestMapping(value="{licenseId}",method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT) public String deleteLicenses( @PathVariable("licenseId") String licenseId) { return String.format("This is the Delete");
}
}

看代碼還OK,但是實(shí)際配置的時(shí)候,第二個(gè)類的環(huán)境配置是個(gè)難點(diǎn),很容易漏掉一些東西,導(dǎo)致編譯失敗。我能給出的建議就是耐心一些,再耐心一些。

啟動(dòng)下服務(wù),idea里面啟動(dòng)還是很方便的。

Java微服務(wù)應(yīng)用測(cè)試的示例分析

通過(guò)瀏覽器,我們能夠根據(jù)輸入的參數(shù),經(jīng)過(guò)處理,封裝成一個(gè)json串返回。

Java微服務(wù)應(yīng)用測(cè)試的示例分析

看完了這篇文章,相信你對(duì)“Java微服務(wù)應(yīng)用測(cè)試的示例分析”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI