tonglin0325的个人主页

SpringBoot学习笔记——swagger-ui

swagger-ui用于给API添加文档,还支持API的请求调用,可以降低前后端联调的沟通成本

1.依赖

1
2
3
4
5
6
7
8
9
10
11
12
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>

2.配置swagger,注意修改basePackage成实际的包名

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
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.genericModelSubstitutes(DeferredResult.class)
.useDefaultResponseMessages(false)
.forCodeGeneration(true)
.apiInfo(apiInfo())
.pathMapping("/") // base,最终调用接口后会和paths拼接在一起
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo")) // 过滤的接口
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("api文档") // 标题
.description("xxxx") // 描述
.termsOfServiceUrl("https://xxx.xxx.xxx")
.version("1.0")
.build();
}

}

3.给controller添加

全文 >>

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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class JFrame_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根

JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
JLabel lab = new JLabel("Label",JLabel.CENTER); //实例化对象,使用剧中对齐
f.add(lab); //向容器中加入组建
Dimension dim = new Dimension(); //实例化Dimension对象

dim.setSize(230,80); //设置大小
f.setSize(dim); //设置组件大小
f.setBackground(Color.WHITE);
Point point = new Point(300,200); //设置现实的坐标点
f.setLocation(point);
f.setVisible(true);
}

}

 

 

更改JLabel的文本样式

 

设置标签的显示字体、大小、背景颜色

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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class JFrame_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根

JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
JLabel lab = new JLabel("Label",JLabel.CENTER); //实例化对象,使用剧中对齐
Font fnt = new Font("Serief",Font.ITALIC+Font.BOLD,28);
lab.setFont(fnt); //设置标签的显示字体
lab.setForeground(Color.RED); //设置标签的文字颜色
f.add(lab); //向容器中加入组建
Dimension dim = new Dimension(); //实例化Dimension对象

dim.setSize(230,80); //设置大小
f.setSize(dim); //设置组件大小
f.setBackground(Color.WHITE);
Point point = new Point(300,200); //设置现实的坐标点
f.setLocation(point);
f.setVisible(true);
}

}

 

 

在JLabel中设置图片

 

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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class JFrame_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根

JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
String picPath = "/home/common/software/database/photo.jpg";
Icon icon = new ImageIcon(picPath);

JLabel lab = new JLabel(icon,JLabel.CENTER); //实例化对象,使用剧中对齐
Font fnt = new Font("Serief",Font.ITALIC+Font.BOLD,28);
lab.setFont(fnt); //设置标签的显示字体
lab.setForeground(Color.RED); //设置标签的文字颜色
f.add(lab); //向容器中加入组建
Dimension dim = new Dimension(); //实例化Dimension对象

dim.setSize(230,80); //设置大小
f.setSize(dim); //设置组件大小
f.setBackground(Color.WHITE);
Point point = new Point(300,200); //设置现实的坐标点
f.setLocation(point);
f.setVisible(true);

}

}

 

 

 

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
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class JText_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
JTextField name = new JTextField(30); //定义文本框,并指定长度
JTextField name_1 = new JTextField("指定内容",10);//定义文本框,并指定内容和长度
JLabel nameLab = new JLabel("输入用户姓名:"); // 定义标签
JLabel name_1Lab = new JLabel("不可编辑文本:"); // 定义标签
name_1.setEnabled(false); //此文本框不可编辑
nameLab.setBounds(10,10,100,20); //设置组件位置和大小
name_1Lab.setBounds(10,40,100,20); //设置组件位置和大小
name.setBounds(110,10,100,20); //设置组件位置和大小
name_1.setBounds(110,40,100,20); //设置组件位置和大小
name.setColumns(10); //设置长度,但是此时不起作用
name_1.setColumns(10); //设置长度,但是此时不起作用
// f.setLayout(new GridLayout(2,2)); //设置容器的布局管理器
f.setLayout(null); //设置容器的布局管理器
f.add(nameLab); //向容器中增加组件
f.add(name); //向容器中增加组件
f.add(name_1Lab); //向容器中增加组件
f.add(name_1); //向容器中增加组件
f.setSize(440, 320); //设置窗体
f.setLocation(300,200); //设置显示位置
f.setVisible(true);
}

}

 

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
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class JPassword_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
JPasswordField jpf1 = new JPasswordField(); //定义秘文框
JPasswordField jpf2 = new JPasswordField(); //定义秘文框
jpf2.setEchoChar('#'); //设置回显字符
JLabel nameLab = new JLabel("默认的显示:"); // 定义标签
JLabel name_1Lab = new JLabel("修改后的显示:"); // 定义标签

