【发布时间】:2017-06-15 23:11:11
【问题描述】:
我正在尝试使用 PathVariable 制作带有 Hello 和名称用户的简单页面。好吧,如果你来http://localhost:8080/#/John,你会在网站上看到“Hello John”。
我知道很好的 Java,但在 AngularJS 中我是初学者。好吧,我认为它的问题。
你好控制器
@Controller
@RequestMapping("/{name}")
public class HelloController {
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
public @ResponseBody
String name(@PathVariable String name) {
return this.name(name);
}
@RequestMapping("/layout")
public String getHomePage(ModelMap modelMap) {
return "hello/layout";
}
}
角度的HelloController
var HelloController = function($scope, $http) {
var name = $name;
$scope.name = function(name) {
$http.get(name).success(function() {
})
};}
app.js
var AngularSpringApp = {};
var App = angular.module('AngularSpringApp', ['AngularSpringApp.filters', 'AngularSpringApp.services', 'AngularSpringApp.directives']);
// Declare app level module which depends on filters, and services
App.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/home', {
templateUrl: 'home/layout',
controller: HomeController
});
$routeProvider.when('/:name', {
templateUrl: 'hello/layout',
controller: HelloController
});
}]);
简单页面hello/layout.html
<div class="alert alert-error" ng-show="error">{{errorMessage}}</div>
<form class="form-horizontal">
<h1>Hello {{name}}</h1>
</form>
感谢您的帮助!
【问题讨论】: