首页 >> 大全

Demo project for Spring Boot 【1】spring

2023-09-13 大全 33 作者:考证青年

This is as a that is given ’s $scope and $http . It uses the $http to the REST at “/”.

If , it will the JSON back from the to $scope., a model named “”. By that model , can bind it to the page’s DOM, it for the user to see.

这个控制器模块被表示为一个简单的函数,它被赋予的 s c o p e 和 scope和 scope和http组件。它使用 h t t p 组 件 在 “ / g r e e t i n g ” 处 使 用 R E S T 服 务 。 如 果 成 功 , 它 将 把 从 服 务 返 回 的 J S O N 分 配 给 http组件在“/”处使用REST服务。 如果成功,它将把从服务返回的JSON分配给 http组件在“/”处使用REST服务。如果成功,它将把从服务返回的JSON分配给范围.问候语,有效地设置了一个名为“”的模型对象。通过设置该模型对象,可以将其绑定到应用程序页面的DOM,呈现给用户看。

The first tag loads the (.min.js) from a (CDN) so that you don’t have to and place it in your . It also loads the code (hello.js) from the ’s path.

The for use with HTML tags. In index.html, two such are in play:

The tag has the ng-app to that this page is an .

The

tag has the ng- set to Hello, the .

Also note the two

tags which use ( by -curly-).

The ID is {{.id}}

The is {{.}}

The the id and of the model which will be set upon the REST .

第一个脚本标记加载缩小的库(最小角度js)从内容交付网络(CDN)中,这样您就不必下载并将其放入项目中。它还加载控制器代码(你好.js)从应用程序的路径。

库支持几个自定义属性,用于标准HTML标记。在索引.html,有两个这样的属性在起作用:

标记具有ngapp属性,指示此页面是应用程序。

标记将ng 属性设置为引用控制器模块Hello。 还要注意使用占位符的两个

标记(由双大括号标识)。

身份证是{{问候语.id}}在

内容是{{问候语.}}在

占位符引用模型对象的id和属性,这些属性将在成功使用REST服务时设置。

package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class DemoAngularJsApplication {public static void main(String[] args) {SpringApplication.run(DemoAngularJsApplication.class, args);}}

package com.example.demo;public class greeting {private String id;private String content;public String getid() {return id;}public void setid(String id) {this.id = id;}public String content() {return content;}public void setcontent(String content) {this.content = content;}
}

package com.example.demo;import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class MvcConfig implements WebMvcConfigurer {public void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/greeting").setViewName("greeting");registry.addViewController("/").setViewName("index");}}

angular.module('demo', [])
.controller('Hello', function($scope, $http) {$http.get('http://localhost:8080/greeting').then(function(response) {$scope.greeting = response.data;});
});

{"id":1,"content":"Hello, World!"}

<!doctype html>
<html ng-app="demo"><head><title>Hello AngularJS</title><script src="/angular/angular.min.js"></script><script src="/js/hello.js"></script></head><body><div ng-controller="Hello">	<p>The ID is {{greeting.id}}</p><p>The content is {{greeting.content}}</p></div></body>
</html>

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了