Java微服务应用测试的示例分析

小编给大家分享一下Java微服务应用测试的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

10年积累的网站建设、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有盐边免费网站建设让你可以放心的选择与我们合作。

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; /** * 该注解相当于@ResponseBody + @Controller合在一起的作用 * 会将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,但是实际配置的时候,第二个类的环境配置是个难点,很容易漏掉一些东西,导致编译失败。我能给出的建议就是耐心一些,再耐心一些。

启动下服务,idea里面启动还是很方便的。

Java微服务应用测试的示例分析

通过浏览器,我们能够根据输入的参数,经过处理,封装成一个json串返回。

Java微服务应用测试的示例分析

看完了这篇文章,相信你对“Java微服务应用测试的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!

分享标题:Java微服务应用测试的示例分析
网站URL:https://www.cdcxhl.com/article4/pdjcoe.html

成都网站建设公司_创新互联,为您提供做网站品牌网站设计网页设计公司网站导航外贸网站建设小程序开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化