数据对象如何定义为Java代码示例

Posted 鹰击长空,万类霜天竞自由!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据对象如何定义为Java代码示例相关的知识,希望对你有一定的参考价值。

想将数据保存为这样子:

[{
		"subject": {
			"code": "B123",
			"words": [{
				"key": "gjc1",
				"wight": 9.8,
				"ct": 1575126920
			}, {
				"key": "gjc1",
				"wight": 9.8,
				"ct": 1575126920
			}, {
				"key": "gjc1",
				"wight": 9.8,
				"ct": 1575126920
			}],
			"wight": 3,
			"ct": 1575126920
		}
	}, {
		"subject": {
			"code": "C456",
			"words": [{
				"key": "gjc1",
				"wight": 9.8,
				"ct": 1575126920
			}, {
				"key": "gjc1",
				"wight": 9.8,
				"ct": 1575126920
			}, {
				"key": "gjc1",
				"wight": 9.8,
				"ct": 1575126920
			}],
			"wight": 3,
			"ct": 1575126920
		}
	}

]

  

转换为Java后,如:

/**
  * Copyright 2019 bejson.com 
  */
package com.besjon.pojo;

/**
 * Auto-generated: 2019-11-30 23:24:14
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
public class JsonRootBean {

    private Subject subject;
    public void setSubject(Subject subject) {
         this.subject = subject;
     }
     public Subject getSubject() {
         return subject;
     }

}

 

/**
  * Copyright 2019 bejson.com 
  */
package com.besjon.pojo;
import java.util.List;

/**
 * Auto-generated: 2019-11-30 23:24:14
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
public class Subject {

    private String code;
    private List<Words> words;
    private int wight;
    private long ct;
    public void setCode(String code) {
         this.code = code;
     }
     public String getCode() {
         return code;
     }

    public void setWords(List<Words> words) {
         this.words = words;
     }
     public List<Words> getWords() {
         return words;
     }

    public void setWight(int wight) {
         this.wight = wight;
     }
     public int getWight() {
         return wight;
     }

    public void setCt(long ct) {
         this.ct = ct;
     }
     public long getCt() {
         return ct;
     }

}

  

/**
  * Copyright 2019 bejson.com 
  */
package com.besjon.pojo;

/**
 * Auto-generated: 2019-11-30 23:24:14
 *
 * @author bejson.com (i@bejson.com)
 * @website http://www.bejson.com/java2pojo/
 */
public class Words {

    private String key;
    private double wight;
    private long ct;
    public void setKey(String key) {
         this.key = key;
     }
     public String getKey() {
         return key;
     }

    public void setWight(double wight) {
         this.wight = wight;
     }
     public double getWight() {
         return wight;
     }

    public void setCt(long ct) {
         this.ct = ct;
     }
     public long getCt() {
         return ct;
     }

}

  

 

直此,完成!!!

 

 

 

 

  

以上是关于数据对象如何定义为Java代码示例的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段12——JavaScript的Promise对象

VSCode自定义代码片段——JS中的面向对象编程

VSCode自定义代码片段9——JS中的面向对象编程

Android - 如何将自定义对象传递给片段

java 如何实现判断一个对象所有的属性是不是为空

java 代码片段