“Java MVC之用到的实体类”的版本间的差异
来自CloudWiki
(创建页面,内容为“ ====用到的实体类:Goods==== <nowiki>package entity; public class Goods { protected String id; //商品编号 protected String name; //商品名称 pro…”) |
|||
第1行: | 第1行: | ||
+ | ==用户类:User== | ||
+ | <nowiki>package entity; | ||
+ | |||
+ | |||
+ | |||
− | ==== | + | |
+ | import service.*; | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | public class User { | ||
+ | private String id; //用户登录账号 | ||
+ | private String name; //用户名-真实姓名 | ||
+ | private String password;//用户登录密码 | ||
+ | |||
+ | |||
+ | /** | ||
+ | * 无参构造函数 | ||
+ | */ | ||
+ | public User() { | ||
+ | |||
+ | } | ||
+ | |||
+ | /** | ||
+ | * 带参构造函数 | ||
+ | * | ||
+ | * | ||
+ | * @param name | ||
+ | * @param password | ||
+ | |||
+ | */ | ||
+ | public User(String name, String password) { | ||
+ | this(); | ||
+ | this.name = name; | ||
+ | this.password = password; | ||
+ | |||
+ | } | ||
+ | |||
+ | public String getId() { | ||
+ | return id; | ||
+ | } | ||
+ | public void setId(String id) { | ||
+ | this.id = id; | ||
+ | } | ||
+ | public String getName() { | ||
+ | return name; | ||
+ | } | ||
+ | public void setName(String name) { | ||
+ | this.name = name; | ||
+ | } | ||
+ | public String getPassword() { | ||
+ | return password; | ||
+ | } | ||
+ | public void setPassword(String password) { | ||
+ | this.password = password; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | @Override | ||
+ | public String toString() { | ||
+ | return "用户编号:" + this.id + | ||
+ | " | 用户姓名:" + this.name; | ||
+ | } | ||
+ | } | ||
+ | </nowiki> | ||
+ | ==商品类:Goods== | ||
<nowiki>package entity; | <nowiki>package entity; | ||
第69行: | 第136行: | ||
} | } | ||
+ | |||
</nowiki> | </nowiki> | ||
− | == | + | ==商品标签类:Tag== |
<nowiki>package entity; | <nowiki>package entity; | ||
第126行: | 第194行: | ||
+ | } | ||
+ | </nowiki> | ||
+ | ==商品子类:Book类== | ||
+ | <nowiki>package entity; | ||
+ | |||
+ | public class Book extends Goods{ | ||
+ | String author; // 书籍作者 | ||
+ | |||
+ | |||
+ | public Book() { | ||
+ | } | ||
+ | public Book(String cid, String name, int number,float price) { | ||
+ | super(cid, name, price, number); | ||
+ | } | ||
+ | public Book(String cid, String name, String author, float price, | ||
+ | int number,Tag tag) { | ||
+ | super(cid, name,price,number,tag); | ||
+ | this.author = author; | ||
+ | } | ||
+ | |||
+ | public String getAuthor() { | ||
+ | return author; | ||
+ | } | ||
+ | public void setAuthor(String author) { | ||
+ | this.author = author; | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public String toString() { | ||
+ | return "商品编号:" + this.id + " | 商品名:" + this.name | ||
+ | + " | 商品总数:" + this.number+" |商品价格:"+this.price | ||
+ | +" | 作者:" + this.author+ " | 类目:" + this.tag ; | ||
+ | } | ||
+ | |||
+ | }</nowiki> | ||
+ | |||
+ | ==商品子类:Ipad类== | ||
+ | <nowiki>package entity; | ||
+ | |||
+ | public class Ipad extends Goods { | ||
+ | private String model; // 平板电脑型号 | ||
+ | |||
+ | public String getModel() { | ||
+ | return model; | ||
+ | } | ||
+ | public void setModel(String model) { | ||
+ | this.model = model; | ||
+ | } | ||
+ | |||
+ | public Ipad() { | ||
+ | } | ||
+ | |||
+ | |||
+ | public Ipad(String id, String name, | ||
+ | float price, int number, String model, Tag tag) { | ||
+ | |||
+ | super(id, name,price,number,tag); | ||
+ | // | ||
+ | this.model = model; | ||
+ | |||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public String toString() { | ||
+ | return "商品编号:" + this.id + " | 商品名:" + this.name | ||
+ | +" | 商品总数:" + this.number+" |商品价格:"+this.price | ||
+ | +" | 型号:" + this.model+ "|商品分类:"+this.tag.toString(); | ||
+ | } | ||
+ | |||
}</nowiki> | }</nowiki> | ||
+ | |||
+ | 返回 [[Java程序设计]] |
2018年6月18日 (一) 01:28的最新版本
用户类:User
package entity; import service.*; public class User { private String id; //用户登录账号 private String name; //用户名-真实姓名 private String password;//用户登录密码 /** * 无参构造函数 */ public User() { } /** * 带参构造函数 * * * @param name * @param password */ public User(String name, String password) { this(); this.name = name; this.password = password; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "用户编号:" + this.id + " | 用户姓名:" + this.name; } }
商品类:Goods
package entity; public class Goods { protected String id; //商品编号 protected String name; //商品名称 protected int number; //商品库存 protected float price; //商品价格 protected Tag tag; // 书籍详细分类(类目) public Goods(){} public Goods(String id,String name,float price,int number){ this.id = id; this.name = name; this.number = number; this.price = price; } public Goods(String id, String name, float price, int number,Tag tag) { this.id = id; this.name = name; this.number = number; this.price = price; this.tag = tag; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } public Tag getTag() { return tag; } public void setTag(Tag tag) { this.tag = tag; } @Override public String toString() { return "Goods [id=" + id + ", name=" + name + ", number=" + number + ", price=" + price +"tag="+tag+ "]"; } }
商品标签类:Tag
package entity; public class Tag { private int id = 0; //商品一级类目 private String firstLevel; //商品二级类目 private String secondLevel; /* * 无参构造函数 */ public Tag() {} /* * 带三个参数的构造函数 */ public Tag(int id, String firstLevel, String secondLevel) { this.id = id; this.firstLevel = firstLevel; this.secondLevel = secondLevel; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFirstLevel() { return firstLevel; } public void setFirstLevel(String firstLevel) { this.firstLevel = firstLevel; } public String getSecondLevel() { return secondLevel; } public void setSecondLevel(String secondLevel) { this.secondLevel = secondLevel; } @Override public String toString() { return this.firstLevel + ">" + this.secondLevel; } }
商品子类:Book类
package entity; public class Book extends Goods{ String author; // 书籍作者 public Book() { } public Book(String cid, String name, int number,float price) { super(cid, name, price, number); } public Book(String cid, String name, String author, float price, int number,Tag tag) { super(cid, name,price,number,tag); this.author = author; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } @Override public String toString() { return "商品编号:" + this.id + " | 商品名:" + this.name + " | 商品总数:" + this.number+" |商品价格:"+this.price +" | 作者:" + this.author+ " | 类目:" + this.tag ; } }
商品子类:Ipad类
package entity; public class Ipad extends Goods { private String model; // 平板电脑型号 public String getModel() { return model; } public void setModel(String model) { this.model = model; } public Ipad() { } public Ipad(String id, String name, float price, int number, String model, Tag tag) { super(id, name,price,number,tag); // this.model = model; } @Override public String toString() { return "商品编号:" + this.id + " | 商品名:" + this.name +" | 商品总数:" + this.number+" |商品价格:"+this.price +" | 型号:" + this.model+ "|商品分类:"+this.tag.toString(); } }
返回 Java程序设计