私はいくつかの春のブートアプリを作りたいです。私はすでに春のブートプロジェクトを作成しましたが、私は問題があります。私のコントローラは次のようになります:Spring Boot and AngularJS
@RestController
public class IndexController {
@RequestMapping(value="/home",method = RequestMethod.GET)
public String homepage(){
return "index";
}
}
しかし、私が見るものはすべてindex.htmlではなく、単語 "index"だけです。 したがって、角度を使用します。
angular.module('mvcApp', [])
.constant('MODULE_NAME', "index")
.config(['$routeSegmentProvider', '$routeProvider', function ($routeSegmentProvider, $routeProvider) {
$routeSegmentProvider
.when('/', 'index')
.when('/index', 'index')
.when('/configuration', 'configuration')
$routeSegmentProvider.segment('index', {
templateUrl: 'HTML/index.html',
controller: 'IndexCtrl'
});
$routeProvider.otherwise({redirectTo: '/'});
}]);
とコントローラ:
angular.module('mvcApp').controller('IndexCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) {
$scope.hello = "Hello from AngularJS";
}]);
私のindex.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello!</title>
</head>
<body ng-app="mvcApp" ng-controller="IndexCtrl">
Greeting page.
{{hello}}
</body>
</html>
しかし、それは動作しません、私は自分のローカルホスト上でのみエラーを参照してください。私はこの角度コントローラの作品を作成し、適切にビューを返すことができますどのように
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Sep 04 15:33:41 CEST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
?
それは動作しますが、それだけで単語「インデックス」を私に示しています。コントローラはindex.htmlを検索しません。 $ routeSegmentProvider .when( '/'、 'index') .when( '/ index'、 'index') –
これで、 '@ RestController'を' @Controller'に置き換えます。 – EpicPandaForce
Iクラス名の前に@RequestMapping()を使うべきだと思います。 –