1.项目准备工作(到这个阶段,想必java的相关环境已经熟练配置了,有问题可联Q,相互交流,相互进步:810806242)
(1)创建一个maven项目,使用webapp模板
(2)在idea的该项目中配置tomcat
(3)测试项目环境,运行tomcat后,在浏览器打开index.html页面,出现hello world,环境配置成功
(4)在pom.xml中导入jsp,servlet,连接数据库的依赖,jstl,standard依赖
1 <dependency> 2 <groupId>javax.servlet</groupId> 3 <artifactId>servlet-api</artifactId> 4 <version>2.5</version> 5 </dependency> 6 <dependency> 7 <groupId>javax.servlet.jsp</groupId> 8 <artifactId>javax.servlet.jsp-api</artifactId> 9 <version>2.3.3</version> 10 </dependency> 11 <dependency> 12 <groupId>mysql</groupId> 13 <artifactId>mysql-connector-java</artifactId> 14 <version>5.1.47</version> 15 </dependency> 16 <dependency> 17 <groupId>javax.servlet.jsp.jstl</groupId> 18 <artifactId>jstl-api</artifactId> 19 <version>1.2</version> 20 </dependency> 21 <dependency> 22 <groupId>taglibs</groupId> 23 <artifactId>standard</artifactId> 24 <version>1.1.2</version> 25 </dependency>
(5)创建项目目录结构(可能以后会根据个人需求增加相关的目录结构以及文件,但是这几个是基本的)
(6)编写实体类(bean),进行ORM映射(数据库表-类之间的映射,注意:实体类的编写要与数据库字段相对应,数据库文件链接:https://pan.baidu.com/s/1Cqyw3_vcDBHz7UDft8rCDQ提取码:6666 ),以bill表为例,bill表字段为
bill表对应的实体类代码(实体类中无非是,对应字段的变量声明,加上构造器和get,set方法),其余数据库表同理。
1 package com.xiaoma.pojo; 2 3 import java.util.Date; 4 5 public class Bill { 6 private int ID;//主键ID 7 private String BillCode;//账单编码 8 private String ProductName;//商品名称 9 private String ProductDesc;//商品描述 10 private String ProductUnit;//商品单位 11 private float ProductCount;//商品数量 12 private float TotalPrice;//商品总额 13 private int IsPayment;//是否支付 14 private int CreatedBy;//创建者 15 private Date CreationDate;//创建时间 16 private int ModifyBy;//修改者 17 private Date ModifyDate;//修改时间 18 private int ProviderId;//供应商ID 19 20 public Bill() { 21 } 22 23 public Bill(int ID, String billCode, String productName, String productDesc, String productUnit, 24 float productCount, float totalPrice, int isPayment, int createdBy, Date creationDate, 25 int modifyBy, Date modifyDate, int providerId) { 26 this.ID = ID; 27 BillCode = billCode; 28 ProductName = productName; 29 ProductDesc = productDesc; 30 ProductUnit = productUnit; 31 ProductCount = productCount; 32 TotalPrice = totalPrice; 33 IsPayment = isPayment; 34 CreatedBy = createdBy; 35 CreationDate = creationDate; 36 ModifyBy = modifyBy; 37 ModifyDate = modifyDate; 38 ProviderId = providerId; 39 } 40 41 public int getID() { 42 return ID; 43 } 44 45 public void setID(int ID) { 46 this.ID = ID; 47 } 48 49 public String getBillCode() { 50 return BillCode; 51 } 52 53 public void setBillCode(String billCode) { 54 BillCode = billCode; 55 } 56 57 public String getProductName() { 58 return ProductName; 59 } 60 61 public void setProductName(String productName) { 62 ProductName = productName; 63 } 64 65 public String getProductDesc() { 66 return ProductDesc; 67 } 68 69 public void setProductDesc(String productDesc) { 70 ProductDesc = productDesc; 71 } 72 73 public String getProductUnit() { 74 return ProductUnit; 75 } 76 77 public void setProductUnit(String productUnit) { 78 ProductUnit = productUnit; 79 } 80 81 public float getProductCount() { 82 return ProductCount; 83 } 84 85 public void setProductCount(float productCount) { 86 ProductCount = productCount; 87 } 88 89 public float getTotalPrice() { 90 return TotalPrice; 91 } 92 93 public void setTotalPrice(float totalPrice) { 94 TotalPrice = totalPrice; 95 } 96 97 public int getIsPayment() { 98 return IsPayment; 99 } 100 101 public void setIsPayment(int isPayment) { 102 IsPayment = isPayment; 103 } 104 105 public int getCreatedBy() { 106 return CreatedBy; 107 } 108 109 public void setCreatedBy(int createdBy) { 110 CreatedBy = createdBy; 111 } 112 113 public Date getCreationDate() { 114 return CreationDate; 115 } 116 117 public void setCreationDate(Date creationDate) { 118 CreationDate = creationDate; 119 } 120 121 public int getModifyBy() { 122 return ModifyBy; 123 } 124 125 public void setModifyBy(int modifyBy) { 126 ModifyBy = modifyBy; 127 } 128 129 public Date getModifyDate() { 130 return ModifyDate; 131 } 132 133 public void setModifyDate(Date modifyDate) { 134 ModifyDate = modifyDate; 135 } 136 137 public int getProviderId() { 138 return ProviderId; 139 } 140 141 public void setProviderId(int providerId) { 142 ProviderId = providerId; 143 } 144 }
(现在时间2021年10月15日晚21:27,欲知后事如何,请听下回分解)
来源:https://www.cnblogs.com/XiaoMaGuai/p/15412760.html