前景
今天高高高兴兴的敲代码,龙飞凤舞,张牙舞爪,帅的一B,创建presenter,modle,view一起合成,复制返回数据,解析json数据,打开GsonFomat->粘贴->OK,帅的一B, 一气合成我都佩服自己,来看看结果
public class ContrastListModel2 {
/**
* car_id : 12345
* rrc_id : bj-53215
* first_img : http://static.renrenche.com/o_1cnldi8vb597881539632895472032546.jpg
* is_promise_sell : 保卖
* status : 已检测
* car_model : 大众-高尔夫 2015款 1.6L自动时尚型
* receive_time : 2018-08-15 16:20
* review_time : 2018-08-28 10:20
* redline_diff_count : 2
* other_diff_count : 5
*/
private int car_id;
private String rrc_id;
private String first_img;
private String is_promise_sell;
private String status;
private String car_model;
private String receive_time;
private String review_time;
private int redline_diff_count;
private int other_diff_count;
public static ContrastListModel2 objectFromData(String str) {
return new Gson().fromJson(str, ContrastListModel2.class);
}
public int getCar_id() {
return car_id;
}
public void setCar_id(int car_id) {
this.car_id = car_id;
}
public String getRrc_id() {
return rrc_id;
}
public void setRrc_id(String rrc_id) {
this.rrc_id = rrc_id;
}
public String getFirst_img() {
return first_img;
}
public void setFirst_img(String first_img) {
this.first_img = first_img;
}
public String getIs_promise_sell() {
return is_promise_sell;
}
public void setIs_promise_sell(String is_promise_sell) {
this.is_promise_sell = is_promise_sell;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getCar_model() {
return car_model;
}
public void setCar_model(String car_model) {
this.car_model = car_model;
}
public String getReceive_time() {
return receive_time;
}
public void setReceive_time(String receive_time) {
this.receive_time = receive_time;
}
public String getReview_time() {
return review_time;
}
public void setReview_time(String review_time) {
this.review_time = review_time;
}
public int getRedline_diff_count() {
return redline_diff_count;
}
public void setRedline_diff_count(int redline_diff_count) {
this.redline_diff_count = redline_diff_count;
}
public int getOther_diff_count() {
return other_diff_count;
}
public void setOther_diff_count(int other_diff_count) {
this.other_diff_count = other_diff_count;
}
}
这是个啥玩意,怎么命名的这么操蛋,驼峰呢??一个一个加@SerializedName改名字吗?我去看了下GsonFormat,好像没有什么能对驼峰命名的定义,好郁闷啊!搜索了下GsonFormat还好是开源的,想了下要不要自己尝试改一改,我感觉还是有这个必要的因为后端哪里命名规则是下划线为标准的,以后改这个地方挺多的,还是改下吧!
1:开始动工-学习下简单的插件开发
2:下载GsonFormat源码
https://github.com/DimRed/GsonFormat
3:导入项目
花了好几个失效,下载该下载的东西,又是翻墙又是等待,我的亲娘啊折腾死了,当我准备调试运行的时候,我郁闷了,怎么开源的是导入的结构和上门的资料上不一样啊,开源的源码怎么好像是用Gradle构建的呀,脑壳疼!折腾了半天,由于我是小白,折腾了半天,也没啥资料,最后没办法,我想到了自己创建一个项目
1:按照资料1提供的教程,创建一个plugin项目
2:复制GsonFormat源码,粘贴到src目录
3:复制GsonFormat的resources目录,替换自己创建的项目
OK运行一下
发现打开了另外一个Intellij创建,我想了下这个窗口就应该能用GsonFormat了,测试发现也可以
2:代码好了,接下来修改代码
通过上面的学习人,我们知道插件肯定有Action的一个入口,都知道GsonFormat都是在Generate中所以找了下这个Action
可以看到当点击的时候会,打开一个JsonDialog的diaog,这也就是第一个ui,定位了下位置
想了下我是不是应该,在设置界面加入一个,智能驼峰命名的选项呀,SettingDialog.form,添加了个智能驼峰命名
修改SettingDialog代码,注释上门都有
package org.gsonformat.intellij.ui;
import com.intellij.openapi.project.Project;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.VariableKind;
import org.apache.http.util.TextUtils;
import org.gsonformat.intellij.config.Config;
import org.gsonformat.intellij.config.Constant;
import javax.swing.*;
import java.awt.event.*;
public class SettingDialog extends JFrame {
private JPanel contentPane;
private JRadioButton fieldPublicRadioButton;
private JRadioButton fieldPrivateRadioButton;
private JCheckBox useSerializedNameCheckBox;
private JButton objectButton;
private JButton object1Button;
private JButton arrayButton;
private JButton array1Button;
private JTextField suffixEdit;
private JCheckBox objectFromDataCB;
private JCheckBox objectFromData1CB;
private JCheckBox arrayFromDataCB;
private JCheckBox arrayFromData1CB;
private JCheckBox reuseEntityCB;
/**
* 是否驼峰命名的checkBox控件
*/
private JCheckBox isAutoName;
private JButton cancelButton;
private JButton okButton;
private JTextField filedPrefixTF;
private JCheckBox filedPrefixCB;
private JRadioButton gsonJRB;
private JRadioButton jackRB;
private JRadioButton fastJsonRB;
private JRadioButton otherRB;
private JTextField annotationFT;
private JCheckBox virgoModelCB;
private JCheckBox generateCommentsCT;
private JRadioButton loganSquareCB;
private JRadioButton autoValueRadioButton;
private JCheckBox splitGenerateMode;
private JRadioButton lombokRB;
private String annotaionStr;
private JCheckBox useWrapperClassCB;
public SettingDialog(Project project) {
setContentPane(contentPane);
// setModal(true);
getRootPane().setDefaultButton(okButton);
this.setAlwaysOnTop(true);
setTitle("Setting");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListen