前台代码:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<script src="/lib/go-js/assets/js/go.js"></script> <script id="code" th:inline="javascript">
/*<![CDATA[*/
function init() { var keynode, mapnode; keynode = eval([[${nodekey}]]);
mapnode = eval([[${nodemap}]]); console.log(keynode);
console.log(mapnode) if (window.goSamples) goSamples();
var $ = go.GraphObject.make;
myDiagram = $(go.Diagram, "myDiagramDiv",
{
initialContentAlignment: go.Spot.Center,
"undoManager.isEnabled": true
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, "RoundedRectangle", {strokeWidth: 1},
new go.Binding("fill", "color")),
$(go.TextBlock,
{margin: 20, width: 60, height: 20},
new go.Binding("text", "key"))
);
// myDiagram.model = new go.GraphLinksModel(
// [
// {key: "Alpha", color: "lightblue"},
// {key: "Beta", color: "orange"},
// {key: "Gamma", color: "lightgreen"},
// {key: "Delta", color: "pink"}
// ], [
// {from: "Alpha", to: "Beta"},
// {from: "Alpha", to: "Gamma"},
// {from: "Gamma", to: "Delta"},
// {from: "Delta", to: "Alpha"}
// ]
// ); myDiagram.model = new go.GraphLinksModel(keynode, mapnode);
} /*]]>*/
</script>
</head>
<body onload="init()">
<div id="sample">
<div id="myDiagramDiv" style="border: solid 1px black; width:800px; height:800px"></div>
</div>
</body>
</html>

后台代码:

package com.thunisoft.maybeemanagementcenter.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.thunisoft.maybeemanagementcenter.pojo.LinkMap;
import com.thunisoft.maybeemanagementcenter.pojo.LinkNode;
import com.thunisoft.maybeemanagementcenter.util.JsonHelper;
import com.thunisoft.maybeemanagementcenter.util.JsonStrUltil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.ArrayList;
import java.util.List; @Controller
@RequestMapping("/sleuth")
public class SleuthController { /**
*
*/
@GetMapping("/index")
public String index(Model model) { List<LinkNode> nodekey = new ArrayList<>();
nodekey.add(new LinkNode("a"));
nodekey.add(new LinkNode("b"));
nodekey.add(new LinkNode("c"));
nodekey.add(new LinkNode("d")); List<LinkMap> nodemap = new ArrayList<>();
nodemap.add(new LinkMap("a", "b"));
nodemap.add(new LinkMap("a", "c"));
nodemap.add(new LinkMap("c", "d"));
nodemap.add(new LinkMap("d", "a")); JsonHelper jm = new JsonHelper();
String nodekeyjson = null;
String nodemapjson = null;
try {
nodekeyjson = jm.toJson(nodekey);
nodemapjson = jm.toJson(nodemap);
} catch (JsonProcessingException e) {
e.printStackTrace();
} model.addAttribute("nodekey", nodekeyjson);
model.addAttribute("nodemap", nodemapjson); return "link";
}
}

pojo:

package com.thunisoft.maybeemanagementcenter.pojo;

/**
* 链路中节点
*/
public class LinkNode {
private String key;
private String color = "lightblue"; /*背景颜色,默认亮蓝色*/ public LinkNode(String key) {
this.key = key;
} public LinkNode(String key, String color) {
this.key = key;
this.color = color;
} public String getKey() {
return key;
} public void setKey(String key) {
this.key = key;
} public String getColor() {
return color;
} public void setColor(String color) {
this.color = color;
}
}
package com.thunisoft.maybeemanagementcenter.pojo;

/**
* 链路之间节点映射
*/
public class LinkMap {
private String from;
private String to; public LinkMap(String from, String to) {
this.from = from;
this.to = to;
} public String getFrom() {
return from;
} public void setFrom(String from) {
this.from = from;
} public String getTo() {
return to;
} public void setTo(String to) {
this.to = to;
}
}

