Javaweb超市订单管理系统SMBMS

SMBMS:登陆注销、用户管理、订单管理、供应商管理

系统搭建流程

1、建表:

create table smbms.smbms_address
(
    id           int default 0 not null
        primary key,
    contact      varchar(30)   null,
    addressDesc  varchar(50)   null,
    postCode     varchar(30)   null,
    tel          varchar(20)   null,
    createBy     varchar(50)   null,
    creationDate datetime      null,
    column_8     int           null,
    modifyBy     varchar(50)   null,
    modifyDate   datetime      null,
    userId       varchar(50)   null
);

create table smbms.smbms_bill
(
    id           int default 0 not null
        primary key,
    billCode     int           null,
    productName  varchar(100)  null,
    productDesc  varchar(50)   null,
    productUnit  varchar(50)   null,
    productCount int(4)        null,
    totalPrice   double        null,
    isPayment    varchar(50)   null,
    createBy     varchar(50)   null,
    creationDate datetime      null,
    modifyBy     varchar(50)   null,
    modifyDate   datetime      null,
    provideId    int           null
);

create table smbms.smbms_provider
(
    id           int default 0 not null
        primary key,
    proCode      varchar(30)   null,
    proName      varchar(50)   null,
    proDesc      varchar(50)   null,
    proContact   varchar(50)   null,
    proPhone     varchar(30)   null,
    prAddress    varchar(50)   null,
    proFax       varchar(50)   null,
    createBy     varchar(50)   null,
    creationDate datetime      null,
    modifyBy     varchar(50)   null,
    modifyDate   datetime      null
);

create table smbms.smbms_role
(
    id           int default 0 not null
        primary key,
    roleCode     varchar(50)   null,
    roleName     varchar(50)   null,
    createdBy    varchar(50)   null,
    creationDate datetime      null,
    modifyBy     varchar(50)   null,
    modifyDate   datetime      null
);

create table smbms.smbms_user
(
    id           int default 0 not null
        primary key,
    userCode     varchar(50)   null,
    userName     varchar(50)   null,
    userPassword varchar(50)   null,
    gender       int    null,
    birthday     datetime      null,
    phone        varchar(30)   null,
    address      varchar(40)   null,
    userRole     int 		   null,
    createdBy    int		   null,
    creationDate datetime      null,
    modifyBy     int 		   null,
    modifyDate   datetime      null
);

2、建一个maven web项目
3、配置tomcat
3、测试项目能否正常启动
4、导入项目用到的依赖包(servlet、mysql、)
5、编写实体类(项目结构搭建好):ORM映射:表-类映射

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Bill {
    private int id;
    private String billCode;
    private String productname;
    private String productDesc;
    private String productUnit;
    private int productCount;
    private double totalPrice;
    private String isPayment;
    private String createBy;
    private Date creationDate;
    private String modifyBy;
    private Date modifyDate;
    private Providerprovideid;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Provider {
    private int id;
    private String proCode;
    private String proName;
    private String proDesc;
    private String proContact;
    private String phone;
    private String adress;
    private String proFax;
    private String createBy;
    private Date creationDate;
    private String modifyBy;
    private Date modifydate;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Role {
    private int id;
    private String roleCode;
    private String roleName;
    private String createdBy;
    private Date creationDate;
    private String modifyBy;
    private Date modifyDate;
}

@Data
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {
   private int id;

    private String userCode;

    private String userName;

    private String userPassword;

    private int gender;

    private Date birthday;

    private String phone;

    private String address;

    private int userRole;

    private int createdBy;

    private Date creationDate;

    private int modifyBy;

    private Date modifyDate;
}

6、配置db.properties文件

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

7、编写数据库的公共类

public class BaseDao {

    private static String driver;
    private static String url;
    private static String username;
    private static String password;

//    静态代码块,类加载的时候就初始化
    static{
//        通过类加载器读取对应的资源
    InputStream asStream = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
    Properties properties = new Properties();
    try {
        properties.load(asStream);
    } 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 conn = null;
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url,username,password);
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
//      编写查询公共类
    public static ResultSet execute(Connection conn,String sql,Object[]params,ResultSet resultSet,PreparedStatement preparedStatement){
        try {
            preparedStatement = conn.prepareStatement(sql);
            for (int i = 0; i < params.length; i++) {
                preparedStatement.setObject(i+1,params[i]);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        try {
            resultSet = preparedStatement.executeQuery(sql);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return resultSet;
    }
//    编写增删改公共方法
public static int execute(Connection conn,String sql,Object[]params,PreparedStatement preparedStatement){
    try {
        preparedStatement = conn.prepareStatement(sql);
        for (int i = 0; i < params.length; i++) {
            preparedStatement.setObject(i+1,params[i]);
        }
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    int updateRows = 0;
    try {
        updateRows = preparedStatement.executeUpdate(sql);
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }
    return updateRows;
}
//释放资源
    public static boolean releaseResource(Connection conn,PreparedStatement preparedStatement,ResultSet resultSet){
        Boolean flag = true;
        if (resultSet!=null){
            try {
                resultSet.close();
//                GC回收
                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 (conn!=null){
            try {
                conn.close();
                conn=null;
            } catch (SQLException throwables) {
                throwables.printStackTrace();
                flag = false;
            }
        }
        return flag;
    }

}
  • 编写字符编码过滤器
 public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        filterChain.doFilter(request,response);

    }
  <!--    字符编码过滤器-->
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>atu.wanaei.filter.CharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

8、导入静态资源
导入路径上传到了gitee上
在这里插入图片描述
准备工作到此完成,之后开始实现登录功能,有兴趣的去代码中看

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不想当个程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值