繁体   English   中英

通过矩形中Spring POST响应的URL位置标头获取一个实体

[英]Fetch one entity by url location header of Spring POST response in restangular

我如何才能将新发布的实体获取到Spring应用程序中,该应用程序仅将创建的资源的“ location”标头带回给我? 我设法使用标题从URL获取

RestangularProvider.setFullResponse(true);

在restangular配置中(顺便说一句,有没有更优雅的方法呢?当前的解决方案迫使我到处使用.data)。

响应如下所示:

Cache-Control   no-cache, no-store, max-age=0, must-revalidate
Date    Sat, 03 Jan 2015 11:50:56 GMT
Expires 0
Location     https://localhost:8443/users/54a7d7a0ccf25ba3e97a51f9
Pragma  no-cache
Server  Apache-Coyote/1.1
Strict-Transport-Security   max-age=31536000 ; includeSubDomains
Transfer-Encoding   chunked
X-Application-Context   application
X-Content-Type-Options  nosniff
X-Frame-Options DENY
X-XSS-Protection    1; mode=block

我的矩形后控制器动作如下所示:

$scope.create = function () {
        $scope.users.post({
            name: $scope.name,
            surname: $scope.surname,
            title: $scope.title,
            email: $scope.email,
            password: $scope.password,
            phone: $scope.phone,
            skype: $scope.skype,
            roles: $scope.roles,
            nonLocked: $scope.nonLocked,
            nonExpired: $scope.nonExpired,
            credintialsNonExpired: $scope.credintialsNonExpired
        }).then(
                function (data) {
                    var location = data.headers('location');
                    var modal = $('#newUser');
                    modal.modal('hide');
                    modal.on('hidden.bs.modal', function () {
                        $(this).find('form')[0].reset();
                    });
                    $('#roles').selectpicker('deselectAll');
                },
                function (error) {
                    if (error.status === 409) {
                        $('.alert').removeClass('hidden');
                    } else {
                        alert("Niestety wystąpił błąd, czy na pewno wypełniłeś wszystkie pola?");
                    }
                }
        );

服务器端Spring资源:

@RepositoryRestResource
public interface UserRepository extends MongoRepository<User, String> {

    public User findOneByEmail(@Param("email") String email);
}

我应该如何使用restangular请求此特定资源,以及如何将其推送到集合中以刷新视图?

看来我已经知道了。 我需要使用的是

users.oneUrl('users', location).get().then(
                                    function (newUser) {
                                        $scope.users.push(newUser);
                                    });

成功发布一个新用户后,所有作品都像魅力一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM