RestController等注解作用等

package com.thoughtmechanix.controllers;

import com.thoughtmechanix.model.License;
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.RestController;

@RestController//告诉spring容器这个Java类将用于基于Rest的服务,此注解将自动处理以
//jason或xml方式传递到服务中的数据的序列化,在默认情况下,@RestController类将返回的数据序列化
//为json
//同时这个注解下的方法不需要再返回ResponseBody类
@RequestMapping(value = “/v1/organizations/{organizationId}/licenses”)
//这一注解告诉spring容器本方法将要公开的http端点
public class LicenseServiceController {

@RequestMapping(value="/{licenseId}",method = RequestMethod.GET)
public License getLicenses(@PathVariable("organizationId") String organizationId,
                           @PathVariable("licenseId") String licenseId) {

//@PathVariable注解将输入的URL传递的参数值{parameterName}语法表示映射为方法的参数
//return licenseService.getLicense(licenseId);
return new License()
.withId(licenseId)
.withOrganizationId(organizationId)
.withProductName(“Teleco”)
.withLicenseType(“Seat”);
}
}

猜你喜欢

转载自blog.csdn.net/m0_37487653/article/details/87887154