我是rest api的新手。
我需要制作一个将字符串作为参数然后返回布尔值的 api。
现在我的问题是如何将该字符串传递给我的 api,然后在我的 api 中获取字符串?
我是rest api的新手。
我需要制作一个将字符串作为参数然后返回布尔值的 api。
现在我的问题是如何将该字符串传递给我的 api,然后在我的 api 中获取字符串?
下面是一个示例,它在参数中接受一个字符串,如果未提供查询参数,则它具有一个默认值:
@Path("business/department/")
public interface DepartmentService {
@GET
@Path("/cs/availability/chat")
@Produces(MediaType.APPLICATION_JSON)
boolean getCustomerServiceAvailability(@QueryParam("type") @DefaultValue("chat") String type);
}
实现类可以是任何实现你的接口的东西。在这个例子中,它是一个无状态的 EJB
@Stateless
public class DepartmentServiceImpl implements DepartmentService {
@Context
private HttpServletRequest request;
private static final Logger LOGGER = Logger.getLogger(DepartmentServiceImpl.class.getName());
@Override
public boolean getCustomerServiceAvailability(String scheduleType) {
RequestInfo reqInfo = new RequestInfo(request, this.getClass(), "getCustomerServiceAvailability");
boolean available;
try {
available = CallBusinessService(scheduleType);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getLocalizedMessage());
throw new ServiceException();
} finally {
reqInfo.logExecutionTime();
}
}
}