nameLab.setBounds(10,10,100,20); //设置组件位置和大小
name_1Lab.setBounds(10,40,100,20); //设置组件位置和大小
jpf1.setBounds(110,10,100,20); //设置组件位置和大小
jpf2.setBounds(110,40,100,20); //设置组件位置和大小

f.setLayout(null); //设置容器的布局管理器
f.add(nameLab); //向容器中增加组件
f.add(jpf1); //向容器中增加组件
f.add(name_1Lab); //向容器中增加组件
f.add(jpf2); //向容器中增加组件
f.setSize(440, 320); //设置窗体
f.setLocation(300,200); //设置显示位置
f.setVisible(true);
}

}

 

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
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class JTextArea_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
JTextArea name = new JTextArea("1231231231231312312",3,10); //定义文本框
name.setLineWrap(true); //如果内容过长,自动换行
JLabel nameLab = new JLabel("多行文本域"); // 定义标签

nameLab.setBounds(10,10,120,20); //设置组件位置和大小
name.setBounds(130,10,150,100); //设置组件位置和大小
f.setLayout(null); //设置容器的布局管理器
f.add(nameLab); //向容器中增加组件
f.add(name); //向容器中增加组件
f.setSize(440, 320); //设置窗体
f.setLocation(300,200); //设置显示位置
f.setVisible(true);
}

}

 

 

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
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;

public class Jmenu_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
JFrame frame = new JFrame("窗体"); //定义窗体
JTextArea text = new JTextArea(); //定义文本域
text.setEditable(true); //定义文本组件可编辑
frame.getContentPane().add(new JScrollPane(text)); //在面板中加入文本框及滚动条

JMenu menuFile = new JMenu("文件"); //定义JMenu组件
//定义显示图标
menuFile.setIcon(new ImageIcon("/home/common/software/database/123.jpg"));
JMenuBar menuBar = new JMenuBar(); //定义JMenu组件
//定义显示图标
JMenuItem newMenu = new JMenuItem("新建",new ImageIcon("/home/common/software/database/123.jpg"));
//定义显示图标
JMenuItem openMenu = new JMenuItem("打开",new ImageIcon("/home/common/software/database/123.jpg"));

newMenu.setMnemonic('N');
openMenu.setMnemonic('O');

newMenu.setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK));
openMenu.setAccelerator(KeyStroke.getKeyStroke('O',java.awt.Event.CTRL_MASK));

menuFile.add(newMenu); //加入菜单项
menuFile.addSeparator(); //加入分割线
menuFile.add(openMenu); //加入菜单项

menuBar.add(menuFile); //加入JMenu
frame.addWindowListener(new WindowAdapter(){ //加入动作监听
public void windowClosing(WindowEvent e) { //窗口关闭时触发,按下关闭按钮
// TODO 自动生成的方法存根
System.out.println("windowClosing-->窗口关闭");
System.exit(1);
}
});
frame.setJMenuBar(menuBar); //在窗体中加入JMenuBar组件
frame.setVisible(true);
frame.setLocation(300,200); //设置显示位置
frame.setSize(300, 180);

}

}

 

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
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;

public class Jmenu_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
JFrame frame = new JFrame("窗体"); //定义窗体
JTextArea text = new JTextArea(); //定义文本域
text.setEditable(true); //定义文本组件可编辑
frame.getContentPane().add(new JScrollPane(text)); //在面板中加入文本框及滚动条

