FulworxRESTful接口实现

联合创作 · 2023-09-19 08:27

Fulworx 通过一个简单的 Annotations 为 XWork 框架的 Action 增加了输出 RESTful 接口的功能,如下代码所示:

@URITemplate(uri="/someURI/user/{lastname}/{firstname}")
@Accessor("user")
public class UserAction implements CreateAction, ReadAction
{
    private User user;
    private String firstname;
    private String lastname;
    private UserService userService;

    public UserAction(UserService service){
        this.userService=service;
    }

    public String create()
    {
        user = this.userService.create(firstname,
                                       lastname,
                                       user.getEmail(),
                                       user.getPhone());
        if(user == null){
          //if user isn't found, insert firstname and lastname into
          //resource bundle message, and return a 404 status code
          throw new ApplicationException(
            new BundledErrorDetail("user.error.notfound",
                                   ResourceBundle.getBundle("ErrorMessages"),
                                   new Object[]{firstname, lastname}),
            404);
        }
        return SUCCESS;
    }

    public String read()
    {
        user = this.userService.read(firstname, lastname);
        return SUCCESS;
    }

    public User getUser()
    {
       return user;
    }

    public void setUser(User user)
    {
       this.user = user;
    }
    //also, getter / setter for firstname, lastname
}

浏览 9
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报