1. 创建一个Maven项目
2. 添加web结构
3. 配置Tomcat
4. 测试项目是否能够跑起来
5. 导入jar包
一开始应该导入servlet,mysql,jsp包
| <dependencies> |
| |
| <dependency> |
| <groupId>javax.servlet</groupId> |
| <artifactId>javax.servlet-api</artifactId> |
| <version>4.0.1</version> |
| </dependency> |
| |
| <dependency> |
| <groupId>javax.servlet.jsp</groupId> |
| <artifactId>javax.servlet.jsp-api</artifactId> |
| <version>2.3.3</version> |
| </dependency> |
| |
| <dependency> |
| <groupId>mysql</groupId> |
| <artifactId>mysql-connector-java</artifactId> |
| <version>5.1.47</version> |
| </dependency> |
| </dependencies> |
6.创建项目包结构

dao:主要写有关于数据库的java代码
Filter:编写过滤器代码
pojo:编写实体类代码,OMG映射:表和类的映射
service:业务代码
servlet:servlet代码,主要用于取参数
7.编写实体类(表和类的映射)
| public class Bill { |
| private Integer id; |
| private String billCode; |
| private String productName; |
| private String productDesc; |
| private String productUnit; |
| private String productCount; |
| private String totallPrice; |
| private Integer isPayment; |
| private Integer createBy; |
| private Date createDate; |
| private String modifyBy; |
| private String modifyDate; |
| private Integer providerId; |
| |
| public Bill(Integer id, String billCode, String productName, String productDesc, String productUnit, String productCount, String totallPrice, Integer isPayment, Integer createBy, Date createDate, String modifyBy, String modifyDate, Integer providerId) { |
| this.id = id; |
| this.billCode = billCode; |
| this.productName = productName; |
| this.productDesc = productDesc; |
| this.productUnit = productUnit; |
| this.productCount = productCount; |
| this.totallPrice = totallPrice; |
| this.isPayment = isPayment; |
| this.createBy = createBy; |
| this.createDate = createDate; |
| this.modifyBy = modifyBy; |
| this.modifyDate = modifyDate; |
| this.providerId = providerId; |
| } |
| |
| public Bill() { |
| } |
| |
| public Integer getId() { |
| return id; |
| } |
| |
| public void setId(Integer id) { |
| this.id = id; |
| } |
| |
| public String getBillCode() { |
| return billCode; |
| } |
| |
| public void setBillCode(String billCode) { |
| this.billCode = billCode; |
| } |
| |
| public String getProductName() { |
| return productName; |
| } |
| |
| public void setProductName(String productName) { |
| this.productName = productName; |
| } |
| |
| public String getProductDesc() { |
| return productDesc; |
| } |
| |
| public void setProductDesc(String productDesc) { |
| this.productDesc = productDesc; |
| } |
| |
| public String getProductUnit() { |
| return productUnit; |
| } |
| |
| public void setProductUnit(String productUnit) { |
| this.productUnit = productUnit; |
| } |
| |
| public String getProductCount() { |
| return productCount; |
| } |
| |
| public void setProductCount(String productCount) { |
| this.productCount = productCount; |
| } |
| |
| public String getTotallPrice() { |
| return totallPrice; |
| } |
| |
| public void setTotallPrice(String totallPrice) { |
| this.totallPrice = totallPrice; |
| } |
| |
| public Integer getIsPayment() { |
| return isPayment; |
| } |
| |
| public void setIsPayment(Integer isPayment) { |
| this.isPayment = isPayment; |
| } |
| |
| public Integer getCreateBy() { |
| return createBy; |
| } |
| |
| public void setCreateBy(Integer createBy) { |
| this.createBy = createBy; |
| } |
| |
| public Date getCreateDate() { |
| return createDate; |
| } |
| |
| public void setCreateDate(Date createDate) { |
| this.createDate = createDate; |
| } |
| |
| public String getModifyBy() { |
| return modifyBy; |
| } |
| |
| public void setModifyBy(String modifyBy) { |
| this.modifyBy = modifyBy; |
| } |
| |
| public String getModifyDate() { |
| return modifyDate; |
| } |
| |
| public void setModifyDate(String modifyDate) { |
| this.modifyDate = modifyDate; |
| } |
| |
| public Integer getProviderId() { |
| return providerId; |
| } |
| |
| public void setProviderId(Integer providerId) { |
| this.providerId = providerId; |
| } |
| } |
8.编写基础公共类
8.1编写数据库公共类
| public class baseDao { |
| private static String driver; |
| private static String url; |
| private static String username; |
| private static String password; |
| static{ |
| Properties ps = new Properties(); |
| |
| InputStream rs = baseDao.class.getClassLoader().getResourceAsStream("db.properties"); |
| try { |
| ps.load(rs); |
| |
| } catch (IOException e) { |
| e.printStackTrace(); |
| } |
| driver=ps.getProperty("driver"); |
| url=ps.getProperty("url"); |
| username=ps.getProperty("username"); |
| password=ps.getProperty("password"); |
| } |
| |
| public static Connection getConnection(){ |
| Connection connection=null; |
| try { |
| Class.forName(driver); |
| connection = DriverManager.getConnection(url, username, password); |
| |
| } catch (Exception throwables) { |
| throwables.printStackTrace(); |
| } |
| return connection; |
| } |
| |
| public static ResultSet Query(Connection connection,String sql,Object[] params){ |
| ResultSet resultSet=null; |
| try { |
| PreparedStatement preparedStatement = connection.prepareStatement(sql); |
| for (int i = 0; i <params.length ; i++) { |
| preparedStatement.setObject(i+1,params[i]); |
| } |
| resultSet = preparedStatement.executeQuery(); |
| |
| } catch (SQLException throwables) { |
| throwables.printStackTrace(); |
| } |
| return resultSet; |
| } |
| |
| public static int update(Connection connection,String sql,Object[] params) throws Exception { |
| PreparedStatement preparedStatement = connection.prepareStatement(sql); |
| for (int i = 0; i < params.length; i++) { |
| preparedStatement.setObject(i+1,params[i]); |
| } |
| int updateRows = preparedStatement.executeUpdate(); |
| return updateRows; |
| } |
| |
| public static Boolean closeResult(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet) { |
| boolean flag = true; |
| if (resultSet != null) { |
| try { |
| resultSet.close(); |
| |
| resultSet = null; |
| } catch (SQLException throwables) { |
| throwables.printStackTrace(); |
| flag = false; |
| } |
| } |
| if (preparedStatement != null) { |
| try { |
| preparedStatement.close(); |
| |
| preparedStatement = null; |
| } catch (SQLException throwables) { |
| throwables.printStackTrace(); |
| flag = false; |
| } |
| } |
| if (connection != null) { |
| try { |
| connection.close(); |
| |
| connection = null; |
| } catch (SQLException throwables) { |
| throwables.printStackTrace(); |
| flag = false; |
| } |
| } |
| return flag; |
| } |
| } |
8.2编写字符过滤器
| public class characterEncodingFilter implements Filter { |
| |
| public void init(FilterConfig filterConfig) throws ServletException { |
| |
| } |
| |
| public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| servletRequest.setCharacterEncoding("utf-8"); |
| servletResponse.setCharacterEncoding("utf-8"); |
| servletResponse.setContentType("text/html;charset=UTF-8"); |
| filterChain.doFilter(servletRequest,servletResponse); |
| } |
| |
| public void destroy() { |
| |
| } |
| } |
9导入网页静态资源
https://gitee.com/git_baboben/smbms?_from=gitee_search

准备工作完成
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix