来自 angular-ui-router 和 spring mvc 的请求映射 [英] Requestmapping from angular-ui-router and spring mvc

查看:30
本文介绍了来自 angular-ui-router 和 spring mvc 的请求映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 AngulaJS 作为 javascript 客户端,使用 spring mvc 作为休息后端.在 AngulaJS 中,我使用 ui-router.

I am using AngulaJS as a javascript client side and spring mvc as a rest backend. In AngulaJS i am using ui-router.

这里是 config.js 文件

Here is config.js file

function config($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/index");
    $stateProvider
        .state('trains', {
            url: "/trains",
            templateUrl: "views/pages/trains.html",
            data: {
                pageTitle: 'Trains'
            }
        })

下面是 html 文件 (left-sliderbar.html

Below is html file (left-sliderbar.html

<li ui-sref-active="active">
    <a href="javascript:;" ui-sref="trains" title="the trains">Trains </a>
 </li> 

问题是当我点击左侧滑块中的火车"菜单时,我无法使用 Spring MVC 的 Rest Backend 中的方法获取请求映射.下面是 Spring MVC 控制器的代码

The problem is when I clicked on "Trains" menu in left left-sliderbar, I cannot get request mapping with the method in Rest Backend of Spring MVC. Below is code from Controller of Spring MVC

@RequestMapping("/trains")
    public String getTrainPartialPage(ModelMap modelMap) {
        System.out.println("---------Request Mapping: /trains: " + this.getClass());
        return "pages/trains";
    }

请帮我解决它,我想使用 ui-router 而不是 ngRoute,谢谢

Please help me to fix it out, I'd like to use ui-router than ngRoute, thanks you

推荐答案

我在相同的上下文中遇到了同样的问题.

I had the same problem in a same context.

我认为您应该尝试在您的 templateUrl: "views/pages/trains" 而不是 templateUrl: "views/pages/trains.html">$stateProvider 提供者.

I think you shoud try to use templateUrl: "views/pages/trains" instead of templateUrl: "views/pages/trains.html" in your $stateProvider provider.

后端控制器应该公开这个请求映射:

The back-end controller should expose this request mapping:

@RequestMapping(value = "/train")
public ModelAndView getMain() {
    return new ModelAndView("pages/train");
}

注意:使用 ModelAndView 作为返回对象而不是 String(没有使用 String,实际上我不明白为什么).

NB: Using ModelAndView as a return object instead of String (didn't worked with String and actually I con't figure why).

Angular UI Router 将在 url 中写入 /train,Spring 将提供映射在 /train 路由上的 html 文件.

Angular UI Router will write /train in the url and Spring will serve the html file mapped on the /train route.

希望能帮到你.

这篇关于来自 angular-ui-router 和 spring mvc 的请求映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