LieBrother

当才华撑不起野心时,应该静下心来学习;当能力驾驭不了目标时,应该沉下心来历练。


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

在 Angular 项目中配置 Wijmo5

发表于 2017-06-18   |   分类于 Angular , Wijmo5   |     |   阅读次数

摘要:本文将介绍在 Angular4 项目中配置 Wijmo5 UI控件,文中采用的 Angular 版本为 4.0.0,Wijmo 版本为 C1Wijmo-Eval_5.20171.300

下载 Wijmo5 官方文件

C1Wijmo-Eval_5.20171.300.zip

创建好 Angular4 项目

文中不介绍搭建 Angular 开发环境的过程,需要的可以参考官方提供的 快速入门

创建项目 ng new wijmo ,并测试 ng serve ,运行成功过后再进行接下来的配置。

配置 Wijmo5

解压文件后进入 NpmImages 文件夹,拷贝 wijmo-amd-min 到 Angular项目 wijmo 的 npm_modules 目录下且改名为 wijmo,并 wijmo 项目的 package.json 文件中的 dependencies 中添加配置如下

1
2
3
"dependencies": {
"wijmo": "^5.20171.300"
}

将 “C1Wijmo-Eval_5.20171.300\Dist\styles” 拷贝到 Angular 项目的 src 目录下,并在 src/styles.css 文件中添加 wijmo 自带的样式文件

1
@import "styles/wijmo.min.css";

编写代码

app/app.modules.ts 代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { WjInputModule } from 'wijmo/wijmo.angular2.input';

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
WjInputModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

添加了

1
2
3
import { WjInputModule } from 'wijmo/wijmo.angular2.input'; 
...
imports: [ WjInputModule ]

app/component.ts 代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Component } from '@angular/core';
import { WjInputModule } from 'wijmo/wijmo.angular2.input';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';

value: number = 123;

change() {
alert("my WjInputNumber value is " + this.value);
}
}

添加了

1
2
3
4
5
6
import { WjInputModule } from 'wijmo/wijmo.angular2.input';

value: number = 123;
change() {
alert("my WjInputNumber value is " + this.value);
}

app/app.component.html添加代码如下:

1
2
3
4
5
<h1>My First Wijmo Project</h1>
<wj-input-number
[(value)]="value"
(change)="change()"
></wj-input-number>

运行结果

运行结果

在 Ubuntu 中安装 Wine

发表于 2017-04-20   |   分类于 Ubuntu   |     |   阅读次数

个人博客原文:在 Ubuntu 中安装 Wine

摘要:本文简单介绍在 Ubuntu 中安装 Wine

安装命令

如果 Ubuntu 系统是 64 位的,需要运行下面的命令,使可以使用 32 位的系统架构

1
sudo dpkg --add-architecture i386

添加资源

1
2
3
wget https://dl.winehq.org/wine-builds/Release.key
sudo apt-key add Release.key
sudo apt-add-repository https://dl.winehq.org/wine-builds/ubuntu/

更新资源

1
sudo apt-get update

安装

下面3个选其中一个就可以了

Stable branch

1
sudo apt-get install --install-recommends winehq-stable

Development branch

1
sudo apt-get install --install-recommends winehq-devel

Staging branch

1
sudo apt-get install --install-recommends winehq-staging

Eureka Server 搭建部署

发表于 2017-04-16   |   分类于 Eureka   |     |   阅读次数

个人博客原文:Eureka Server 搭建部署

摘要:本文讲述如何在本地搭建配置 Eureka Server

下载

eureka-server-1.6.2.war
tomcat

安装

解压

1
tar -xvzf apache-tomcat-8.5.13.tar.gz

将 eureka-server.war 复制到 tomcat 的 webapps 目录下,并改名为 eureka.war

1
cp ~/eureka-server-1.6.2.war /csh/software/tomcat/webapps/eureka.war

启动 Tomcat

1
bin/startup.sh

验证

在浏览器中访问 http://localhost:8080/eureka , 看到下面的页面就是部署 Eureka Server 成功

Eureka Server

保存 Hexo 博客源码到 GitHub

发表于 2017-04-15   |   分类于 Hexo   |     |   阅读次数

个人博客原文:保存 Hexo 博客源码到 GitHub

摘要:本文介绍在使用 Hexo 博客的时候,怎么保存博客原文。

我们在使用 Hexo 来写博客的时候,我们将博客搭建在 GitHub 上后,当我们使用 hexo d 部署到 GitHub 上,其实没有把我们编写的 xxx.md 原博客文档保存上去,而只是生成一些博客需要的静态的页面。假设我们硬盘坏了,数据无法恢复,那么我们的博客源文档也会不见,所以最好我们是把源代码也托管到 GitHub 上, 这个也有一个好处就是你在其他电脑上也可以同步编写博客。接下来就讲述如何实现。

