gpt4 book ai didi

java - 将 $routeParams 从 angularjs 传递到 spring-MVC Controller

转载 作者:太空宇宙 更新时间:2023-11-04 14:00:54 31 4
gpt4 key购买 nike

这就是我的 AngularJs Controller 中的内容

.when("/M:topicId", {templateUrl: "Mu", controller: "conMFs"})

app.controller('conMFs',function($scope,$routeParams){
$scope.otherId = $routeParams.topicId;
});

这是我的 Spring Controller

@RequestMapping(value="/controlerM", method = RequestMethod.GET)  
public ModelAndView controlerM(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView model = null;
session=request.getSession(true);
user = (User) session.getAttribute("user");

List<ends1> ends=(List<ends1>) ifriendlistservice.getends(user.getId(),5);
session.setAttribute("MutualFriends", MutualFriends);
model = new ModelAndView("ends");

return model;

我能够从 AngularJS Controller 中的 AngularJS 页面获取 topicId(使用 $scope.otherId),但是我无法将此值传递给我的 Spring Controller ,从那里我重定向到新页面。

我应该怎么做?

最佳答案

.when("/M:topicId", {templateUrl: "Mu", controller: "conMFs"})
app.controller('conMFs',function($window){
$window.location.reload();
});

然后服务器应用程序从请求的网址获取topicId。您还需要启用 $locationProvider.html5Mode

How should I do this?

你不应该。 Angular 的业余工作是不让服务器应用程序重新加载页面。上面的代码是快速和肮脏的,只有当你正在将 Angular 集成到现有项目中时才可以,但是时间框架要求你部分依赖旧的代码库。

如果您确实需要进行重定向(例如,重定向到外部页面),请发出 AJAX 请求,将 topicId 以及其他内容放入其中,获取重定向 url 作为响应,然后使用 $window.location.href 进行重定向。

我对 Spring 不太熟悉,但上述内容适用于任何服务器端应用程序。

关于java - 将 $routeParams 从 angularjs 传递到 spring-MVC Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29316759/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com