스프링 부트 앱을 만들고 싶습니다. 이미 스프링 부트 프로젝트를 만들었지 만 문제가 있습니다. 내 컨트롤러 모양은 다음과 같습니다 :스프링 부트와 앵글러
@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를 사용하고 싶습니다. $ routeSegmentProvider .when ('/', 'index') .when ('/ index', 'index') –
그런 다음'@ RestController'를'@ Controller'로 대체하십시오. – EpicPandaForce
I 클래스 이름 앞에 @RequestMapping()을 사용해야합니다. –