我们通过4个实例来具体学习java web开发.这一篇我们讲例子1. 品牌管理(不带mysql的)、即第一篇章中所讲的 没有关系的
第一步: 创建java工程,创建实体类
代码-pojo:
package com.rengl.pojo; import java.io.Serializable; /** * time: 2023-05-04 17:05 * author: rengl */ public class Brand implements Serializable { private Integer id; private String title; private String path; public Brand() { } public Brand(Integer id, String title, String path) { this.id = id; this.title = title; this.path = path; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } }
package com.rengl.pojo; /** * 全局结果 * author:rengl * 2023-05-04 1:27 */ public class Result { private boolean code; private String msg; private Object data; public Result(boolean code, String msg,Object data) { this.code = code; this.msg = msg; this.data = data; } public Result() { } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Object getData() { return data; } public void setData(Object data) { this.data = data; } public void setCode(boolean code) { this.code = code; } }
因为没有mysql,我们用java中List作为存储.缺点就是不能持久化.优点是更纯粹的java
代码-dao:
package com.rengl.dao; import com.rengl.pojo.Brand; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * author:rengl * 2023-05-04 17:12 * 模拟持久层,纯java状态下从内存中查询List */ public class BrandMapper { private List<Brand> list = new ArrayList(); priva