文章目录
- 一、项目介绍
- 二、项目技术栈
- 三、核心代码
- 四、项目展示
- 五、源码获取
一、项目介绍
在当今互联网高速发展的时代,大学校园内的学生生活正在发生着翻天覆地的变化。其中,校园内的餐饮服务无疑是亟需改革和创新的领域之一。
传统的校园食堂模式,往往存在就餐高峰时段拥挤、菜品选择单一、订餐流程繁琐等诸多问题,严重影响了学生的就餐体验。为了解决这一痛点,迫切需要开发一套功能全面、操作简便的校园订餐系统。
二、项目技术栈
- 后端:javaweb+jdk+tomcat
- 前端:jsp+css+js
- 数据库:mysql
三、核心代码
验证码生产类
public class CheckCode {
public String getCheckCode(){
Random random = new Random();
String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
}
return sRand;
}
}
管理员登录
public int adminLogin(String username,String md5password,String password,String useros,String loginip){
String sql = "select * from admin where username = '"+username+"' and isuse='1'";
String sql2 = "insert into adminlog(username,password,logintime,loginip,useros,ok) values('"+username+"','"+md5password+"','"+date+"','"+loginip+"','"+useros+"','true')";
String sql3 = "insert into adminlog(username,password,logintime,loginip,useros,ok) values('"+username+"','"+password+"','"+date+"','"+loginip+"','"+useros+"','false')";
String sql4 = "update admin set logintimes = logintimes+1 where username = '"+username+"' ";
DBO dbo = new DBO();
String pwd;
dbo.open();
try{
rs = dbo.executeQuery(sql);
if(rs.next()){
pwd = rs.getString("password");
if(pwd.trim().equals(md5password)){
dbo.executeUpdate(sql2);
dbo.executeUpdate(sql4);
return Constant.SUCCESS;
}
else{
dbo.executeUpdate(sql3);
return Constant.PASSWORD_ERROR;
}
}
else{
dbo.executeUpdate(sql3);
return Constant.NAME_ERROR;
}
}catch(Exception e){
e.printStackTrace();
return Constant.SYSTEM_ERROR;
}finally{
dbo.close();
}
}
查询管理员信息
public List getAdminInfo(String username){
String sql = "select * from admin where username='"+username+"' ";
DBO dbo = new DBO();
dbo.open();
list = new ArrayList();
try{
rs = dbo.executeQuery(sql);
rs.next();
list.add(rs.getString("username"));
list.add(rs.getInt("flag"));
list.add(rs.getInt("logintimes"));
list.add(date);
list.add(rs.getString("quanxian"));
return list;
}catch(Exception e){
e.printStackTrace();
return list;
}finally{
dbo.close();
}
}
查询信息
//分页查询所有个人会员
public void setEVERYPAGENUM(int EVERYPAGENUM){
this.EVERYPAGENUM=EVERYPAGENUM;
}
public int getMessageCount() { //得到信息总数
DBO dbo=new DBO();
dbo.open();
try {
rs = dbo.executeQuery(sql);
rs.next();
count = rs.getInt(1);
return count;
} catch (SQLException ex) {
ex.printStackTrace();
return -1;
} finally {
dbo.close();
}
}
public int getPageCount() { //得到共多少页(根据每页要显示几条信息)
if (count % EVERYPAGENUM == 0) {
return count / EVERYPAGENUM;
} else {
return count / EVERYPAGENUM + 1;
}
}
public List getMessage(int page) { //得到每页要显示的信息
DBO dbo=new DBO();
dbo.open();
List list = new ArrayList();
try {
rs = dbo.executeQuery(sql2);
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
qq++;
List list2=new ArrayList();
list2.add(rs.getInt("id"));
list2.add(rs.getString("username"));
list2.add(rs.getString("regtime"));
list2.add(rs.getString("ifuse"));
list2.add(rs.getString("logintimes"));
list2.add(rs.getString("lasttime"));
list2.add(rs.getString("lastip"));
list.add(list2);
} else {
break; //减少空循环的时间
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return null;
} finally {
dbo.close();
}
}
企业会员
///所有企业会员
public int getMessageCountCO() { //得到信息总数
DBO dbo=new DBO();
dbo.open();
try {
rs = dbo.executeQuery("select count(*) from member where type='co'");
rs.next();
count = rs.getInt(1);
return count;
} catch (SQLException ex) {
ex.printStackTrace();
return -1;
} finally {
dbo.close();
}
}
public List getMessageCO(int page) { //得到每页要显示的信息
DBO dbo=new DBO();
dbo.open();
List list = new ArrayList();
try {
rs = dbo.executeQuery("select * from member where type='co' order by id desc ");
for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {
rs.next();
}
for (int t = 0; t < EVERYPAGENUM; t++) {
if (rs.next()) {
qq++;
List list2=new ArrayList();
list2.add(rs.getInt("id"));
list2.add(rs.getString("username"));
list2.add(rs.getString("regtime"));
list2.add(rs.getString("ifuse"));
list2.add(rs.getString("logintimes"));
list2.add(rs.getString("lasttime"));
list2.add(rs.getString("lastip"));
list.add(list2);
} else {
break; //减少空循环的时间
}
}
return list;
} catch (SQLException ex) {
ex.printStackTrace();
return null;
} finally {
dbo.close();
}
}
数据库连接类
public class DBO {
private Connection conn;
private Statement stmt;
private DataSource ds;
public DBO()
{
}
/**
打开数据库
*/
public void open()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/wsdc?useUnicode=true&characterEncoding=gb2312","root","root");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=xwfb","sa","123");
stmt=conn.createStatement();
System.out.println("打开数据库连接");
}
catch (Exception ex)
{
System.err.println("打开数据库时出错: " + ex.getMessage());
}
}
/**
关闭数据库,将连接返还给连接池
*/
public void close()
{
try
{
// connMgr.freeConnection("java", conn);
conn.close();
System.out.println ("释放连接");
}
catch (SQLException ex)
{
System.err.println("返还连接池出错: " + ex.getMessage());
}
}
/**
执行查询
*/
public ResultSet executeQuery(String sql) throws SQLException
{
ResultSet rs = null;
rs = stmt.executeQuery(sql);
System.out.println ("执行查询");
return rs;
}
/**
执行增删改
*/
public int executeUpdate(String sql) throws SQLException
{
int ret = 0;
ret = stmt.executeUpdate(sql);
System.out.println ("执行增删改");
return ret;
}
/**
将SQL语句加入到批处理
*/
public void addBatch(String sql) throws SQLException
{
stmt.addBatch(sql);
}
/**
执行批处理
*/
public int [] executeBatch() throws SQLException
{
boolean isAuto=conn.getAutoCommit();
conn.setAutoCommit(false);
int [] updateCounts = stmt.executeBatch();
// conn.commit();
// conn.setAutoCommit(isAuto);
//conn.setAutoCommit(true);
return updateCounts;
}
public boolean getAutoCommit() throws SQLException
{
return conn.getAutoCommit();
}
public void setAutoCommit(boolean auto) throws SQLException
{
conn.setAutoCommit(auto);
}
public void commit() throws SQLException
{
conn.commit();
// this.close();
}
public void rollBack() throws SQLException
{
conn.rollback();
// this.close();
}
}
四、项目展示
登录页面
项目主页
留言管理
后台管理
五、源码获取
因为页面与源码太多了,所以页面与源码只展示了一部分,完整源码已经打包了,点击下面蓝色链接获取!
点我获取源码