Gojs简单例子的更多相关文章

  1. Hibernate4.2.4入门(一)——环境搭建和简单例子

    一.前言 发下牢骚,这段时间要做项目,又要学框架,搞得都没时间写笔记,但是觉得这知识学过还是要记录下.进入主题了 1.1.Hibernate简介 什么是Hibernate?Hibernate有什么用? ...

  2. AgileEAS.NET SOA 中间件平台.Net Socket通信框架-简单例子-实现简单的服务端客户端消息应答

    一.AgileEAS.NET SOA中间件Socket/Tcp框架介绍 在文章AgileEAS.NET SOA 中间件平台Socket/Tcp通信框架介绍一文之中我们对AgileEAS.NET SOA ...

  3. spring mvc(注解)上传文件的简单例子

    spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...

  4. ko 简单例子

    Knockout是在下面三个核心功能是建立起来的: 监控属性(Observables)和依赖跟踪(Dependency tracking) 声明式绑定(Declarative bindings) 模板 ...

  5. mysql定时任务简单例子

    mysql定时任务简单例子 ? 1 2 3 4 5 6 7 8 9     如果要每30秒执行以下语句:   [sql] update userinfo set endtime = now() WHE ...

  6. java socket编程开发简单例子 与 nio非阻塞通道

    基本socket编程 1.以下只是简单例子,没有用多线程处理,只能一发一收(由于scan.nextLine()线程会进入等待状态),使用时可以根据具体项目功能进行优化处理 2.以下代码使用了1.8新特 ...

  7. 一个简单例子:贫血模型or领域模型

    转:一个简单例子:贫血模型or领域模型 贫血模型 我们首先用贫血模型来实现.所谓贫血模型就是模型对象之间存在完整的关联(可能存在多余的关联),但是对象除了get和set方外外几乎就没有其它的方法,整个 ...

  8. [转] 3个学习Socket编程的简单例子:TCP Server/Client, Select

    以前都是采用ACE的编写网络应用,最近由于工作需要,需要直接只用socket接口编写CS的代码,重新学习这方面的知识,给出自己所用到的3个简单例子,都是拷贝别人的程序.如果你能完全理解这3个例子,估计 ...

  9. jsonp的简单例子

    jsonp的简单例子 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...

随机推荐

  1. 在js中嵌套java代码

    jsp中有时候在js中操作某些java后台传递过来的数据逻辑比较复杂,比如list内容的遍历,可以直接在页面上添加java脚本来执行内容,代码如下: //在js中插入java代码操作 <% // ...

  2. highlightjs 详解

    起源: 最近想做一个代码高亮的功能.发现开源社区已经有了这类的项目.比如说highlightjs. 第一步:下载highlightjs 官网:https://highlightjs.org 可以看到它 ...

  3. 安装Flume的时候出现File Channel transaction capacity cannot be greater than the capacity of the channel capacity -解决方案 摘自网络

    部署flume集群时,在启动collector服务器没报错,启动agent服务器报错: File Channel transaction capacity cannot be greater than ...

  4. iOS提交iTunes审核时出现Invalid Binary错误

    xcode5编译一个xcode4时写的代码,提交iTunes审核时出错. 1.iOS提交审核时出现Invalid Binary错误 2.收到邮件: iPhone 5 Optimization Requ ...

  5. 认识和使用Task

    对于多线程,我们经常使用的是Thread.在我们了解Task之前,如果我们要使用多核的功能可能就会自己来开线程,然而这种线程模型在.net 4.0之后被一种称为基于“任务的编程模型”所冲击,因为tas ...

  6. 我的Eclipse设置

    1.默认编码改成:UTF-8(在老项目里设置此项可能导致java源码文件注释显示乱码!可以手工输入GBK三个字母,然后点apply) 2.文件默认打开方式 3.背景颜色(#C0C0C0,RGB(192 ...

  7. 未能为数据库 '*'中得对象'*'分配空间,因文件组'PRIMARY'已满

    服务器使用mssqlserver2005,最近经常出现无法新增信息错误,查看日志,发现严重错误提示,内容大致为: 无法为数据库 'weixin_main' 中的对象 'dbo.wx_logs'.'PK ...

  8. [Windows Azure] How to Create and Deploy a Cloud Service?

    The Windows Azure Management Portal provides two ways for you to create and deploy a cloud service: ...

  9. Mybatis根据配置文件获取session(多数据源)

    1.config.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configura ...

  10. 【TensorFlow】TF-tf.nn.dropout

    官方的接口是这样的 tf.nn.dropout(x, keep_prob, noise_shape=None, seed=None, name=None) 根据给出的keep_prob参数,将输入te ...