建立分支

因为 master 分支是存放 Hexo 博客生成的页面,所以只能创建一个分支来保存博客的源代码在你的 GitHub 。例如,我创建了一个分支叫 save

创建分支 save

更改默认分支

更改我们的项目的默认分支为 save

更改默认分支 save

clone 项目

clone 你的项目到你的 Hexo 目录下。例如我的是执行下面的命令:

1
git clone https://github.com/1CSH1/1CSH1.github.io.git

执行命令

执行下面的命令将你的博客的原文配置等等保存到分支 save 上

1
2
3
4
git remote add origin https://github.com/1CSH1/1CSH1.github.io.git
git add .
git commit -m "your description"
git push origin save

配置

确认你的 _config.yml 配置是提交到 master 分支

1
2
3
4
deploy:
type: git
repository: git@github.com:1CSH1/1CSH1.github.io.git
branch: master

通过以上的配置,就可以把 Hexo 博客的源文件配置等到保存到 GitHub 上。

Json 工具类

发表于 2017-04-05   |   分类于 Java , Json   |     |   阅读次数

个人博客原文:Json 工具类
代码:JsonUtil.java

摘要:文中使用了阿里的Json转换工具fastjson来做封装,实现了对象和Json互转,对象数组和Json互转,list和Json互转,Map和Json互转。在项目中可以直接使用该工具类来做Json和其他对象的转换。

maven

1
2
3
4
5
6
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.30</version>
</dependency>

工具类代码:

JsonUtil.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.example.util.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.JSONLibDataFormatSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* @author James-CSH
* @since 17-3-29 下午10:41
*/
public class JsonUtil {

private static final SerializeConfig config;

static {
config = new SerializeConfig();
// compatible with the java.util.Date and the java.sql.Date
config.put(java.util.Date.class, new JSONLibDataFormatSerializer());
config.put(java.sql.Date.class, new JSONLibDataFormatSerializer());
}

/**
* set the default value of the object which the value is null
*/
private static final SerializerFeature[] features = {
SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullListAsEmpty,
SerializerFeature.WriteNullBooleanAsFalse,
SerializerFeature.WriteNullStringAsEmpty,
};

/**
* list to json
*
* @param list
* the list that will transform to json string
* @return
* the json string of list transform
*/
public static String list2json(List list) {
return JSON.toJSONString(list);
}

/**
* map to json
* @param map
* the map that will transform to json string
* @return
* the json string of map transform
*/
public static String map2json(Map map) {
return JSONObject.toJSONString(map);
}

/**
* object array to json
*
* @param objects
* the object array that will transform to json string
* @return
* the json string of array transform
*/
public static String array2json(Object[] objects) {
return JSON.toJSONString(objects);
}

/**
* object to json
*
* @param object
* the object that will transform to json string
* @return
* the json string of object
*/
public static String object2json(Object object) {
return JSON.toJSONString(object, config, features);
}


/**
* json to list
*
* @param json
* the json string that will transform to list
* @param clazz
* the class of the list's element
* @param <T>
* the generic of the class
* @return
* the list that json string transform
*/
public static <T> List<T> json2list(String json, Class<T> clazz) {
return JSON.parseArray(json, clazz);
}

/**
* json to map
*
* @param json
* json string that will transform to map
* @return
* the map fo json string
*/
public static Map json2map(String json) {
return JSONObject.parseObject(json);
}


/**
* json string to object array
*
* @param json
* the json string will transform to object array
* @param clazz
* the class of the json will transform
* @param ts
* the real object array
* @param <T>
* the real object
* @return
* the object array of the json string
*
* @param json
* @param clazz
* @param ts
* @param <T>
* @return
*/
public static <T> T[] json2array(String json, Class<T> clazz, T[] ts) {
return JSON.parseArray(json, clazz).toArray(ts);
}

/**
* json string to object
*
* @param json
* the json string that will transform to object
* @param clazz
* the class that json will transform
* @param <T>
* the object class
* @return
* the object of json string
*/
public static <T> Object json2object(String json, Class<T> clazz) {
return JSON.parseObject(json, clazz);
}

}

测试代码:

