我是使用Jersey编写RESTful服务的新手。以下是示例代码。构建RESTful服务代码的正确方法
我创建了一个类“用户”这个类里面&把一切。
// Service to get the user information
@Path("/User")
public class User {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/getloggedinuser")
public String getUserInfo(@Context HttpServletRequest httpServletRequest) {
// Some code to get the user information
// Call M1
M1();
}
private void M1(){
// Some other business logic
// Call another method
M2();
}
private void M2(){
// Some other business logic
}
}
有谁可以请告诉我更好的方法来构建我的服务。我没有什么想法,但不确定这些想法是否真的很好,还是保持现在的实施。
问题
服务类(用户)的具体落实。这是一个好主意,创建一个接口(比如IUser)并执行User类的实现?
我应该创建一个控制器类&注入IUser作为控制器中的依赖关系吗? Jersey是否提供任何开箱功能来创建控制器类。
阿图尔
这也可能有所帮助:https://www.toptal.com/spring/top-10-most-common-spring-framework-mistakes – sschrass