JMenu menuFile = new JMenu("文件"); //定义JMenu组件
//定义显示图标
menuFile.setIcon(new ImageIcon("/home/common/software/database/123.jpg"));
JMenuBar menuBar = new JMenuBar(); //定义JMenu组件
//定义显示图标
JMenuItem newMenu = new JMenuItem("新建",new ImageIcon("/home/common/software/database/123.jpg"));
//定义显示图标
JMenuItem openMenu = new JMenuItem("打开",new ImageIcon("/home/common/software/database/123.jpg"));

newMenu.setMnemonic('N');
openMenu.setMnemonic('O');

newMenu.setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK));
openMenu.setAccelerator(KeyStroke.getKeyStroke('O',java.awt.Event.CTRL_MASK));

menuFile.add(newMenu); //加入菜单项
menuFile.addSeparator(); //加入分割线
menuFile.add(openMenu); //加入菜单项

menuBar.add(menuFile); //加入JMenu

newMenu.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
text.append("选择了newMenu");
}
});

openMenu.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
text.append("选择了openMenu");
}
});

frame.addWindowListener(new WindowAdapter(){ //加入动作监听
public void windowClosing(WindowEvent e) { //窗口关闭时触发,按下关闭按钮
// TODO 自动生成的方法存根
System.out.println("windowClosing-->窗口关闭");
System.exit(1);
}
});

frame.setJMenuBar(menuBar); //在窗体中加入JMenuBar组件

frame.setVisible(true);
frame.setLocation(300,200); //设置显示位置
frame.setSize(300, 180);

}

}

 

 

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
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class JTable_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
JFrame frame = new JFrame("窗体"); //定义窗体
String[] titles = {"姓名","年龄","性别","成绩","是否及格"};
Object[][] userInfo = {{"张三",22,"男",99,true},{"张三",22,"男",99,true}
,{"张三",22,"男",99,true},{"张三",22,"男",99,true},{"张三",22,"男",99,true}};

JTable table = new JTable(userInfo,titles);

JScrollPane scr = new JScrollPane(table);

frame.add(scr);
frame.setSize(330,100);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){ //加入事件监听
public void windowClosing(WindowEvent arg0) { //窗口关闭时触发,按下关闭按钮
// TODO 自动生成的方法存根
System.out.println("windowClosing-->窗口关闭");
System.exit(1);
}
});
}

}

 

 

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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class JFrame_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根

JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
String picPath = "/home/common/software/database/photo.jpg";
Icon icon = new ImageIcon(picPath);

JButton but = new JButton(icon);
f.add(but); //向容器中加入组建
Dimension dim = new Dimension(); //实例化Dimension对象

dim.setSize(230,80); //设置大小
f.setSize(dim); //设置组件大小
f.setBackground(Color.WHITE);
Point point = new Point(300,200); //设置现实的坐标点
f.setLocation(point);
f.setVisible(true);

}

}

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JToggleButton;

public class JToggleButton_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
JFrame f = new JFrame("Swing窗口"); //实例化窗体对象
JToggleButton but1 = new JToggleButton("已选中",true);
JToggleButton but2 = new JToggleButton("未选中");
JToggleButton but3 = new JToggleButton("按我");
f.setLayout(new GridLayout(3,1)); //设置排版样式
f.add(but1);
f.add(but2);
f.add(but3);
f.setSize(440, 320); //设置窗体
f.setLocation(300,200); //设置显示位置
f.setVisible(true);
}

}

 

 

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
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