TestJsonUtil.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.example.util.json;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author James-CSH
* @since 17-3-31 下午10:47
*/
public class TestJsonUtil {

@Test
public void testObject() {
Person person = new Person();
person.setId(1);
person.setName("James陈");
person.setAge(23);
person.setGender(1);

Person child = new Person();
child.setId(2);
child.setName("James陈 儿子");
child.setAge(2);
child.setGender(1);

List<Person> children = new ArrayList<Person>();
children.add(child);
person.setChildren(children);

String personsJson = JsonUtil.object2json(person);
System.out.println(personsJson); //{"age":23,"children":[{"age":2,"children":[],"gender":1,"id":2,"name":"James陈 儿子"}],"gender":1,"id":1,"name":"James陈"}
Person person2 = (Person) JsonUtil.json2object(personsJson, Person.class);
System.out.println(person2.toString()); //Person{id=1, name='James陈', age=23, gender=1, children=[Person{id=2, name='James陈 儿子', age=2, gender=1, children=[]}]}
}

@Test
public void testArray() {
Person[] persons = new Person[10];
Person person;
Person child;
for (int i=0; i<persons.length; i++) {
person = new Person();
person.setId(i);
person.setName("James陈" + i);
person.setAge(20 + i);
person.setGender(i > 5 ? 1 : 0);

child = new Person();
child.setId(100 + i);
child.setName("James陈 " + i + "儿子");
child.setAge(i);
child.setGender(i < 5 ? 1 : 0);

List<Person> children = new ArrayList<Person>(1);
children.add(child);
person.setChildren(children);

persons[i] = person;
}

String personsJson = JsonUtil.array2json(persons);
System.out.println(personsJson);
//[{"age":20,"children":[{"age":0,"gender":1,"id":100,"name":"James陈 0儿子"}],"gender":0,"id":0,"name":"James陈0"},{"age":21,"children":[{"age":1,"gender":1,"id":101,"name":"James陈 1儿子"}],"gender":0,"id":1,"name":"James陈1"},{"age":22,"children":[{"age":2,"gender":1,"id":102,"name":"James陈 2儿子"}],"gender":0,"id":2,"name":"James陈2"},{"age":23,"children":[{"age":3,"gender":1,"id":103,"name":"James陈 3儿子"}],"gender":0,"id":3,"name":"James陈3"},{"age":24,"children":[{"age":4,"gender":1,"id":104,"name":"James陈 4儿子"}],"gender":0,"id":4,"name":"James陈4"},{"age":25,"children":[{"age":5,"gender":0,"id":105,"name":"James陈 5儿子"}],"gender":0,"id":5,"name":"James陈5"},{"age":26,"children":[{"age":6,"gender":0,"id":106,"name":"James陈 6儿子"}],"gender":1,"id":6,"name":"James陈6"},{"age":27,"children":[{"age":7,"gender":0,"id":107,"name":"James陈 7儿子"}],"gender":1,"id":7,"name":"James陈7"},{"age":28,"children":[{"age":8,"gender":0,"id":108,"name":"James陈 8儿子"}],"gender":1,"id":8,"name":"James陈8"},{"age":29,"children":[{"age":9,"gender":0,"id":109,"name":"James陈 9儿子"}],"gender":1,"id":9,"name":"James陈9"}]
Person[] persons2 = new Person[]{};
persons2 = JsonUtil.json2array(personsJson, Person.class, persons2);
for (int i=0; i<persons2.length; i++) {
System.out.println(persons2[i].toString());
/*
Person{id=0, name='James陈0', age=20, gender=0, children=[Person{id=100, name='James陈 0儿子', age=0, gender=1, children=null}]}
Person{id=1, name='James陈1', age=21, gender=0, children=[Person{id=101, name='James陈 1儿子', age=1, gender=1, children=null}]}
Person{id=2, name='James陈2', age=22, gender=0, children=[Person{id=102, name='James陈 2儿子', age=2, gender=1, children=null}]}
Person{id=3, name='James陈3', age=23, gender=0, children=[Person{id=103, name='James陈 3儿子', age=3, gender=1, children=null}]}
Person{id=4, name='James陈4', age=24, gender=0, children=[Person{id=104, name='James陈 4儿子', age=4, gender=1, children=null}]}
Person{id=5, name='James陈5', age=25, gender=0, children=[Person{id=105, name='James陈 5儿子', age=5, gender=0, children=null}]}
Person{id=6, name='James陈6', age=26, gender=1, children=[Person{id=106, name='James陈 6儿子', age=6, gender=0, children=null}]}
Person{id=7, name='James陈7', age=27, gender=1, children=[Person{id=107, name='James陈 7儿子', age=7, gender=0, children=null}]}
Person{id=8, name='James陈8', age=28, gender=1, children=[Person{id=108, name='James陈 8儿子', age=8, gender=0, children=null}]}
Person{id=9, name='James陈9', age=29, gender=1, children=[Person{id=109, name='James陈 9儿子', age=9, gender=0, children=null}]}
*/
}
}

@Test
public void testList() {
List<Person> persons = new ArrayList<Person>(10);
Person person;
Person child;
for (int i=0; i<10; i++) {
person = new Person();
person.setId(i);
person.setName("James陈" + i);
person.setAge(20 + i);
person.setGender(i > 5 ? 1 : 0);

child = new Person();
child.setId(100 + i);
child.setName("James陈 " + i + "儿子");
child.setAge(i);
child.setGender(i < 5 ? 1 : 0);

List<Person> children = new ArrayList<Person>(1);
children.add(child);
person.setChildren(children);

persons.add(person);
}

String personsJson = JsonUtil.list2json(persons);
System.out.println(personsJson);
//[{"age":20,"children":[{"age":0,"gender":1,"id":100,"name":"James陈 0儿子"}],"gender":0,"id":0,"name":"James陈0"},{"age":21,"children":[{"age":1,"gender":1,"id":101,"name":"James陈 1儿子"}],"gender":0,"id":1,"name":"James陈1"},{"age":22,"children":[{"age":2,"gender":1,"id":102,"name":"James陈 2儿子"}],"gender":0,"id":2,"name":"James陈2"},{"age":23,"children":[{"age":3,"gender":1,"id":103,"name":"James陈 3儿子"}],"gender":0,"id":3,"name":"James陈3"},{"age":24,"children":[{"age":4,"gender":1,"id":104,"name":"James陈 4儿子"}],"gender":0,"id":4,"name":"James陈4"},{"age":25,"children":[{"age":5,"gender":0,"id":105,"name":"James陈 5儿子"}],"gender":0,"id":5,"name":"James陈5"},{"age":26,"children":[{"age":6,"gender":0,"id":106,"name":"James陈 6儿子"}],"gender":1,"id":6,"name":"James陈6"},{"age":27,"children":[{"age":7,"gender":0,"id":107,"name":"James陈 7儿子"}],"gender":1,"id":7,"name":"James陈7"},{"age":28,"children":[{"age":8,"gender":0,"id":108,"name":"James陈 8儿子"}],"gender":1,"id":8,"name":"James陈8"},{"age":29,"children":[{"age":9,"gender":0,"id":109,"name":"James陈 9儿子"}],"gender":1,"id":9,"name":"James陈9"}]
List<Person> persons2 = JsonUtil.json2list(personsJson, Person.class);
for (int i=0; i<persons2.size(); i++) {
System.out.println(persons2.get(i).toString());
/*
Person{id=0, name='James陈0', age=20, gender=0, children=[Person{id=100, name='James陈 0儿子', age=0, gender=1, children=null}]}
Person{id=1, name='James陈1', age=21, gender=0, children=[Person{id=101, name='James陈 1儿子', age=1, gender=1, children=null}]}
Person{id=2, name='James陈2', age=22, gender=0, children=[Person{id=102, name='James陈 2儿子', age=2, gender=1, children=null}]}
Person{id=3, name='James陈3', age=23, gender=0, children=[Person{id=103, name='James陈 3儿子', age=3, gender=1, children=null}]}
Person{id=4, name='James陈4', age=24, gender=0, children=[Person{id=104, name='James陈 4儿子', age=4, gender=1, children=null}]}
Person{id=5, name='James陈5', age=25, gender=0, children=[Person{id=105, name='James陈 5儿子', age=5, gender=0, children=null}]}
Person{id=6, name='James陈6', age=26, gender=1, children=[Person{id=106, name='James陈 6儿子', age=6, gender=0, children=null}]}
Person{id=7, name='James陈7', age=27, gender=1, children=[Person{id=107, name='James陈 7儿子', age=7, gender=0, children=null}]}
Person{id=8, name='James陈8', age=28, gender=1, children=[Person{id=108, name='James陈 8儿子', age=8, gender=0, children=null}]}
Person{id=9, name='James陈9', age=29, gender=1, children=[Person{id=109, name='James陈 9儿子', age=9, gender=0, children=null}]}
*/
}
}

@Test
public void testMap() {
Person person = new Person();
person.setId(1);
person.setName("James陈");
person.setAge(23);
person.setGender(1);

Person child = new Person();
child.setId(2);
child.setName("James陈 儿子");
child.setAge(2);
child.setGender(1);

List<Person> children = new ArrayList<Person>();
children.add(child);
person.setChildren(children);

Map<String, Person> map1 = new HashMap<String, Person>();
map1.put("key1", person);
String personJson = JsonUtil.map2json(map1);
System.out.println(personJson);
//{"key1":{"age":23,"children":[{"age":2,"gender":1,"id":2,"name":"James陈 儿子"}],"gender":1,"id":1,"name":"James陈"}}
Map map2 = JsonUtil.json2map(personJson);
System.out.println(map2.get("key1"));
//{"gender":1,"children":[{"gender":1,"name":"James陈 儿子","id":2,"age":2}],"name":"James陈","id":1,"age":23}
}

}
1…141516…24
LieBrother

LieBrother

当才华撑不起野心时,应该静下心来学习;当能力驾驭不了目标时,应该沉下心来历练。

120 日志
38 分类
138 标签
© 2016 - 2019 LieBrother
由 Hexo 强力驱动
主题 - NexT.Mist
本站访客数人次  |  本站总访问量次