控制器
公共类sreappcontroller{
private static final string template=“你好,%s!”(二)
@GetMapping(“/Greeting”)。
返回新问候语(counter.incrementandget(),string.format(template,name));
供参考的javascript和HTML:。
“use strict”;
$scope.greeting=response.data;
})(二)
<!文档类型HTML>
<meta charset=“utf-8”>
<script src=“https://ajax.googleapis.com/ajax/libs/angular js/1.7.2/angular.min.js”></script>
</head>
.
//@Controller
@RestController // @Controller and @ResponseBody into one
public class SreAppController {
@GetMapping("/")
public String index() {
return "index";
}
}
this问题。所以,我发现this
@RestController
public class SreAppController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@GetMapping("/greeting")
public Greeting index(@RequestParam(value="name", defaultValue="World") String name){
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}
}
Thishttp://rest-service.guides.spring.io/greeting
本教程说明了对最少数量的Web应用程序代码的需求,以便Spring引导知道启动Tomcat。建议app.groovy(如下所示),但我的REST控制器启动嵌入式Tomcat服务器,所以我不认为这是问题所在。
@Controller class JsApp { }
供参考的javascript和HTML:
"use strict";
angular.module('demo', []).controller('app', function($scope, $http) {
$http.get('/greeting').
then(function (response) {
$scope.greeting = response.data;
});
});
<!DOCTYPE html>
<html lang="en" ng-app="demo">
<head>
<meta charset="UTF-8">
<title>Hello AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="app">
<p>The ID is {{greeting.id}}</p>
<p>The content is {{greeting.content}}</p>
</div>
</body>
</html>
项目层次结构