class MyRadio{
private JFrame frame = new JFrame("窗体");
private Container cont = frame.getContentPane();
private JRadioButton jrb1 = new JRadioButton("单选1");
private JRadioButton jrb2 = new JRadioButton("单选2");
private JRadioButton jrb3 = new JRadioButton("单选3");
private JPanel pan = new JPanel();
public MyRadio(){
//定义一个面板的边框显示条
pan.setBorder(BorderFactory.createTitledBorder("请选择按钮"));
pan.setLayout(new GridLayout(1,3));
ButtonGroup group = new ButtonGroup();
group.add(this.jrb1);
group.add(this.jrb2);
group.add(this.jrb3);
pan.add(this.jrb1);
pan.add(this.jrb2);
pan.add(this.jrb3);
cont.add(pan);
this.frame.setSize(330,80);
this.frame.setVisible(true);
this.frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) { //窗口关闭时触发,按下关闭按钮
// TODO 自动生成的方法存根
System.out.println("windowClosing-->窗口关闭");
System.exit(1);
}
});
}
}


//主类
//Function : JRadioButton_demo
public class JRadioButton_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
new MyRadio();
}

}

 

 

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
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

class MyRadio implements ItemListener{
private JFrame frame = new JFrame("窗体");
private Container cont = frame.getContentPane();
private JRadioButton jrb1 = new JRadioButton("单选1");
private JRadioButton jrb2 = new JRadioButton("单选2");
private JRadioButton jrb3 = new JRadioButton("单选3");
private JPanel pan = new JPanel();
public MyRadio(){
//定义一个面板的边框显示条
pan.setBorder(BorderFactory.createTitledBorder("请选择按钮"));
pan.setLayout(new GridLayout(1,3));
ButtonGroup group = new ButtonGroup();
group.add(this.jrb1);
group.add(this.jrb2);
group.add(this.jrb3);
pan.add(this.jrb1);
pan.add(this.jrb2);
pan.add(this.jrb3);

jrb1.addItemListener(this); //加入事件监听
jrb2.addItemListener(this); //加入事件监听
jrb3.addItemListener(this); //加入事件监听

cont.add(pan);
this.frame.setSize(330,80);
this.frame.setVisible(true);
this.frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) { //窗口关闭时触发,按下关闭按钮
// TODO 自动生成的方法存根
System.out.println("windowClosing-->窗口关闭");
System.exit(1);
}
});
}
@Override
public void itemStateChanged(ItemEvent e) {
// TODO 自动生成的方法存根
if(e.getSource() == jrb1){
System.out.println("jrb1");
}else if(e.getSource() == jrb2){
System.out.println("jrb2");
}else{
System.out.println("jrb3");
}
}
}


//主类
//Function : JRadioButton_demo
public class JRadioButton_demo {

public static void main(String[] args) {
// TODO 自动生成的方法存根
new MyRadio();
}

}

 

Java数据库——PreparedStatement接口

PreparedStatement接口是Statement的子接口,属于预处理操作,与直接使用Statement不同的是,PreparedStatement在操作时,是先在数据表中准备好了一条SQL语句,但是此SQL语句的具体内容暂时不设置,而是之后再进行设置。

全文 >>

Avro学习笔记——avro-tools工具

1.下载avro-tools.jar

1
https://archive.apache.org/dist/avro/avro-1.10.1/java/

avro-tools.jar常用命令:Working with Apache Avro files in Amazon S3  

也可以查看help

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
java -jar ./avro-tools-1.10.1.jar help
Version 1.10.1 of Apache Avro
Copyright 2010-2015 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (https://www.apache.org/).
----------------
Available tools:
canonical Converts an Avro Schema to its canonical form
cat Extracts samples from files
compile Generates Java code for the given schema.
concat Concatenates avro files without re-compressing.
count Counts the records in avro files or folders
fingerprint Returns the fingerprint for the schemas.
fragtojson Renders a binary-encoded Avro datum as JSON.
fromjson Reads JSON records and writes an Avro data file.
fromtext Imports a text file into an avro data file.
getmeta Prints out the metadata of an Avro data file.
getschema Prints out schema of an Avro data file.
idl Generates a JSON schema from an Avro IDL file
idl2schemata Extract JSON schemata of the types from an Avro IDL file
induce Induce schema/protocol from Java class/interface via reflection.
jsontofrag Renders a JSON-encoded Avro datum as binary.
random Creates a file with randomly generated instances of a schema.
recodec Alters the codec of a data file.
repair Recovers data from a corrupt Avro Data file
rpcprotocol Output the protocol of a RPC service
rpcreceive Opens an RPC Server and listens for one message.
rpcsend Sends a single RPC message.
tether Run a tethered mapreduce job.
tojson Dumps an Avro data file as JSON, record per line or pretty.
totext Converts an Avro data file to a text file.
totrevni Converts an Avro data file to a Trevni file.
trevni_meta Dumps a Trevni file's metadata as JSON.
trevni_random Create a Trevni file filled with random instances of a schema.
trevni_tojson Dumps a Trevni file as JSON.

2.查看avro文件的schema

1
2
java -jar ./avro-tools-1.10.1.jar getschema ./xxxx.avro

3.查看avro文件内容的json格式

1
2
java -jar ./avro-tools-1.10.1.jar tojson ./nova_ads_access_log-0-0008589084.avro | less

4.使用avro-tools编译java代码

编译avro IDL文件,参考

1
2
https://avro.apache.org/docs/current/gettingstartedjava.html
https://yanbin.blog/convert-apache-avro-to-parquet-format-in-java/

定义schema文件kst.avsc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"namespace": "com.linkedin.haivvreo",
"name": "test_serializer",
"type": "record",
"fields": [
{ "name":"string1", "type":"string" },
{ "name":"int1", "type":"int" },
{ "name":"tinyint1", "type":"int" },
{ "name":"smallint1", "type":"int" },
{ "name":"bigint1", "type":"long" },
{ "name":"boolean1", "type":"boolean" },
{ "name":"float1", "type":"float" },
{ "name":"double1", "type":"double" },
{ "name":"list1", "type":{"type":"array", "items":"string"} },
{ "name":"map1", "type":{"type":"map", "values":"int"} },
{ "name":"struct1", "type":{"type":"record", "name":"struct1_name", "fields": [
{ "name":"sInt", "type":"int" }, { "name":"sBoolean", "type":"boolean" }, { "name":"sString", "type":"string" } ] } },
{ "name":"union1", "type":["float", "boolean", "string"] },
{ "name":"enum1", "type":{"type":"enum", "name":"enum1_values", "symbols":["BLUE","RED", "GREEN"]} },
{ "name":"nullableint", "type":["int", "null"] },
{ "name":"bytes1", "type":"bytes" },
{ "name":"fixed1", "type":{"type":"fixed", "name":"threebytes", "size":3} }
] }

编译avro IDL文件

1
2
java -jar ./src/main/resources/avro-tools-1.10.1.jar compile schema ./src/main/avro/kst.avsc ./src/main/java

全文 >>

Ubuntu下的MySQL安装

1.安装mysql-server

1
2
3
sudo apt-get update
sudo apt-get install mysql-server mysql-client

2.重新启动mysql服务

1
2
sudo service mysql restart

3.让apache支持mysql

1
2
sudo apt-get install libapache2-mod-auth-mysql

16.04使用下面命令

1
2
sudo apt-get install libmysqlclient-dev

4.登录mysql

1
2
mysql -u root -p

如果修改了配置文件my.cnf配置文件,需要重启数据库(修改方法在下面),重启数据库之前需要先重新载入apparmor配置文件,使用下面命令重新载入:

1
2
sudo /etc/init.d/apparmor restart

重新启动数据库

1
2
sudo /etc/init.d/mysql start

5.查看数据库的编码

1.查看MySQL数据库服务器和数据库MySQL字符集。

1
2
SHOW VARIABLES LIKE 'character_set_%';

全文 >>

元注解(Annotation)

J2SE 5.0提供了很多新的特征。其中一个很重要的特征就是对元数据(Metadata)的支持。在J2SE 5.0中,这种元数据称为注解(Annotation)。

通过使用注解,程序开发人员可以在不改变原有逻辑的情况下,在源文件嵌入一些补充的信息。

全文 >>