从棱角分明的UI路由器和Spring MVC Requestmapping [英] Requestmapping from angular-ui-router and spring mvc

查看:217
本文介绍了从棱角分明的UI路由器和Spring MVC Requestmapping的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AngulaJS作为一个JavaScript客户端和Spring MVC作为一个休息的后端。
在AngulaJS我使用的UI路由器。

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文件(左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中的其余后端的方法请求映射。下面是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";
    }

请帮我解决它,我想使用的用户界面路由器比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.

我觉得你768,16尝试使用 templateUrl:意见/页/火车而不是 templateUrl:意见/页/ 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 作为返回对象,而不是字符串(没有使用过字符串,实际上我续图为什么)。

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

角UI路由器会写 /火车在URL和Spring将成为映射到 /火车路线。

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

希望会帮助你。

这篇关于从棱角分明的UI路由器和Spring MVC Requestmapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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