IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> javaweb-30:smbms项目搭建 -> 正文阅读

[大数据]javaweb-30:smbms项目搭建

SMBMS

在这里插入图片描述

数据库:

sql脚本:【通过sqlyog图形化界面操作,在历史记录中对应相应的sql,表的引擎默认为InnoDB,字符集和核对默认和数据库一致】

CREATE DATABASE `smbms`CHARACTER SET utf8 COLLATE utf8_general_ci; 
USE `smbms`; 

 CREATE TABLE `smbms`.`smbms_user` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `userCode` VARCHAR(15), `userName` VARCHAR(15), `userPassword` VARCHAR(15), `gender` INT(10), `birthday` DATE, `phone` VARCHAR(15), `address` VARCHAR(30), `userRole` BIGINT, `createBy` BIGINT, `creationDate` DATETIME, `modifyBy` BIGINT, `modifyDate` DATETIME, PRIMARY KEY (`id`) ); 
 
 CREATE TABLE `smbms`.`smbms_role` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `roleCode` VARCHAR(30), `roleName` VARCHAR(30), `createBy` BIGINT, `creationDate` DATETIME, `modifyBy` BIGINT, `modifyDate` DATETIME, PRIMARY KEY (`id`) ); 

 CREATE TABLE `smbms`.`smbms_address` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `contact` VARCHAR(30), `addressDesc` VARCHAR(30), `postCode` VARCHAR(30), `tel` VARCHAR(30), `createBy` BIGINT, `creationDate` DATETIME, `modifyBy` BIGINT, `modifyDate` DATETIME, `userId` BIGINT, PRIMARY KEY (`id`) ); 
 
 CREATE TABLE `smbms`.`smbms_bill` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `billCode` VARCHAR(30), `productName` VARCHAR(30), `productDesc` VARCHAR(100), `productUnit` VARCHAR(10), `productCount` DECIMAL(20,2), `totalPrice` DECIMAL(20,2), `isPayment` INT, `createBy` BIGINT, `creationDate` DATETIME, `modifyBy` BIGINT, `modifyDate` DATETIME, `providerId` BIGINT, PRIMARY KEY (`id`) ); 

 CREATE TABLE `smbms`.`smbms_provider` ( `id` BIGINT NOT NULL AUTO_INCREMENT, `proCode` VARCHAR(30), `proName` VARCHAR(50), `proDesc` VARCHAR(100), `proContact` VARCHAR(50), `proPhone` VARCHAR(30), `proAddress` VARCHAR(100), `proFax` VARCHAR(30), `createBy` BIGINT, `creationDate` DATETIME, `modifyBy` BIGINT, `modifyDate` DATETIME, PRIMARY KEY (`id`) ); 

设计器:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-m9WdQMEv-1635065824070)(C:\Users\Administrator\Desktop\学习笔记\javaweb\javaweb-30:smbms项目搭建.assets\image-20211024145402084.png)]

项目如何搭建?

考虑使用不使用maven?依赖,jar

项目搭建准备工作

1.搭建一个maven web项目

1)根据idea 的maven模板创建一个web项目

2)pom中删除非必要的东西(只留gav坐标及打包方式)

3)补全目录(java和resources)

4)web.xml改为新版:4.0的

2.配置tomcat

3.测试项目是否能够跑起来

4.导入项目中会遇到的jar包

jsp,servlet,mysql驱动,jstl,standard…

5.创建项目包结构

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-o9fFjGq0-1635065824073)(C:\Users\Administrator\Desktop\学习笔记\javaweb\javaweb-30:smbms项目搭建.assets\image-20211024151841643.png)]

6.编写实体类

ORM映射:表-类 映射

可以通过idea右侧数据库的mybatis-generator创建-生成实体未驼峰命名

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-EEecS07q-1635065824076)(C:\Users\Administrator\Desktop\学习笔记\javaweb\javaweb-30:smbms项目搭建.assets\image-20211024154555138.png)]

实体类属性最好加注释

7.编写基础公共类

? 1.数据库配置文件

? 2.编写数据库的公共类

? 3.编写字符编码过滤器

8.导入静态资源

放在webapp目录下

代码show

pojo/Bill.java

package com.gongyi.pojo;

import java.math.BigDecimal;
import java.util.Date;


public class Bill {
    private Integer id;//id

    private String billCode;//账单编码

    private String productName;//商品名称

    private String productDesc;//商品描述

    private String productUnit;//商品单位

    private BigDecimal productCount;//商品数量

    private BigDecimal totalPrice;//总金额

    private Integer isPayment;//是否支付

    private Long createBy;//创建者

    private Date creationDate;//创建时间

    private Long modifyBy;//更新者

    private Date modifyDate;//更新时间

    private Long providerId;//供应商id

    private String providerName;//供应商名称

    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 BigDecimal getProductCount() {
        return productCount;
    }

    public void setProductCount(BigDecimal productCount) {
        this.productCount = productCount;
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public Integer getIsPayment() {
        return isPayment;
    }

    public void setIsPayment(Integer isPayment) {
        this.isPayment = isPayment;
    }

    public String getProviderName() {
        return providerName;
    }

    public void setProviderName(String providerName) {
        this.providerName = providerName;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Long getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(Long modifyBy) {
        this.modifyBy = modifyBy;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    public Long getProviderId() {
        return providerId;
    }

    public void setProviderId(Long providerId) {
        this.providerId = providerId;
    }
}

pojo/Provider.java

package com.gongyi.pojo;

import java.util.Date;


public class Provider {
    private Integer id;//id

    private String proCode;//供应商编码

    private String proName;//供应商名称

    private String proDesc;//供应商描述

    private String proContact;//供应商联系人

    private String proPhone;//供应商电话

    private String proAddress;//供应商地址

    private String proFax;//供应商传真

    private Long createBy;//创建者

    private Date creationDate;//创建时间

    private Long modifyBy;//更新者

    private Date modifyDate;//更新时间

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getProCode() {
        return proCode;
    }

    public void setProCode(String proCode) {
        this.proCode = proCode;
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public String getProDesc() {
        return proDesc;
    }

    public void setProDesc(String proDesc) {
        this.proDesc = proDesc;
    }

    public String getProContact() {
        return proContact;
    }

    public void setProContact(String proContact) {
        this.proContact = proContact;
    }

    public String getProPhone() {
        return proPhone;
    }

    public void setProPhone(String proPhone) {
        this.proPhone = proPhone;
    }

    public String getProAddress() {
        return proAddress;
    }

    public void setProAddress(String proAddress) {
        this.proAddress = proAddress;
    }

    public String getProFax() {
        return proFax;
    }

    public void setProFax(String proFax) {
        this.proFax = proFax;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Long getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(Long modifyBy) {
        this.modifyBy = modifyBy;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }
}

pojo/Role.java

package com.gongyi.pojo;

import java.util.Date;


public class Role {
    private Integer id;//id

    private String roleCode;//角色编码

    private String roleName;//角色名称

    private Long createBy;//创建者

    private Date creationDate;//创建时间

    private Long modifyBy;//更新者

    private Date modifyDate;//更新时间

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getRoleCode() {
        return roleCode;
    }

    public void setRoleCode(String roleCode) {
        this.roleCode = roleCode;
    }

    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Long getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(Long modifyBy) {
        this.modifyBy = modifyBy;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }
}

pojo/User.java

package com.gongyi.pojo;

import java.util.Date;


public class User {
    private Integer id;//id

    private String userCode;//用户编码

    private String userName;//用户名称

    private String userPassword;//用户密码

    private Integer gender;//性别

    private Date birthday;//出生日期

    private String phone;//电话

    private String address;//地址

    private Long userRole;//用户角色

    private Long createBy;//创建者

    private Date creationDate;//创建时间

    private Long modifyBy;//更新者

    private Date modifyDate;//更新时间

    private Integer age;//年龄

    private String userRoleName;//用户角色名称

    public Integer getAge() {
        Date date = new Date();
        Integer age = date.getYear() - birthday.getYear();
        return age;
    }



    public String getUserRoleName() {
        return userRoleName;
    }

    public void setUserRoleName(String userRoleName) {
        this.userRoleName = userRoleName;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Long getUserRole() {
        return userRole;
    }

    public void setUserRole(Long userRole) {
        this.userRole = userRole;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Long getModifyBy() {
        return modifyBy;
    }

    public void setModifyBy(Long modifyBy) {
        this.modifyBy = modifyBy;
    }

    public Date getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }
}

dao/BaseDao.java

package com.gongyi.dao;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

//操作数据库的公共类
public class BaseDao {
    private static String driver;
    private static String url;
    private static String username;
    private static String password;

    //静态代码块,类加载的时候就初始化了
    static {
        Properties properties = new Properties();
        //通过类加载器读取对应的资源
        InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        driver = properties.getProperty("driver");
        url = properties.getProperty("url");
        username = properties.getProperty("username");
        password = properties.getProperty("password");
    }

    //获取数据库的连接
    public static Connection getConnection() {
        Connection connection = null;
        try {
            Class.forName(driver);
            connection = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }

    //编写查询公共方法
    public static ResultSet execute(Connection connection, String sql, Object[] params, ResultSet resultSet, PreparedStatement preparedStatement) throws SQLException {
        //预编译的SQL,在后面直接执行就可以了
        preparedStatement = connection.prepareStatement(sql);
        for (int i = 0; i < params.length; i++) {
            //setObject,占位符从1开始,但是我们的数组是从0开始
            preparedStatement.setObject(i + 1, params[i]);
        }
        resultSet = preparedStatement.executeQuery();
        return resultSet;
    }

    //编写增删改公共方法
    public static int execute(Connection connection, String sql, Object[] params, PreparedStatement preparedStatement) throws SQLException {
        preparedStatement = connection.prepareStatement(sql);
        for (int i = 0; i < params.length; i++) {
            //setObject,占位符从1开始,但是我们的数组是从0开始
            preparedStatement.setObject(i + 1, params[i]);
        }
        int updateRows = preparedStatement.executeUpdate();
        return updateRows;
    }

    //释放资源
    public static boolean closeResource(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) {
        boolean flag = true;
        if (resultSet != null) {
            try {
                resultSet.close();
                //GC回收
                resultSet = null;
            } catch (SQLException e) {
                e.printStackTrace();
                flag = false;
            }
        }
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
                //GC回收
                preparedStatement = null;
            } catch (SQLException e) {
                e.printStackTrace();
                flag = false;
            }
        }
        if (connection != null) {
            try {
                connection.close();
                //GC回收
                connection = null;
            } catch (SQLException e) {
                e.printStackTrace();
                flag = false;
            }
        }
        return flag;
    }
}

filter/CharacterEncodingFilter.java

package com.gongyi.filter;


import javax.servlet.*;
import java.io.IOException;

public class CharacterEncodingFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        chain.doFilter(request, response);
    }

    public void destroy() {

    }
}

db.properties

driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306?useUnicode=true&characterEncoding=utf-8
username=root
password=123456

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0"
         metadata-complete="true">
    <!--字符编码过滤器-->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>com.gongyi.filter.CharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.gongyi</groupId>
    <artifactId>smbms</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</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>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
    </dependencies>
</project>

代码结构图:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iKBQNwcT-1635065824079)(C:\Users\Administrator\Desktop\学习笔记\javaweb\javaweb-30:smbms项目搭建.assets\image-20211024165345344.png)]

静态资源下载地址

彩蛋

1.sql yog中的架构设计器

2.idea maven web配置tomcat fix时无artifactId可添加

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2VxY7pKE-1635065824081)(C:\Users\Administrator\Desktop\学习笔记\javaweb\javaweb-30:smbms项目搭建.assets\image-20211024150937365.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xHZ7cksO-1635065824082)(C:\Users\Administrator\Desktop\学习笔记\javaweb\javaweb-30:smbms项目搭建.assets\image-20211024150947735.png)]

解决:maven用idea自带的默认的就行,3.8.1不行

3.idea取消重复代码提醒:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1PvoppFG-1635065824083)(C:\Users\Administrator\Desktop\学习笔记\javaweb\javaweb-30:smbms项目搭建.assets\image-20211024163737454.png)]

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-10-25 12:36:07  更:2021-10-25 12:38:43 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 2:48:34-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码