引言:商城订单管理系统属于小型的Java web系统,由java web+mysql+servlet实现,采用mvc的设计模式,jdbc编程,具备增删改查以及模糊查询,用户登陆注册的功能,版本为eclipse版,如果需要别的版本如idea版,系统架构采用ssm或者springboot的类似Java 或Java web 小型软件系统,或者定制的,需要本系统源码的,
关注一下,送IT视频资料,并送Java web源码一份,希望能帮到你;
1、数据库表图:
2、登陆界面
3、系统主界面
4、更改界面
5、系统架构图
6、重要代码(接口)
public interface GoodsMapper {
List<Goods> selectAll();
int delete(int gId);
boolean insert(Goods record);
boolean update(Goods record,int gId);
List<Goods> findByGno(int gId);
Goods findByGId(int gId);
}
7、实现类
package com.service;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.mapper.GoodsMapper;
import com.model.Goods;
import com.utils.DBUtils;
//#f91570
public class GoodsService implements GoodsMapper {
Connection con=null;
@Override
public List<Goods> selectAll() {
List<Goods> list=new ArrayList<Goods>();//定义list集合
try {
con=DBUtils.getConnection();//获取连接
String sql="select * from Goods";//
PreparedStatement pst=con.prepareStatement(sql);//执行sql
ResultSet rs=pst.executeQuery();//获取查询结果集
while(rs.next()){//ֹ
Goods record=new Goods();//实例化对象
record.setgId(rs.getInt("gId"));
record.setGoodsName(rs.getString("goodsName"));
record.setGoodsCount(rs.getInt("goodsCount"));
record.setGoodsPrice(rs.getDouble("goodsPrice"));
record.setCreateTime(rs.getDate("createTime"));
list.add(record);//丢到list集合里
}
} catch (Exception e) {
e.printStackTrace();
} finally{
DBUtils.closeConnection(con);//关闭连接
}
return list;//返回list集合
}
@Override
public int delete(int gId) {
try {
con=DBUtils.getConnection();
String sql="delete from goods where gId=?";
PreparedStatement pst=con.prepareStatement(sql);
pst.setInt(1,gId);
pst.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
return 0;
} finally{
DBUtils.closeConnection(con);
}
return 1;
}
@Override
public boolean insert(Goods record) {
String sql="insert into goods(gId,goodsName,goodsPrice,goodsCount,createTime) values(?,?,?,?,?)";
try {
con=DBUtils.getConnection();
PreparedStatement pst=con.prepareStatement(sql);
pst=con.prepareStatement(sql);
pst.setInt(1, record.getgId());
pst.setString(2, record.getGoodsName());
pst.setDouble(3, record.getGoodsPrice());
pst.setInt(4,record.getGoodsCount());
pst.setDate(5, record.getCreateTime());
pst.execute();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally{
DBUtils.closeConnection(con);
}
}
@Override
public boolean update(Goods record, int gId) {
try{
con=DBUtils.getConnection();
String sql="update Goods set goodsName=?,goodsPrice=?,goodsCount=?,createTime=? where gId=?";
PreparedStatement pst=con.prepareStatement(sql);
pst.setString(1,record.getGoodsName());
pst.setDouble(2,record.getGoodsPrice());
pst.setInt(3,record.getGoodsCount());
pst.setDate(4, record.getCreateTime());
pst.setInt(5,gId);
pst.execute();
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}finally{
DBUtils.closeConnection(con);
}
}
@Override
public List<Goods> findByGno(int gId) {
Connection con=null;
List<Goods> list =new ArrayList<Goods>();
try{
con=DBUtils.getConnection();
String sql="select * from Goods where gId like ?";
PreparedStatement pst=con.prepareStatement(sql);
pst.setString(1, "%"+gId+"%");
ResultSet rs=pst.executeQuery();
while(rs.next()) {
Goods record =new Goods();
record.setgId(rs.getInt("gId"));
record.setGoodsName(rs.getString("goodsName"));
record.setGoodsCount(rs.getInt("goodsCount"));
record.setGoodsPrice(rs.getDouble("goodsPrice"));
record.setCreateTime(rs.getDate("createTime"));
list.add(record);
}
return list;
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
DBUtils.closeConnection(con);
}
}
@Override
public Goods findByGId(int gId) {
try{
con=DBUtils.getConnection();
String sql="select * from Goods where gId=?";
PreparedStatement pst=con.prepareStatement(sql);
pst.setInt(1,gId);
ResultSet rs=pst.executeQuery();
if(rs.next()){
Goods record=new Goods();
record.setgId(rs.getInt("gId"));
record.setGoodsName(rs.getString("goodsName"));
record.setGoodsCount(rs.getInt("goodsCount"));
record.setGoodsPrice(rs.getDouble("goodsPrice"));
record.setCreateTime(rs.getDate("createTime"));
return record;
}else{
return null;
}
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
DBUtils.closeConnection(con);
}
}
public static void main(String[] args) {
GoodsService s=new GoodsService();
/*List<Student> list=s.selectAll();
for(Student st:list) {
System.out.println(st.getsAddress());
}*/
Goods stu=new Goods();
//stu.setsNo(sNo);
/*stu.setsName("");
stu.setsAge(21);
stu.setsAddress("");
stu.setSchool("海院");
boolean b=s.update(stu, 1211);*/
//System.out.println(b);
List<Goods> list=s.selectAll();
for(Goods st:list) {
System.out.println(st.getGoodsName());
}
}
}
8、总结
代码比较多,我只选择了重要的代码,希望帮到大家。有问题的可以加我qq1728608455,欢迎咨询。