一、 開發(fā)背景
軟件名稱:超市管理系統(tǒng)(servlet+jsp)
使用對(duì)象:學(xué)習(xí)或了解過 java 基礎(chǔ)課程,開始接觸 javaWeb 的學(xué)生和軟件愛好者
源碼鏈接:超市管理系統(tǒng): 超市管理系統(tǒng)
Sql文件https://pan.baidu.com/s/1BtMM8erQ9E25fQ1j4eHltQ?pwd=8nmj
二、 需求分析
該超市管理系統(tǒng),設(shè)置了登錄權(quán)限驗(yàn)證,所有用戶除了訪問首頁瀏覽商品外,均需輸入賬號(hào)、密碼登錄進(jìn)入系統(tǒng);
三、開發(fā)環(huán)境
- 系統(tǒng)環(huán)境:Windows10
- 開發(fā)工具:IDEA
- Java版本:JDK 11
- 服務(wù)器:tomcat 9.0
- 數(shù)據(jù)庫:MySQL 8.0.15
- 系統(tǒng)采用技術(shù):Servlet+Jsp+Jdbc+jQuery+Ajax+面向接口編程
四、運(yùn)行效果
五、開發(fā)流程
新建工程目錄結(jié)構(gòu)
- ?BillDaodao層
package com.chen.dao.Bill;/*
*
操作數(shù)據(jù)庫的
*/
import com.chen.pojo.Bill;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
public interface BillDao {
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單總數(shù)
public abstract int getBillCount(Connection conn,String queryProductName,int queryProviderId,int queryIsPayment)throws SQLException;
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單列表
public abstract List<Bill> getBillList(Connection conn,String queryProductName,int queryProviderId,int queryIsPayment, int currentPageNo, int pageSize) throws SQLException;
//添加訂單
public abstract boolean addBill(Connection conn,Bill bill)throws SQLException;
//刪除訂單
public abstract boolean deleteBill(Connection conn,int billId)throws SQLException;
//根據(jù)訂單id 獲取訂單信息
public abstract Bill findByBillId(Connection conn,int billId)throws SQLException;
//修改訂單信息
public abstract boolean modifyBill(Connection conn,int billId,Bill bill)throws SQLException;
}
- dao層BillDaoImpl?
package com.chen.dao.Bill;/*
*/
import com.chen.dao.BaseDao;
import com.chen.pojo.Bill;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class BillDaoImpl implements BillDao{
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單總數(shù)
@Override
public int getBillCount(Connection conn, String queryProductName, int queryProviderId, int queryIsPayment) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
int count = 0;
if(conn != null){
StringBuffer sql = new StringBuffer();
sql.append("select count(1) as count from smbms_bill b,smbms_provider p where b.providerId = p.id");
List<Object> paramsList = new ArrayList<>();
if(queryProductName != "") {
sql.append(" and productName like ?");
paramsList.add("%"+queryProductName+"%");
}
if(queryProviderId != 0){
sql.append(" and providerId = ?");
paramsList.add(queryProviderId);
}
if(queryIsPayment != 0){
sql.append(" and isPayment = ?");
paramsList.add(queryIsPayment);
}
Object[] params = paramsList.toArray();
rs = BaseDao.executeQuery(conn, sql.toString(), pstm, params, rs);
//遍歷結(jié)果集 從結(jié)果集中取出數(shù)量count
if (rs.next()){
count = rs.getInt("count");
}
//關(guān)閉資源
BaseDao.closeResource(null,pstm,rs);
}
return count;
}
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單列表
@Override
public List<Bill> getBillList(Connection conn, String queryProductName, int queryProviderId, int queryIsPayment, int currentPageNo, int pageSize) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
List<Bill> bills = new ArrayList<>();
if(conn != null){
System.out.println("enter BillDaoImpl...");
//動(dòng)態(tài)拼接字符串
StringBuffer sql = new StringBuffer();
//參數(shù)列表
ArrayList<Object> paramsList = new ArrayList<>();
sql.append("select b.*,p.proName as proName from smbms_bill b,smbms_provider p where b.providerId = p.id");
if(queryProductName != "" && queryProviderId != 0 && queryIsPayment != 0){
//說明三個(gè)參數(shù)都不為空
sql.append(" and productName like ? and providerId = ? and isPayment = ?");
paramsList.add("%"+queryProductName+"%");
try {
paramsList.add(queryProviderId);
paramsList.add(queryIsPayment);
}catch (Exception e){
e.printStackTrace();
}
}else if(queryProductName != "" || queryProviderId != 0 || queryIsPayment != 0){
//說明三個(gè)參數(shù)有些不為空
if(queryProductName != ""){
sql.append(" and productName like ?");
paramsList.add("%"+queryProductName+"%");
}
if(queryProviderId != 0){
sql.append(" and providerId = ?");
paramsList.add(queryProviderId);
}
if(queryIsPayment != 0){
sql.append(" and isPayment = ?");
paramsList.add(queryIsPayment);
}
}
//在數(shù)據(jù)庫中 分頁使用limit startIndex,pageSize 總數(shù)
//當(dāng)前頁 = (當(dāng)前頁-1)*頁面大小
sql.append(" order by b.creationDate DESC limit ?,?");
currentPageNo = (currentPageNo-1)*pageSize;
paramsList.add(currentPageNo);
paramsList.add(pageSize);
//sql拼接完成 參數(shù)列表也正確
System.out.println("Test SQL --> "+sql.toString());
//將參數(shù)列表進(jìn)行轉(zhuǎn)換
Object[] params = paramsList.toArray();
//執(zhí)行sql
rs = BaseDao.executeQuery(conn, sql.toString(), pstm, params, rs);
//遍歷結(jié)果集 封裝對(duì)象 添加到列表
while (rs.next()){
Bill bill = new Bill();
bill.setId(rs.getInt("id"));
bill.setBillCode(rs.getString("billCode"));
bill.setProductName(rs.getString("productName"));
bill.setProductDesc(rs.getString("productDesc"));
bill.setProductUnit(rs.getString("productUnit"));
bill.setProductCount(rs.getBigDecimal("productCount"));
bill.setTotalPrice(rs.getBigDecimal("totalPrice"));
bill.setIsPayment(rs.getInt("isPayment"));
bill.setCreatedBy(rs.getInt("createdBy"));
bill.setCreationDate(rs.getTimestamp("creationDate"));
bill.setModifyBy(rs.getInt("modifyBy"));
bill.setModifyDate(rs.getTimestamp("modifyDate"));
bill.setProviderId(rs.getInt("providerId"));
bill.setProviderName(rs.getString("proName"));
bills.add(bill);
}
//關(guān)閉資源
BaseDao.closeResource(null,pstm,rs);
}
//返回列表
return bills;
}
//添加訂單
@Override
public boolean addBill(Connection conn, Bill bill) throws SQLException {
PreparedStatement pstm = null;
boolean flag = false;
if (conn != null){
String sql = "insert into smbms_bill (billCode,productName,productDesc,productUnit,productCount,totalPrice,isPayment,createdBy,creationDate,modifyBy,modifyDate,providerId)values(?,?,?,?,?,?,?,?,?,?,?,?)" ;
Object[] params = {bill.getBillCode(),bill.getProductName(),bill.getProductDesc(),bill.getProductUnit(),bill.getProductCount(),bill.getTotalPrice(),bill.getIsPayment(),bill.getCreatedBy(),bill.getCreationDate(),bill.getModifyBy(),bill.getModifyDate(),bill.getProviderId()};
int updateRows = BaseDao.execute(conn, sql, pstm, params);
if(updateRows > 0){
flag = true;
}
BaseDao.closeResource(null,pstm,null);
}
return flag;
}
//刪除訂單
@Override
public boolean deleteBill(Connection conn, int billId) throws SQLException {
PreparedStatement pstm = null;
boolean flag = false;
if(conn != null){
String sql = "delete from smbms_bill where id = ?";
Object[] params = {billId};
int updateRows = BaseDao.execute(conn, sql, pstm, params);
if(updateRows > 0){
flag = true;
}
BaseDao.closeResource(null,pstm,null);
}
return flag;
}
//根據(jù)訂單id 獲取訂單信息
@Override
public Bill findByBillId(Connection conn, int billId) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
Bill bill = new Bill();
if(conn != null){
String sql = "select b.*,p.proName as providerName from smbms_bill b,smbms_provider p where b.id = ? and b.providerId = p.id";
Object[] params = {billId};
rs = BaseDao.executeQuery(conn, sql, pstm, params, rs);
//遍歷此結(jié)果集 并存入bill對(duì)象
if(rs.next()){
bill.setBillCode(rs.getString("billCode"));
bill.setProductName(rs.getString("productName"));
bill.setProductDesc(rs.getString("productDesc"));
bill.setProductUnit(rs.getString("productUnit"));
bill.setProductCount(rs.getBigDecimal("productCount"));
bill.setTotalPrice(rs.getBigDecimal("totalPrice"));
bill.setIsPayment(rs.getInt("isPayment"));
bill.setCreatedBy(rs.getInt("createdBy"));
bill.setCreationDate(rs.getTimestamp("creationDate"));
bill.setModifyBy(rs.getInt("modifyBy"));
bill.setModifyDate(rs.getTimestamp("modifyDate"));
bill.setProviderId(rs.getInt("providerId"));
bill.setProviderName(rs.getString("providerName"));
}
BaseDao.closeResource(null,pstm,rs);
}
return bill;
}
//修改訂單信息
@Override
public boolean modifyBill(Connection conn, int billId, Bill bill) throws SQLException {
PreparedStatement pstm = null;
boolean flag = false;
if(conn != null){
String sql = "update smbms_bill set billCode = ?,productName =?,productDesc = ?,productUnit = ?,productCount = ? ,totalPrice = ?,isPayment = ?,createdBy = ?,creationDate = ?,modifyBy = ?,modifyDate = ?,providerId = ? where id = ?";
Object[] params = {bill.getBillCode(),bill.getProductName(),bill.getProductDesc(),bill.getProductUnit(),bill.getProductCount(),bill.getTotalPrice(),bill.getIsPayment(),bill.getCreatedBy(),bill.getCreationDate(),bill.getModifyBy(),bill.getModifyDate(),bill.getProviderId(),billId};
int updateRows = BaseDao.execute(conn, sql, pstm, params);
if (updateRows > 0) {
flag = true;
}
BaseDao.closeResource(null,pstm,null);
}
return flag;
}
}
- dao.Provider.ProviderDao?
package com.chen.dao.Provider;/*
*/
import com.chen.pojo.Provider;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
public interface ProviderDao {
//根據(jù)供應(yīng)商編碼 或 供應(yīng)商名稱 查詢供應(yīng)商總數(shù)
public abstract int getProviderCounts(Connection conn,String queryProCode,String queryProName)throws SQLException;
//查詢供應(yīng)商數(shù)據(jù)列表
public abstract List<Provider> getProviderList(Connection conn,String ProCode,String ProName,int currentPageNo, int pageSize)throws SQLException;
//添加供應(yīng)商的方法
public abstract boolean addProvider(Connection conn,Provider provider)throws SQLException;
//刪除供應(yīng)商的方法
public abstract boolean deleteProvider(Connection conn,int providerId)throws SQLException;
//根據(jù)供應(yīng)商id查詢供應(yīng)商信息的方法
public abstract Provider findById(Connection conn,int providerId)throws SQLException;
//修改供應(yīng)商信息方法
public abstract boolean modifyProvider(Connection conn,int id,Provider provider)throws SQLException;
}
-
com.chen.dao.Role.RoleDao
package com.chen.dao.Role;/* */ import com.chen.pojo.Role; import java.sql.Connection; import java.sql.SQLException; import java.util.List; public interface RoleDao { //獲取角色列表 public abstract List<Role> getRoleList(Connection conn)throws SQLException; }
com.chen.dao.Role.RoleDaoImpl
package com.chen.dao.Role;/*
*/
import com.chen.dao.BaseDao;
import com.chen.pojo.Role;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class RoleDaoImpl implements RoleDao {
//獲取角色列表
@Override
public List<Role> getRoleList(Connection conn) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
ArrayList<Role> roles = new ArrayList<>();
if(conn != null){
String sql = "select * from smbms_role";
Object[] params = {};
rs = BaseDao.executeQuery(conn, sql, pstm, params, rs);
while(rs.next()){
Role role = new Role();
role.setId(rs.getInt("id"));
role.setRoleName(rs.getString("roleName"));
role.setRoleCode(rs.getString("roleCode"));
roles.add(role);
}
}
BaseDao.closeResource(null,pstm,rs);
return roles;
}
}
?com.chen.dao.User.UserDao
package com.chen.dao.User;/*
*/
import com.chen.pojo.User;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
//登錄 判斷 的接口
public interface UserDao {
//得到要登錄的用戶信息
public abstract User getLoginInfo(Connection conn,String userCode) throws SQLException;
//修改密碼
public abstract int updatePassword(Connection conn,int id,String newPsd)throws SQLException;
//根據(jù)用戶名 或 角色 查詢用戶總數(shù)
public abstract int getUserCounts(Connection conn,String username,int userRole)throws SQLException;
//根據(jù)條件 查詢 獲取用戶列表 userList
public abstract List<User> getUserList(Connection conn,String username,int userRole,int currentPageNo,int pageSize)throws SQLException;
//用戶管理模塊中的 子模塊—— 添加用戶
public abstract int addUser(Connection conn,User user)throws SQLException;
//用戶管理模塊中的子模塊 —— 刪除用戶
public abstract boolean deleteUser(Connection conn,int userId)throws SQLException;
//根據(jù)用戶id 查詢用戶信息
public abstract User findById(Connection conn,int userId)throws SQLException;
//用戶管理模塊中的子模塊 —— 更改用戶信息
public abstract boolean modify(Connection conn,int id,User user)throws SQLException;
}
com.chen.dao.User.UserDaoImpl
package com.chen.dao.User;/*
*/
import com.chen.dao.BaseDao;
import com.chen.pojo.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
//登錄 判斷 的實(shí)現(xiàn)類
public class UserDaoImpl implements UserDao {
@Override
//得到要登錄的用戶信息
public User getLoginInfo(Connection conn, String userCode) throws SQLException {
PreparedStatement preparedStatement = null;
ResultSet rs = null;
User user = null;
//如果連數(shù)據(jù)庫都沒連接就無需判斷了
if(conn!=null){
//編寫sql語句預(yù)編譯sql
String sql = "select * from smbms_user where userCode = ?";
//存放參數(shù)
Object[] params = {userCode};
//使用預(yù)處理對(duì)象調(diào)用 操作數(shù)據(jù)庫的公共類 的執(zhí)行 sql查詢語句
rs = BaseDao.executeQuery(conn, sql, preparedStatement, params,rs);
//遍歷結(jié)果集 封裝到一個(gè)用戶中
if(rs.next()){
user = new User();
user.setId(rs.getInt("id"));
user.setUserCode(rs.getString("userCode"));
user.setUserName(rs.getString("userName"));
user.setUserPassword(rs.getString("userPassword"));
user.setGender(rs.getInt("gender"));
user.setBirthday(rs.getDate("birthday"));
user.setPhone(rs.getString("phone"));
user.setAddress(rs.getString("address"));
user.setUserRole(rs.getInt("userRole"));
user.setCreatedBy(rs.getInt("createdBy"));
user.setCreateDate(rs.getTimestamp("creationDate"));
user.setModifyBy(rs.getInt("modifyBy"));
user.setModifyDate(rs.getTimestamp("modifyDate"));
}
//調(diào)用 操作數(shù)據(jù)庫的公共類 的執(zhí)行 釋放資源
BaseDao.closeResource(null,preparedStatement,rs);
}
//返回一個(gè)用戶
return user;
}
//修改當(dāng)前用戶密碼
@Override
public int updatePassword(Connection conn, int id, String newPsd) throws SQLException {
PreparedStatement pstm = null;
int result = 0;
if (conn != null) {
String sql = "update smbms_user set userPassword = ? where id = ?";
Object params[] = {newPsd,id};
result = BaseDao.execute(conn, sql, pstm, params);
BaseDao.closeResource(null,pstm,null);
}
return result;
}
//根據(jù)用戶名 或 角色 查詢用戶總數(shù)
@Override
public int getUserCounts(Connection conn, String username, int userRole) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
int count = 0;
if(conn!=null){
//SQL語句因?yàn)槁?lián)合多表查詢 所以需要拼接
StringBuffer sql = new StringBuffer();
//默認(rèn)兩表聯(lián)合 查詢總條數(shù)
sql.append("select count(1) as count from smbms_user u,smbms_role r where u.userRole = r.id");
//建一個(gè)集合來存儲(chǔ)參數(shù)
ArrayList<Object> list = new ArrayList<>();
if(username!=null){
sql.append(" and u.userName like ?");
list.add("%"+username+"%");//默認(rèn)下標(biāo)為0
}
if(userRole>0 & userRole<4){
sql.append(" and u.userRole = ?");
list.add(userRole);//默認(rèn)下標(biāo)為1
}
//把list轉(zhuǎn)換為數(shù)組
Object[] arrays = list.toArray();
System.out.println("拼接的sql語句:"+sql.toString());
//執(zhí)行sql語句
rs = BaseDao.executeQuery(conn, sql.toString(), pstm, arrays, rs);
//遍歷結(jié)果集
if(rs.next()){
//從結(jié)果集中獲取數(shù)量
count = rs.getInt("count");
}
//最終關(guān)閉資源連接
BaseDao.closeResource(null,pstm,rs);
}
return count;
}
//根據(jù)條件 查詢 獲取用戶列表 userlist
@Override
public List<User> getUserList(Connection conn, String username, int userRole, int currentPageNo, int pageSize) throws SQLException {
PreparedStatement pstm = null;
ResultSet rs = null;
List<User> userList = new ArrayList<User>();
if(conn!=null){
//SQL語句因?yàn)槁?lián)合多表查詢 所以需要拼接
StringBuffer sql = new StringBuffer();
//默認(rèn)兩表聯(lián)合 查詢總條數(shù)
sql.append("select u.*,r.roleName as userRoleName from smbms_user u,smbms_role r where u.userRole = r.id");
//建一個(gè)集合來存儲(chǔ)參數(shù)
List<Object> list = new ArrayList<>();
if(username!=null){
sql.append(" and u.userName like ?");
list.add("%"+username+"%");//默認(rèn)下標(biāo)為0
}
if(userRole>0 & userRole<4){
sql.append(" and u.userRole = ?");
list.add(userRole);//默認(rèn)下標(biāo)為1
}
//在數(shù)據(jù)庫中 分頁使用limit startIndex,pageSize 總數(shù)
//當(dāng)前頁 = (當(dāng)前頁-1)*頁面大小
sql.append(" order by u.creationDate DESC limit ?,?");
currentPageNo = (currentPageNo-1)*pageSize;
list.add(currentPageNo);
list.add(pageSize);
Object[] params = list.toArray();
System.out.println("getUserList的語句"+sql.toString());
//執(zhí)行sql
rs = BaseDao.executeQuery(conn, sql.toString(), pstm, params, rs);
while (rs.next()){
User user = new User();
user.setId(rs.getInt("id"));
user.setUserCode(rs.getString("userCode"));
user.setUserName(rs.getString("userName"));
user.setGender(rs.getInt("gender"));
user.setBirthday(rs.getDate("birthday"));
user.setPhone(rs.getString("phone"));
user.setUserRoleName(rs.getString("userRoleName"));
user.setUserRole(rs.getInt("userRole"));
userList.add(user);
}
BaseDao.closeResource(null,pstm,rs);
}
return userList;
}
//用戶管理模塊中的 子模塊—— 添加用戶
public int addUser(Connection conn,User user)throws SQLException{
PreparedStatement pstm = null;
int updateRows = 0;
if(conn != null){
String sql = "insert into smbms_user (userCode,userName,userPassword,gender,birthday,phone,address,userRole,createdBy,creationDate)values(?,?,?,?,?,?,?,?,?,?)";
Object[] params ={user.getUserCode(),user.getUserName(),user.getUserPassword(),user.getGender(),user.getBirthday(),user.getPhone(),user.getAddress(),user.getUserRole(),user.getCreatedBy(),user.getCreateDate()};
//執(zhí)行sql 返回執(zhí)行結(jié)果(成功的語句數(shù)量)
updateRows= BaseDao.execute(conn,sql,pstm,params);
//釋放資源
BaseDao.closeResource(null,pstm,null);
}
return updateRows;
}
//用戶管理模塊中的子模塊 —— 刪除用戶
@Override
public boolean deleteUser(Connection conn, int userCode)throws SQLException {
PreparedStatement pstm = null;
boolean flag = false;
if(conn != null){
String sql = "delete from smbms_user where id = ?";
Object[] params = {userCode};
//執(zhí)行sql 返回執(zhí)行結(jié)果(成功的語句數(shù)量)
int updateRows= BaseDao.execute(conn,sql,pstm,params);
if(updateRows>0){
flag = true;
}
//釋放資源
BaseDao.closeResource(null,pstm,null);
}
return flag;
}
//根據(jù)用戶 id查詢用戶信息
@Override
public User findById(Connection conn, int userId) throws SQLException {
User user = null;
PreparedStatement pstm = null;
ResultSet rs = null;
if(conn != null){
String sql = "select u.*,r.roleName as userRoleName from smbms_user u,smbms_role r where u.id = ? and u.userRole = r.id";
Object[] params ={userId};
rs = BaseDao.executeQuery(conn, sql, pstm, params, rs);
if(rs.next()){
user = new User();
user.setId(rs.getInt("id"));
user.setUserCode(rs.getString("userCode"));
user.setUserName(rs.getString("userName"));
user.setUserPassword(rs.getString("userPassword"));
user.setGender(rs.getInt("gender"));
user.setBirthday(rs.getDate("birthday"));
user.setPhone(rs.getString("phone"));
user.setAddress(rs.getString("address"));
user.setUserRole(rs.getInt("userRole"));
user.setCreatedBy(rs.getInt("createdBy"));
user.setCreateDate(rs.getTimestamp("creationDate"));
user.setModifyBy(rs.getInt("modifyBy"));
user.setModifyDate(rs.getTimestamp("modifyDate"));
user.setUserRoleName(rs.getString("userRoleName"));
}
//釋放資源
BaseDao.closeResource(null,pstm,rs);
}
return user;
}
//用戶管理模塊中的子模塊 —— 更改用戶信息
@Override
public boolean modify(Connection conn, int id,User user) throws SQLException {
boolean flag = false;
PreparedStatement pstm = null;
if(conn != null){
//編寫sql語句
String sql = "update smbms_user set userName = ?,gender = ?,birthday =?,phone = ?,address = ?,userRole = ?,modifyBy = ?,modifyDate = ? where id = ?";
Object[] params = {user.getUserName(),user.getGender(),user.getBirthday(),user.getPhone(),user.getAddress(),user.getUserRole(),user.getModifyBy(),user.getModifyDate(),id};
//執(zhí)行sql語句
int updateRows = BaseDao.execute(conn, sql, pstm, params);
if(updateRows>0){
flag = true;
}
//釋放連接
BaseDao.closeResource(null,pstm,null);
}
return flag;
}
}
com.chen.dao.BaseDao
package com.chen.dao;/*
*
操作數(shù)據(jù)庫的公共類
*/
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;
//靜態(tài)代碼塊 類加載的時(shí)候初始化
static {
Properties properties = new Properties();
//通過類加載器讀取對(duì)應(yīng)的資源 反射
InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
//properties讀取文件內(nèi)容
try {
properties.load(is);//加載這個(gè)流
} catch (IOException e) {
e.printStackTrace();
}
driver = properties.getProperty("driver");
url = properties.getProperty("url");
username = properties.getProperty("username");
password = properties.getProperty("password");
}
//獲取數(shù)據(jù)庫的連接
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
//編寫查詢公共方法
public static ResultSet executeQuery(Connection conn,String sql,PreparedStatement preparedStatement,Object[] params,ResultSet resultSet) throws SQLException {
//預(yù)編譯的sql在后面直接執(zhí)行即可
preparedStatement = conn.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
//setObject 占位符從1開始 而數(shù)字從0開始
preparedStatement.setObject(i+1,params[i]);
}
resultSet = preparedStatement.executeQuery();//ResultSet,數(shù)據(jù)庫結(jié)果集的數(shù)據(jù)表,通常通過執(zhí)行查詢數(shù)據(jù)庫的語句生成。g
return resultSet;
}
//編寫增刪改查公共方法
public static int execute(Connection conn,String sql,PreparedStatement preparedStatement,Object[] params) throws SQLException {
//預(yù)編譯的sql在后面直接執(zhí)行即可
int updateRow;
preparedStatement = conn.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
//setObject 占位符從1開始 而數(shù)字從0開始
preparedStatement.setObject(i+1,params[i]);
}
updateRow = preparedStatement.executeUpdate();
return updateRow;
}
//釋放資源
public static boolean closeResource(Connection conn,PreparedStatement preparedStatement,ResultSet resultSet){
boolean flag = true;
if(conn!=null){
try {
conn.close();
//GC回收
conn = 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(resultSet!=null){
try {
resultSet.close();
//GC回收
resultSet = null;
} catch (SQLException e) {
e.printStackTrace();
flag = false;
}
}
return flag;
}
}
com.chen.filter.CharacterEncodingFilter
package com.chen.filter;/*
*
*/
import javax.servlet.*;
import java.io.IOException;
public class CharacterEncodingFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletRequest.setCharacterEncoding("utf-8");
servletResponse.setCharacterEncoding("utf-8");
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void destroy() {
}
}
package com.chen.filter. LoginFilter
package com.chen.filter;/*
*
*/
import com.chen.pojo.User;
import com.chen.util.Constants;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class LoginFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
User user = (User) request.getSession().getAttribute(Constants.USER_SESSION);
//過濾器 從session中獲取用戶 判斷是否登錄
if (user == null) {
//證明未登錄 或 已注銷
response.sendRedirect(request.getContextPath()+"/error.jsp");
}else{
filterChain.doFilter(request,response);
}
}
@Override
public void destroy() {
}
}
com.chen.pojo.Bill
public class Bill {
private Integer id; //id
private String billCode; //賬單編碼
private String productName; //商品名稱
private String productDesc; //商品描述
private String productUnit; //商品單位
private BigDecimal productCount; //商品數(shù)量
private BigDecimal totalPrice; //總金額
private Integer isPayment; //是否支付
private Integer providerId; //供應(yīng)商ID
private Integer createdBy; //創(chuàng)建者
private Date creationDate; //創(chuàng)建時(shí)間
private Integer modifyBy; //更新者
private Date modifyDate;//更新時(shí)間
private String providerName;//供應(yīng)商名稱
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = 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 Integer getProviderId() {
return providerId;
}
public void setProviderId(Integer providerId) {
this.providerId = providerId;
}
public Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
}
com.chen.pojo.Provider
package com.chen.pojo;/*
*
*/
import java.util.Date;
public class Provider {
private Integer id; //id
private String proCode; //供應(yīng)商編碼
private String proName; //供應(yīng)商名稱
private String proDesc; //供應(yīng)商描述
private String proContact; //供應(yīng)商聯(lián)系人
private String proPhone; //供應(yīng)商電話
private String proAddress; //供應(yīng)商地址
private String proFax; //供應(yīng)商傳真
private Integer createdBy; //創(chuàng)建者
private Date creationDate; //創(chuàng)建時(shí)間
private Integer modifyBy; //更新者
private Date modifyDate;//更新時(shí)間
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 Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
}
com.chen.pojo.Role
package com.chen.pojo;
import java.util.Date;
public class Role {
private Integer id; //id
private String roleCode; //角色編碼
private String roleName; //角色名稱
private Integer createdBy; //創(chuàng)建者
private Date creationDate; //創(chuàng)建時(shí)間
private Integer modifyBy; //更新者
private Date modifyDate;//更新時(shí)間
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 Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
}
com.chen.pojo.User
package com.chen.pojo;/*
*/
import java.util.Date;
public class User {
private Integer id;
private String userCode; //用戶編碼
private String userName;
private String userPassword;
private Integer gender;
private Date birthday;
private String phone;
private String address;
private Integer userRole;
private Integer createdBy; //創(chuàng)建者
private Date createDate;
private Integer modifyBy; //更新者
private Date modifyDate; //更新時(shí)間
private Integer age; //年齡
private String userRoleName; //用戶角色名稱
public Integer getAge() {
Date date = new Date();
Integer age = date.getYear()-birthday.getYear();
return age;
}
public void setAge(Integer age) {
this.age = 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 Integer getUserRole() {
return userRole;
}
public void setUserRole(Integer userRole) {
this.userRole = userRole;
}
public Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
}
com.chen.service.Bill. BillService
package com.chen.service.Bill;/*
*
業(yè)務(wù)層
*/
import com.chen.pojo.Bill;
import java.sql.SQLException;
import java.util.List;
public interface BillService {
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單總數(shù)
public abstract int getBillCount(String queryProductName, int queryProviderId, int queryIsPayment) throws SQLException;
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單列表
public abstract List<Bill> getBillList(String queryProductName, int queryProviderId, int queryIsPayment, int currentPageNo, int pageSize) throws SQLException;
//添加訂單
public abstract boolean addBill(Bill bill);
//刪除訂單
public abstract boolean deleteBill(int billId);
//根據(jù)訂單id 獲取訂單信息
public abstract Bill findByBillId(int billId)throws SQLException;
//修改訂單信息
public abstract boolean modifyBill(int billId, Bill bill)throws SQLException;
}
com.chen.service.Bill.BillServiceImpl
package com.chen.service.Bill;/*
*
*/
import com.chen.dao.BaseDao;
import com.chen.dao.Bill.BillDaoImpl;
import com.chen.pojo.Bill;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
public class BillServiceImpl implements BillService {
private BillDaoImpl billDao;
public BillServiceImpl(){
this.billDao = new BillDaoImpl();
}
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單總數(shù)
@Override
public int getBillCount(String queryProductName, int queryProviderId, int queryIsPayment) {
Connection conn = null;
int billCount = 0;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
billCount = billDao.getBillCount(conn, queryProductName, queryProviderId, queryIsPayment);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return billCount;
}
}
//根據(jù) 商品名稱、供應(yīng)商id、是否付款 查詢訂單列表
@Override
public List<Bill> getBillList(String queryProductName, int queryProviderId, int queryIsPayment, int currentPageNo, int pageSize) {
Connection conn = null;
List<Bill> billList = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
System.out.println("enter BillServiceImpl...");
billList = billDao.getBillList(conn, queryProductName, queryProviderId, queryIsPayment,currentPageNo,pageSize);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return billList;
}
}
//添加訂單
@Override
public boolean addBill(Bill bill) {
boolean flag = false;
Connection conn = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
flag = billDao.addBill(conn, bill);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return flag;
}
}
//刪除訂單
@Override
public boolean deleteBill(int billId) {
boolean flag = false;
Connection conn = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
flag = billDao.deleteBill(conn, billId);
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return flag;
}
}
//根據(jù)訂單id 獲取訂單信息
@Override
public Bill findByBillId(int billId){
Connection conn = null;
Bill bill = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
bill = billDao.findByBillId(conn, billId);
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return bill;
}
}
//修改訂單信息
@Override
public boolean modifyBill(int billId, Bill bill) {
boolean flag = false;
Connection conn = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
flag = billDao.modifyBill(conn, billId, bill);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return flag;
}
}
}
com.chen.service.Provider.ProviderService
package com.chen.service.Provider;/*
*/
import com.chen.pojo.Provider;
import java.sql.SQLException;
import java.util.List;
public interface ProviderService {
//根據(jù)供應(yīng)商編碼 或 供應(yīng)商名稱 查詢供應(yīng)商總數(shù)
public abstract int getProviderCounts(String queryProCode,String queryProName)throws SQLException;
//查詢供應(yīng)商數(shù)據(jù)列表
public abstract List<Provider> getProviderList(String ProCode, String ProName, int currentPageNo, int pageSize)throws SQLException;
//添加供應(yīng)商的方法
public abstract boolean addProvider(Provider provider)throws SQLException;
//刪除供應(yīng)商的方法
public abstract boolean deleteProvider(int providerId)throws SQLException;
//根據(jù)供應(yīng)商id查詢供應(yīng)商信息的方法
public abstract Provider findById(int providerId)throws SQLException;
//修改供應(yīng)商信息方法
public abstract boolean modifyProvider(int id,Provider provider)throws SQLException;
}
?com.chen.service.Provider. ProviderServiceImpl
package com.chen.service.Provider;/*
*/
import com.chen.dao.BaseDao;
import com.chen.dao.Provider.ProviderDao;
import com.chen.dao.Provider.ProviderDaoImpl;
import com.chen.pojo.Provider;
import java.sql.Connection;
import java.util.List;
public class ProviderServiceImpl implements ProviderService {
//Service層調(diào)用dao層
private ProviderDao providerDao;
public ProviderServiceImpl(){
providerDao = new ProviderDaoImpl();
}
//根據(jù)供應(yīng)商編碼 或 供應(yīng)商名稱 查詢供應(yīng)商總數(shù)
@Override
public int getProviderCounts(String queryProCode, String queryProName) {
Connection conn = null;
int providerCounts = 0;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
providerCounts = providerDao.getProviderCounts(conn, queryProCode, queryProName);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return providerCounts;
}
}
@Override
public List<Provider> getProviderList(String ProCode, String ProName, int currentPageNo, int pageSize) {
List<Provider> providerList = null;
Connection conn = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
providerList = providerDao.getProviderList(conn, ProCode, ProName, currentPageNo, pageSize);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return providerList;
}
}
//添加供應(yīng)商的方法
@Override
public boolean addProvider(Provider provider) {
Connection conn = null;
boolean flag = false;
try {
//獲取數(shù)據(jù)庫連接
conn = BaseDao.getConnection();
//開啟事務(wù)
conn.setAutoCommit(false);
//執(zhí)行方法
flag = providerDao.addProvider(conn, provider);
//提交事務(wù)
conn.commit();
}catch (Exception e){
e.printStackTrace();
//事務(wù)回滾
conn.rollback();
}finally {
//釋放資源
BaseDao.closeResource(conn,null,null);
return flag;
}
}
//刪除供應(yīng)商的方法
@Override
public boolean deleteProvider(int providerId) {
Connection conn = null;
boolean flag = false;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
flag = providerDao.deleteProvider(conn, providerId);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return flag;
}
}
//根據(jù)供應(yīng)商id查詢供應(yīng)商信息的方法
@Override
public Provider findById(int providerId) {
Connection conn = null;
Provider provider = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
provider = providerDao.findById(conn, providerId);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return provider;
}
}
//修改供應(yīng)商信息方法
@Override
public boolean modifyProvider(int id, Provider provider) {
Connection conn = null;
boolean flag = false;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
flag = providerDao.modifyProvider(conn, id, provider);
conn.commit();
}catch (Exception e){
e.printStackTrace();
conn.rollback();
}finally {
BaseDao.closeResource(conn,null,null);
return flag;
}
}
}
com.chen.service.Role.RoleService
package com.chen.service.Role;/*
*
*@create 2021-05-03-23:33
*/
import com.chen.pojo.Role;
import java.util.List;
public interface RoleService {
//獲取角色列表
public abstract List<Role> getRoleList();
}
com.chen.service.Role.RoleServiceImpl
package com.chen.service.Role;/*
*/
import com.chen.dao.BaseDao;
import com.chen.dao.Role.RoleDao;
import com.chen.dao.Role.RoleDaoImpl;
import com.chen.pojo.Role;
import org.junit.Test;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
public class RoleServiceImpl implements RoleService {
//業(yè)務(wù)層調(diào)用持久層
private RoleDao roleDao = null;
public RoleServiceImpl(){
this.roleDao =new RoleDaoImpl();
}
@Override
public List<Role> getRoleList() {
Connection conn = null;
List<Role> roleList = null;
try {
//獲取數(shù)據(jù)庫連接
conn = BaseDao.getConnection();
roleList = roleDao.getRoleList(conn);
} catch (SQLException e) {
e.printStackTrace();
}finally {
BaseDao.closeResource(conn,null,null);
return roleList;
}
}
@Test
public void testGetRoleList(){
RoleServiceImpl roleService = new RoleServiceImpl();
List<Role> roleList = roleService.getRoleList();
for (Role role : roleList) {
System.out.println(role.getRoleName());
}
}
}
com.chen.service.User.UserService
package com.chen.service.User;/*
*
*/
import com.chen.pojo.User;
import java.util.List;
public interface UserService {
//用戶登錄
public abstract User login(String userCode,String passWord);
//根據(jù)用戶ID修改密碼
public abstract boolean updatePassword(int id,String passWord);
//用戶管理——查詢記錄數(shù)
public abstract int getUserCounts(String username,int userRole);
//根據(jù)條件 查詢用戶列表
public abstract List<User> getUserList(String QueryUserName,int QueryUserRole,int currentPageNo,int pageSize);
//用戶管理模塊中的 子模塊—— 添加用戶
public abstract boolean addUser(User user);
//用戶管理模塊中的子模塊 —— 刪除用戶
public abstract boolean deleteUser(int userId);
//根據(jù)id查詢用戶信息
public abstract User findById(int userId);
//用戶管理模塊中的子模塊 —— 更改用戶信息
public abstract boolean modify(int id,User user);
}
com.chen.service.User.UserserviceImpl
package com.chen.service.User;
import com.chen.dao.BaseDao;
import com.chen.dao.User.UserDao;
import com.chen.dao.User.UserDaoImpl;
import com.chen.pojo.User;
import org.junit.Test;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
//用戶登錄的業(yè)務(wù)層實(shí)現(xiàn)類
public class UserServiceImpl implements UserService {
//業(yè)務(wù)層肯定是調(diào)用dao層的
private UserDao userDao;
public UserServiceImpl(){
userDao =new UserDaoImpl();
}
@Override
//(String userCode, String passWord)兩個(gè)參數(shù)對(duì)應(yīng)是的首頁傳來的值
//用戶登錄
public User login(String userCode, String passWord) {
Connection conn = null;
User user = null;
try {
//調(diào)用 dao層操作數(shù)據(jù)庫的公共類方法 獲取數(shù)據(jù)庫的連接
conn = BaseDao.getConnection();
//得到連接后 開始查詢 通過業(yè)務(wù)層調(diào)用具體的數(shù)據(jù)庫操作
user = userDao.getLoginInfo(conn, userCode);
} catch (SQLException e) {
e.printStackTrace();
}finally {
//關(guān)閉資源
BaseDao.closeResource(conn,null,null);
}
return user;
}
//修改密碼
@Override
public boolean updatePassword(int id, String passWord) {
boolean flag = false;
Connection conn = null;
try {
//獲取連接
conn = BaseDao.getConnection();
//調(diào)用dao層 執(zhí)行更新操作
int i = userDao.updatePassword(conn, id, passWord);
if (i > 0) {
flag = true;
}
}catch (Exception e){
e.printStackTrace();
}finally {
BaseDao.closeResource(conn,null,null);
return flag;
}
}
//用戶管理——查詢記錄數(shù)
@Override
public int getUserCounts(String username, int userRole) {
Connection conn = null;
int userCounts = 0;
try {
//獲取連接
conn = BaseDao.getConnection();
//執(zhí)行sql語句
userCounts = userDao.getUserCounts(conn, username, userRole);
}catch (SQLException e){
e.printStackTrace();
}finally {
BaseDao.closeResource(conn,null,null);
return userCounts;
}
}
//根據(jù)條件 查詢用戶列表
@Override
public List<User> getUserList(String QueryUserName, int QueryUserRole, int currentPageNo, int pageSize) {
Connection conn = null;
List<User> userList = null;
try {
//獲取數(shù)據(jù)庫連接
conn = BaseDao.getConnection();
//調(diào)dao層的到userList
userList = userDao.getUserList(conn, QueryUserName, QueryUserRole, currentPageNo, pageSize);
}catch (SQLException e){
e.printStackTrace();
}finally {
BaseDao.closeResource(conn,null,null);
//返回查詢的用戶
return userList;
}
}
//用戶管理模塊中的 子模塊—— 添加用戶
@Override
public boolean addUser(User user) {
Connection conn = null;
boolean flag = false;
try {
//獲取數(shù)據(jù)庫連接
conn = BaseDao.getConnection();
//開啟JDBC事務(wù)管理
conn.setAutoCommit(false);
//Service層調(diào)用dao層的方法添加用戶
int updateRows = userDao.addUser(conn, user);
conn.commit();
if(updateRows > 0){
flag = true;
}
} catch (SQLException e) {
e.printStackTrace();
conn.rollback();
}finally {
//釋放連接
BaseDao.closeResource(conn,null,null);
return flag;
}
}
//用戶管理模塊中的子模塊 —— 刪除用戶
@Override
public boolean deleteUser(int userId) {
boolean flag = false;
Connection conn = null;
try {
//獲取數(shù)據(jù)庫連接
conn = BaseDao.getConnection();
//開啟事務(wù)
conn.setAutoCommit(false);
flag = userDao.deleteUser(conn, userId);
//提交事務(wù)
conn.commit();
}catch (Exception e){
e.printStackTrace();
//事務(wù)回滾
conn.rollback();
}finally {
//釋放連接
BaseDao.closeResource(conn,null,null);
return flag;
}
}
//根據(jù)id查詢用戶信息
@Override
public User findById(int userId) {
User user = null;
Connection conn = null;
try {
conn = BaseDao.getConnection();
conn.setAutoCommit(false);
user = userDao.findById(conn, userId);
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
try {
conn.rollback();
} catch (SQLException ex) {
ex.printStackTrace();
}
}finally {
BaseDao.closeResource(conn,null,null);
return user;
}
}
//用戶管理模塊中的子模塊 —— 更改用戶信息
@Override
public boolean modify(int id,User user) {
Connection conn = null;
boolean flag = false;
try {
conn = BaseDao.getConnection();
//開啟事務(wù)
conn.setAutoCommit(false);
flag = userDao.modify(conn, id,user);
//提交事務(wù)
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
//事務(wù)回滾
try {
conn.rollback();
} catch (SQLException ex) {
ex.printStackTrace();
}
}finally {
//釋放資源
BaseDao.closeResource(conn,null,null);
return flag;
}
}
@Test
public void Test(){
UserServiceImpl us = new UserServiceImpl();
User admin = us.login("CSNZ", "1");
System.out.println("管理員admin的密碼:"+admin!=null?true:false);
}
@Test
public void TestUserCounts(){
UserServiceImpl us = new UserServiceImpl();
int counts = us.getUserCounts(null, 0);
System.out.println(counts);
}
@Test
public void TestGetUserList(){
UserServiceImpl userService = new UserServiceImpl();
List<User> userList = userService.getUserList("", 1, 1, 5);
for (User user : userList) {
System.out.println(user);
}
}
}
com.chen.servlet.Bill.BillServlet
package com.chen.servlet.Bill;/*
*
*/
import com.alibaba.fastjson.JSONArray;
import com.chen.pojo.Bill;
import com.chen.pojo.Provider;
import com.chen.pojo.User;
import com.chen.service.Bill.BillServiceImpl;
import com.chen.service.Provider.ProviderServiceImpl;
import com.chen.util.Constants;
import com.chen.util.PageSupport;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BillServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method = req.getParameter("method");
if(method.equals("query")){
this.query(req,resp);
}else if(method.equals("getproviderlist")){
this.getproviderlist(req,resp);
}else if(method.equals("add")){
this.add(req,resp);
}else if(method.equals("delbill")){
this.deleteBill(req,resp);
}else if(method.equals("modify")){
this.modify(req,resp);
}else if(method.equals("modifysave")){
this.modifysave(req,resp);
}else if(method.equals("view")){
this.viewBill(req,resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
//查詢訂單管理列表
public void query(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("enter BillList query method...");
//從前端獲取搜素信息
String queryProductName = req.getParameter("queryProductName");
String queryProviderId = req.getParameter("queryProviderId");
String queryIsPayment = req.getParameter("queryIsPayment");
int proId = 0;
int isPayment = 0;
//此屬性在搜素按鈕那
String pageIndex = req.getParameter("pageIndex");
//設(shè)置當(dāng)前頁 以及 每頁顯示的數(shù)目
int currentPageNo = 1;
int pageSize = 5;
/*測(cè)試*/
System.out.println("queryProductName - > "+queryProductName);
System.out.println("queryProviderId - > "+queryProviderId);
System.out.println("queryIsPayment - > "+queryIsPayment);
//對(duì)前端傳來的屬性進(jìn)行判斷 如果為空(沒輸入) 則將值賦空字符串 dao層實(shí)現(xiàn)類判斷的時(shí)候 也得根據(jù)空字符串判斷
if (queryProductName == null){
queryProductName = "";
}
if(queryProviderId != null ){
proId = Integer.parseInt(queryProviderId);
}
if(queryIsPayment != null ){
isPayment = Integer.parseInt(queryIsPayment);
}
if(pageIndex!=null){
currentPageNo = Integer.parseInt(pageIndex);
}
//Servlet層調(diào)用service層
BillServiceImpl billService = new BillServiceImpl();
//獲取訂單總數(shù) 分頁:上一頁 下一頁
int totalCount = billService.getBillCount(queryProductName,proId,isPayment);
//總頁數(shù)支持
PageSupport pageSupport = new PageSupport();
System.out.println("當(dāng)前頁:"+currentPageNo);
pageSupport.setCurrentPageNo(currentPageNo);
pageSupport.setPageSize(pageSize);
System.out.println("獲取訂單總數(shù)"+totalCount);
pageSupport.setTotalCount(totalCount);
//總共的頁數(shù)
int totalPageCount = pageSupport.getTotalPageCount();
//控制首頁和尾頁
//如果頁數(shù)小于1,就顯示第一頁 頁數(shù)大于 最后一頁就 顯示最后一頁
if(currentPageNo<1){
currentPageNo =1;
}else if(currentPageNo>totalPageCount){
currentPageNo = totalPageCount;
}
//根據(jù)前端搜索框信息 查詢訂單列表
List<Bill> billList = billService.getBillList(queryProductName, proId, isPayment,currentPageNo,pageSize);
System.out.println("Test billList -> "+billList);
//將此列表存入req中 供前端展示
req.setAttribute("billList",billList);
//查詢供應(yīng)商列表
ProviderServiceImpl providerService = new ProviderServiceImpl();
int totalNum = providerService.getProviderCounts("","");
List<Provider> providerList = providerService.getProviderList("", "", 1, totalNum);
//將此供應(yīng)商列表存入req中 為了使我們搜索框搜素內(nèi)容不清空
req.setAttribute("providerList",providerList);
req.setAttribute("queryProductName",queryProductName);
req.setAttribute("queryProviderId",proId);
req.setAttribute("queryIsPayment",isPayment);
//分頁顯示數(shù)據(jù)
req.setAttribute("totalCount",totalCount);
req.setAttribute("currentPageNo",currentPageNo);
req.setAttribute("totalPageCount",totalPageCount);
//返回前端頁面查看
req.getRequestDispatcher("billlist.jsp").forward(req,resp);
}
//查詢供應(yīng)商 billadd.jsp頁面中的下拉框調(diào)用
public void getproviderlist(HttpServletRequest req, HttpServletResponse resp) throws IOException {
ProviderServiceImpl providerService = new ProviderServiceImpl();
int providerCounts = providerService.getProviderCounts("", "");
List<Provider> providerList = providerService.getProviderList("", "", 1, providerCounts);
//將信息 發(fā)送給ajax 將此集合轉(zhuǎn)換為json格式傳遞
resp.setContentType("application/json");
PrintWriter out = resp.getWriter();
//JSONArray 阿里巴巴的JSON工具類 用途就是:轉(zhuǎn)換格式
out.write(JSONArray.toJSONString(providerList));
out.flush();
out.close();
}
//添加訂單
public void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//從前端獲取數(shù)據(jù) 并封裝
Bill bill = new Bill();
bill.setBillCode(req.getParameter("billCode"));
bill.setProductName(req.getParameter("productName"));
bill.setProductUnit(req.getParameter("productUnit"));
bill.setProductCount(BigDecimal.valueOf(Double.parseDouble(req.getParameter("productCount"))));
bill.setTotalPrice(BigDecimal.valueOf(Double.parseDouble(req.getParameter("totalPrice"))));
bill.setProviderId(Integer.parseInt(req.getParameter("providerId")));
bill.setIsPayment(Integer.parseInt(req.getParameter("isPayment")));
//下面是表單沒有的
bill.setCreatedBy(((User)req.getSession().getAttribute(Constants.USER_SESSION)).getId());
bill.setCreationDate(new Date());
bill.setModifyBy(((User)req.getSession().getAttribute(Constants.USER_SESSION)).getId());
bill.setModifyDate(new Date());
BillServiceImpl billService = new BillServiceImpl();
if(billService.addBill(bill)){
//如果添加成功 重定向跳轉(zhuǎn)到展示訂單頁面
resp.sendRedirect(req.getContextPath()+"/jsp/bill.do?method=query");
}else{
//添加失敗 轉(zhuǎn)發(fā)到此添加頁面
req.getRequestDispatcher("billadd.jsp").forward(req,resp);
}
}
//刪除訂單
public void deleteBill(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//從前端獲取要?jiǎng)h除的訂單id
String billid = req.getParameter("billid");
int id = 0;
//轉(zhuǎn)換
try {
id = Integer.parseInt(billid);
}catch (Exception e){
e.printStackTrace();
id = 0;
}
BillServiceImpl billService = new BillServiceImpl();
//創(chuàng)建一個(gè)map集合 存儲(chǔ) 刪除成功和失敗的信息 傳遞給ajax
Map<Object, Object> resultMap = new HashMap<>();
if(id <= 0){
resultMap.put("delResult","notexist");
}else{
if(billService.deleteBill(id)){
System.out.println("刪除訂單成功...");
//刪除訂單成功
resultMap.put("delResult","true");
}else{
System.out.println("刪除訂單失敗...");
resultMap.put("delResult","false");
}
}
//將此map集合 轉(zhuǎn)換為json格式
resp.setContentType("application/json");
PrintWriter out = resp.getWriter();
//JSONArray 阿里巴巴的JSON工具類 用途就是:轉(zhuǎn)換格式
out.write(JSONArray.toJSONString(resultMap));
out.flush();
out.close();
}
// 要修改的訂單信息 展示
public void modify(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//從前端獲取要修改的訂單id
String billid = req.getParameter("billid");
int id = 0;
try {
id = Integer.parseInt(billid);
}catch (Exception e){
e.printStackTrace();
id = 0;
}
//根據(jù)此id查詢訂單的信息并在修改頁面展示
BillServiceImpl billService = new BillServiceImpl();
Bill bill = billService.findByBillId(id);
bill.setId(id);
//將此bill存入req 并轉(zhuǎn)發(fā)到 billmodify.jsp頁面
req.setAttribute("bill",bill);
req.getRequestDispatcher("billmodify.jsp").forward(req,resp);
}
//修改訂單信息方法
public void modifysave(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
//從前端獲取要修改的訂單id
String billid = req.getParameter("billid");
System.out.println("從前端獲取的訂單id:"+billid);
int id = 0;
try {
id = Integer.parseInt(billid);
}catch (Exception e){
e.printStackTrace();
id = 0;
}
//根據(jù)id查詢舊訂單信息
BillServiceImpl billService = new BillServiceImpl();
Bill bill = billService.findByBillId(id);
//根據(jù)修改的信息 修改對(duì)應(yīng)的訂單
bill.setBillCode(req.getParameter("billCode"));
bill.setProductName(req.getParameter("productName"));
bill.setProductUnit(req.getParameter("productUnit"));
bill.setProductCount(BigDecimal.valueOf(Double.parseDouble(req.getParameter("productCount"))));
bill.setTotalPrice(BigDecimal.valueOf(Double.parseDouble(req.getParameter("totalPrice"))));
bill.setProviderId(Integer.parseInt(req.getParameter("providerId")));
bill.setIsPayment(Integer.parseInt(req.getParameter("isPayment")));
//下面是表單未顯示的
bill.setModifyBy(((User)req.getSession().getAttribute(Constants.USER_SESSION)).getId());
bill.setModifyDate(new Date());
//執(zhí)行修改語句
boolean flag = billService.modifyBill(id, bill);
if(flag){
//如果修改成功 重定向到訂單展示頁面
resp.sendRedirect(req.getContextPath()+"/jsp/bill.do?method=query");
}else{
//修改失敗 轉(zhuǎn)發(fā)到此修改頁面
req.getRequestDispatcher("billmodify.jsp").forward(req,resp);
}
}
//查看 訂單信息
public void viewBill(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//從前端獲取要查看訂單信息的id
String BillId = req.getParameter("billid");
int id = 0;
try {
id = Integer.parseInt(BillId);
}catch (ClassCastException e){
e.printStackTrace();
id = 0;
}
//根據(jù)id查詢訂單信息
BillServiceImpl billService = new BillServiceImpl();
Bill bill = billService.findByBillId(id);
//將信息存入req
req.setAttribute("bill",bill);
//轉(zhuǎn)發(fā)到billview.jsp頁面
req.getRequestDispatcher("billview.jsp").forward(req,resp);
}
}
com.chen.servlet.Provider.ProviderServlet
package com.chen.servlet.Provider;/*
*
*/
import com.alibaba.fastjson.JSONArray;
import com.chen.pojo.Provider;
import com.chen.pojo.User;
import com.chen.service.Provider.ProviderServiceImpl;
import com.chen.util.Constants;
import com.chen.util.PageSupport;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
public class ProviderServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method = req.getParameter("method");
if(method.equals("query")){
this.query(req,resp);
}else if(method.equals("add")){
this.add(req,resp);
}else if(method.equals("delprovider")){
this.deleteProvider(req,resp);
}else if(method.equals("modify")){
this.findById(req,resp);
}else if(method.equals("modifyexe")){
this.modify(req,resp);
}else if(method.equals("view")){
this.view(req,resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
//查詢 供應(yīng)商 列表的方法
public void query(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//從providerlist.jsp中獲取傳來的數(shù)據(jù)
String queryProCode = req.getParameter("queryProCode");
String queryProName = req.getParameter("queryProName");
String pageIndex = req.getParameter("pageIndex");
List<Provider> providerList = null;
int currentPageNo = 1;
int pageSize = 5;
//還需判斷前端傳來的數(shù)據(jù)是否為空
if (queryProCode == null) {
queryProCode = "";
}
if (queryProName == null ){
queryProName = "";
}
if(pageIndex!=null){
currentPageNo = Integer.parseInt(pageIndex);
}
ProviderServiceImpl providerService = new ProviderServiceImpl();
//獲取符合條件的 信息數(shù)量
int providerCounts = providerService.getProviderCounts(queryProCode, queryProName);
//總頁數(shù)支持
PageSupport pageSupport = new PageSupport();
System.out.println("currentPageNo:"+currentPageNo);
pageSupport.setCurrentPageNo(currentPageNo);
pageSupport.setPageSize(pageSize);
System.out.println("providerCounts:"+providerCounts);
pageSupport.setTotalCount(providerCounts);
//總共的頁數(shù)
int totalPageCount = pageSupport.getTotalPageCount();
//總記錄數(shù)
int totalCount = pageSupport.getTotalCount();
//獲取符合條件的 信息
providerList= providerService.getProviderList(queryProCode, queryProName, currentPageNo, pageSize);
//將信息存入requset 使得在前端展示
req.setAttribute("providerList",providerList);
req.setAttribute("totalCount",totalCount);
req.setAttribute("currentPageNo",currentPageNo);
req.setAttribute("totalPageCount",totalPageCount);
req.setAttribute("queryProCode",queryProCode);
req.setAttribute("queryProName",queryProName);
//返回前端頁面展示
req.getRequestDispatcher("providerlist.jsp").forward(req,resp);
}
//添加 供應(yīng)商方法
public void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
//從前端 獲取供應(yīng)商的信息
String proCode = req.getParameter("proCode");
String proName = req.getParameter("proName");
String proContact = req.getParameter("proContact");
String proPhone = req.getParameter("proPhone");
String proAddress = req.getParameter("proAddress");
String proFax = req.getParameter("proFax");
String proDesc = req.getParameter("proDesc");
//下面的參數(shù)自己獲取
int createdBy = ((User)req.getSession().getAttribute(Constants.USER_SESSION)).getId();
//將信息封裝成一個(gè)供應(yīng)商對(duì)象
Provider provider = new Provider();
provider.setProCode(proCode);
provider.setProName(proName);
provider.setProContact(proContact);
provider.setProPhone(proPhone);
provider.setProAddress(proAddress);
provider.setProFax(proFax);
provider.setProDesc(proDesc);
provider.setCreatedBy(createdBy);
provider.setCreationDate(new Date());
//調(diào)用service層方法
ProviderServiceImpl providerService = new ProviderServiceImpl();
boolean flag = providerService.addProvider(provider);
//如果成功 則重定向到providerlist.jsp頁面
if(flag){
resp.sendRedirect(req.getContextPath()+"/jsp/provider.do?method=query");
}else{
//失敗 跳轉(zhuǎn)到添加頁面
req.getRequestDispatcher("provideradd.jsp").forward(req,resp);
}
}
//刪除供應(yīng)商的方法
public void deleteProvider(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//從前端獲取 要?jiǎng)h除的供應(yīng)商 的id
String proid = req.getParameter("proid");
int id = 0;
try {
id = Integer.parseInt(proid);
}catch (Exception e){
e.printStackTrace();
id = 0;
}
//將信息存入一個(gè)map集合中 傳給ajax
HashMap<Object, Object> resultMap = new HashMap<>();
if(id<=0){
resultMap.put("delResult","notexist");
}else{
ProviderServiceImpl providerService = new ProviderServiceImpl();
if(providerService.deleteProvider(id)){
//如果刪除成功
resultMap.put("delResult","true");
}else{
resultMap.put("delResult","false");
}
}
//將此map集合轉(zhuǎn)換成json格式傳遞
resp.setContentType("application/json");
PrintWriter out = resp.getWriter();
//JSONArray 阿里巴巴的JSON工具類 用途就是:轉(zhuǎn)換格式
out.write(JSONArray.toJSONString(resultMap));
out.flush();
out.close();
}
//根據(jù)id查詢供應(yīng)商信息的方法
public void findById(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
//從前端獲取id
String proid = req.getParameter("proid");
int id = 0;
try {
id = Integer.parseInt(proid);
}catch (Exception e){
e.printStackTrace();
id = 0;
}
if(id>0){
ProviderServiceImpl providerService = new ProviderServiceImpl();
Provider provider = providerService.findById(id);
//設(shè)置id 讓修改提交時(shí)可獲取
provider.setId(id);
//將供應(yīng)商信息存至 req
req.setAttribute("provider",provider);
//返回至前端展示頁面
req.getRequestDispatcher("providermodify.jsp").forward(req,resp);
}
}
//修改供應(yīng)商信息方法
public void modify(HttpServletRequest req,HttpServletResponse resp) throws IOException, ServletException {
System.out.println("enter modify ...");
//從前端獲取 要修改的供應(yīng)商的id信息
String proId = req.getParameter("proid");
System.out.println("proId : ->"+proId.toString());
int id = 0;
try {
id = Integer.parseInt(proId);
}catch (Exception e){
e.printStackTrace();
id = 0;
}
//從前端獲取供應(yīng)商信息
String proCode = req.getParameter("proCode");
String proName = req.getParameter("proName");
String proContact = req.getParameter("proContact");
String proPhone = req.getParameter("proPhone");
String proAddress = req.getParameter("proAddress");
String proFax = req.getParameter("proFax");
String proDesc = req.getParameter("proDesc");
//封裝成一個(gè)對(duì)象
Provider provider = new Provider();
provider.setProCode(proCode);
provider.setProName(proName);
provider.setProContact(proContact);
provider.setProPhone(proPhone);
provider.setProAddress(proAddress);
provider.setProFax(proFax);
provider.setProDesc(proDesc);
//下面的參數(shù)不是由前端傳來的
provider.setModifyDate(new Date());
provider.setModifyBy(((User)req.getSession().getAttribute(Constants.USER_SESSION)).getId());
if(id>0){
//執(zhí)行更改
ProviderServiceImpl providerService = new ProviderServiceImpl();
if(providerService.modifyProvider(id, provider)){
//如果修改成功 重定向到展示供應(yīng)商列表頁面
resp.sendRedirect(req.getContextPath()+"/jsp/provider.do?method=query");
}else{
//修改失敗 轉(zhuǎn)發(fā)到此修改頁面
req.getRequestDispatcher("providermodify.jsp").forward(req,resp);
}
}
}
//查看 供應(yīng)商信息方法
public void view(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
//從前端獲取供應(yīng)商的id
String proid = req.getParameter("proid");
int id = 0;
try {
id = Integer.parseInt(proid);
}catch (Exception e){
e.printStackTrace();
id = 0 ;
}
//根據(jù)id查詢
if(id >0){
ProviderServiceImpl providerService = new ProviderServiceImpl();
Provider provider = providerService.findById(id);
//將此對(duì)象傳到providerview.jsp進(jìn)行展示
req.setAttribute("provider",provider);
//重定向到展示頁
req.getRequestDispatcher("providerview.jsp").forward(req,resp);
}
}
}
com.chen.servlet.User.LoginServlet
package com.chen.servlet.User;/*
*
*/
import com.chen.pojo.User;
import com.chen.service.User.UserService;
import com.chen.service.User.UserServiceImpl;
import com.chen.util.Constants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//處理登錄請(qǐng)求的servlet
public class LoginServlet extends HttpServlet {
//控制層 調(diào)用業(yè)務(wù)層代碼 進(jìn)行判斷
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//獲取登錄頁面?zhèn)鱽淼男畔? String userCode = req.getParameter("userCode");
String userPassword = req.getParameter("userPassword");
//和數(shù)據(jù)庫中的密碼進(jìn)行對(duì)比,調(diào)用業(yè)務(wù)層
UserService userService = new UserServiceImpl();
//把登錄的人的信息查到
User user = userService.login(userCode, userPassword);
//判斷
if (user == null || !user.getUserPassword().equals(userPassword)) {
//查無此人
//轉(zhuǎn)發(fā)回登錄頁面 提示 用戶名或密碼錯(cuò)誤
req.setAttribute("error","用戶名或密碼錯(cuò)誤");
req.getRequestDispatcher("login.jsp").forward(req,resp);
}else{
//查有此人
//將用戶的信息放在session中
req.getSession().setAttribute(Constants.USER_SESSION,user);
//跳轉(zhuǎn)到主頁
resp.sendRedirect("jsp/frame.jsp");
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
com.chen.servlet.User.LogoutServlet
package com.chen.servlet.User;/*
*/
import com.chen.util.Constants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class LogoutServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//移除用戶的session
req.getSession().removeAttribute(Constants.USER_SESSION);
//返回登錄頁面
resp.sendRedirect(req.getContextPath()+"/login.jsp");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
com.chen.servlet.User.UserServlet
package com.chen.servlet.User;/*
*/
import com.alibaba.fastjson.JSONArray;
import com.chen.pojo.Role;
import com.chen.pojo.User;
import com.chen.service.Role.RoleServiceImpl;
import com.chen.service.User.UserServiceImpl;
import com.chen.util.Constants;
import com.chen.util.PageSupport;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//實(shí)現(xiàn)Servlet復(fù)用
public class UserServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method = req.getParameter("method");
if(method.equals("savePwd")){
this.savePwd(req,resp);
}else if(method.equals("pwdmodify")){
this.verifyPwd(req,resp);
}else if(method.equals("query")){
this.query(req,resp);
}else if(method.equals("add")){
this.add(req,resp);
}else if(method.equals("getRoleList")){
this.getRoleList(req,resp);
}else if(method.equals("ifExist")){
this.ifExist(req,resp);
}else if(method.equals("deluser")){
this.deleteUser(req,resp);
}else if(method.equals("modify")){
this.findById(req,resp);
}else if(method.equals("modifyexe")){
this.modify(req,resp);
}else if(method.equals("view")){
this.viewUser(req,resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
//用戶修改密碼方法
public void savePwd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//從Session中獲取ID
Object obj = req.getSession().getAttribute(Constants.USER_SESSION);
//獲取前端頁面?zhèn)鱽淼男旅艽a
String newpassword = req.getParameter("newpassword");
//先判斷不為空 再比較密碼是否相等
if(obj != null && newpassword != null){
User user = (User) obj;
UserServiceImpl userService = new UserServiceImpl();
//修改密碼并返回結(jié)果
boolean flag = userService.updatePassword(user.getId(), newpassword);
//如果密碼修改成功 移除當(dāng)前session
if(flag){
req.setAttribute("message","修改密碼成功,請(qǐng)使用新密碼登錄!");
req.getSession().removeAttribute(Constants.USER_SESSION);
}else{
req.setAttribute("message","密碼修改失敗 新密碼不符合規(guī)范");
}
}else{
req.setAttribute("message","新密碼不能為空!");
}
//修改完了 重定向到此修改頁面
req.getRequestDispatcher("pwdmodify.jsp").forward(req,resp);
}
//驗(yàn)證密碼的方法
public void verifyPwd(HttpServletRequest req, HttpServletResponse resp)throws IOException{
//依舊從session中取ID
Object obj = req.getSession().getAttribute(Constants.USER_SESSION);
//取 前端傳來的舊密碼
String oldpassword = req.getParameter("oldpassword");
//將結(jié)果存放在map集合中 讓Ajax使用
Map<String, String> resultMap = new HashMap<>();
//下面開始判斷 鍵都是用result 此處匹配js中的Ajax代碼
if(obj == null){
//說明session被移除了 或未登錄|已注銷
resultMap.put("result","sessionerror");
}else if(oldpassword == null){
//前端輸入的密碼為空
resultMap.put("result","error");
}else {
//如果舊密碼與前端傳來的密碼相同
if(((User)obj).getUserPassword().equals(oldpassword)){
resultMap.put("result","true");
}else{
//前端輸入的密碼和真實(shí)密碼不相同
resultMap.put("result","false");
}
}
//上面已經(jīng)封裝好 現(xiàn)在需要傳給Ajax 格式為json 所以我們得轉(zhuǎn)換格式
resp.setContentType("application/json");//將應(yīng)用的類型變成json
PrintWriter writer = resp.getWriter();
//JSONArray 阿里巴巴的JSON工具類 用途就是:轉(zhuǎn)換格式
writer.write(JSONArray.toJSONString(resultMap));
writer.flush();
writer.close();
}
//查詢用戶列表的方法
public void query(HttpServletRequest req, HttpServletResponse resp){
//查詢用戶列表
//從前端獲取數(shù)據(jù)
String queryUserName = req.getParameter("queryName");
String temp = req.getParameter("queryUserRole");//值為0 、1、2、3
String pageIndex = req.getParameter("pageIndex");
int queryUserRole = 0;
//獲取用戶列表
UserServiceImpl userService = new UserServiceImpl();
//第一次走這個(gè)請(qǐng)求,一定是第一頁,頁面大小固定的
List<User> userList = null;
int currentPageNo = 1;//當(dāng)前頁碼
int pageSize = 5;//頁數(shù) 可以把這個(gè)寫到配置文件中,方便后期修改
if(queryUserName == null){
queryUserName = "";
}
if(temp!=null && !temp.equals("")){
queryUserRole = Integer.parseInt(temp);//給查詢賦值!0,1,2,3
}
if(pageIndex!=null){
currentPageNo = Integer.parseInt(pageIndex);
}
//獲取用戶總數(shù) 分頁:上一頁 下一頁
int totalCount = userService.getUserCounts(queryUserName, queryUserRole);
//總頁數(shù)支持
PageSupport pageSupport = new PageSupport();
System.out.println("當(dāng)前頁:"+currentPageNo);
pageSupport.setCurrentPageNo(currentPageNo);
pageSupport.setPageSize(pageSize);
System.out.println("獲取用戶總數(shù)"+totalCount);
pageSupport.setTotalCount(totalCount);
//總共的頁數(shù)
int totalPageCount = pageSupport.getTotalPageCount();
//控制首頁和尾頁
//如果頁數(shù)小于1,就顯示第一頁 頁數(shù)大于 最后一頁就 顯示最后一頁
if(currentPageNo<1){
currentPageNo =1;
}else if(currentPageNo>totalPageCount){//當(dāng)前頁面大于了最后一頁
currentPageNo = totalPageCount;
}
System.out.println("返回UserList的數(shù)據(jù)測(cè)試"+queryUserName+":"+queryUserRole+":"+currentPageNo+":"+pageSize);
//獲取用戶列表展示
userList = userService.getUserList(queryUserName, queryUserRole, currentPageNo, pageSize);
//將數(shù)據(jù)傳給前端
System.out.println(userList);
// for (User user : userList) {
// System.out.println(user.toString());
// }
req.setAttribute("userList",userList);
RoleServiceImpl roleService = new RoleServiceImpl();
//所有角色
List<Role> roleList = roleService.getRoleList();
req.setAttribute("roleList",roleList);
req.setAttribute("totalCount",totalCount);
req.setAttribute("currentPageNo",currentPageNo);
req.setAttribute("totalPageCount",totalPageCount);
req.setAttribute("queryUserName",queryUserName);
req.setAttribute("queryUserRole",queryUserRole);
//返回至前端
try {
req.getRequestDispatcher("userlist.jsp").forward(req,resp);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//添加用戶方法
public void add(HttpServletRequest req, HttpServletResponse resp)throws IOException,ServletException {
System.out.println("進(jìn)入add方法");
//從前端獲取數(shù)據(jù)
String addUserCode = req.getParameter("userCode");
// System.out.println("\n前端輸入的:"+addUserCode+"\n");
String addUserName = req.getParameter("userName");
String addUserPassword = req.getParameter("userPassword");
String addGender = req.getParameter("gender");
String addBirthday = req.getParameter("birthday");
String addPhone = req.getParameter("phone");
String addAddress = req.getParameter("address");
String addUserRole = req.getParameter("userRole");
//對(duì)數(shù)據(jù)進(jìn)行封裝
User user = new User();
user.setUserCode(addUserCode);
user.setUserName(addUserName);
user.setUserPassword(addUserPassword);
user.setGender(Integer.parseInt(addGender));
try {
user.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse(addBirthday));
}catch (ParseException e){
e.printStackTrace();
}
user.setPhone(addPhone);
user.setAddress(addAddress);
user.setUserRole(Integer.parseInt(addUserRole));
//注意這兩個(gè)參數(shù)不在表單的填寫范圍內(nèi)
user.setCreatedBy(((User)req.getSession().getAttribute(Constants.USER_SESSION)).getId());
user.setCreateDate(new Date());
// System.out.println("封裝好的:"+user.getUserCode());
//調(diào)用service執(zhí)行添加方法
UserServiceImpl userService = new UserServiceImpl();
boolean flag = userService.addUser(user);
if(flag){
//說明執(zhí)行成功 網(wǎng)頁重定向到 用戶管理頁面(即 查詢?nèi)坑脩袅斜?
resp.sendRedirect(req.getContextPath()+"/jsp/user.do?method=query");
}else{
//說明 添加失敗 轉(zhuǎn)發(fā)到此 添加頁面
req.getRequestDispatcher("useradd.jsp").forward(req,resp);
}
}
//用戶管理模塊中 子模塊(添加用戶——表單中的用戶角色下拉框)
public void getRoleList(HttpServletRequest req, HttpServletResponse resp) throws IOException {
List<Role> roleList = null;
RoleServiceImpl roleService = new RoleServiceImpl();
List<Role> roleList1 = roleService.getRoleList();
//把roleList1 轉(zhuǎn)換為json對(duì)象輸出
resp.setContentType("application/json");
PrintWriter out = resp.getWriter();
out.write(JSONArray.toJSONString(roleList1));
out.flush();
out.close();
}
//用戶管理模塊 子模塊(驗(yàn)證用戶編碼是否已經(jīng)存在)
public void ifExist(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//獲取前端輸入 的用戶編碼
String userCode = req.getParameter("userCode");
//將結(jié)果存放在map集合中 讓Ajax使用
Map<String, String> resultMap = new HashMap<>();
if(userCode == null || userCode.equals("")){
System.out.println("前端未填寫用戶編碼...");
resultMap.put("userCode","NoWrite");
}else{
System.out.println("前端填寫了用戶編碼...");
UserServiceImpl userService = new UserServiceImpl();
User isNullUser = userService.login(userCode, "");
//判斷是否已經(jīng)存在這個(gè)用戶編碼
boolean flag = isNullUser != null ? true : false;
if(flag){
//用戶編碼存在
//將信息存入map中
resultMap.put("userCode","exist");
}
}
//上面已經(jīng)封裝好 現(xiàn)在需要傳給Ajax 格式為json 所以我們得轉(zhuǎn)換格式
resp.setContentType("application/json");//將應(yīng)用的類型變成json
PrintWriter writer = resp.getWriter();
//JSONArray 阿里巴巴的JSON工具類 用途就是:轉(zhuǎn)換格式
writer.write(JSONArray.toJSONString(resultMap));
writer.flush();
writer.close();
}
//用戶管理模塊中的子模塊 —— 刪除用戶
public void deleteUser(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//從前端獲取 要?jiǎng)h除的用戶 的信息
String userid = req.getParameter("uid");
int delId = 0;
//先轉(zhuǎn)換
try {
delId= Integer.parseInt(userid);
}catch (Exception e){
e.printStackTrace();
delId = 0;
}
//將結(jié)果存放在map集合中 讓Ajax使用
Map<String, String> resultMap = new HashMap<>();
if(delId<=0){
resultMap.put("delResult","notexist");
}else {
UserServiceImpl userService = new UserServiceImpl();
if(userService.deleteUser(delId)){
resultMap.put("delResult","true");
}else {
resultMap.put("delResult", "false");
}
}
//上面已經(jīng)封裝好 現(xiàn)在需要傳給Ajax 格式為json 所以我們得轉(zhuǎn)換格式
resp.setContentType("application/json");//將應(yīng)用的類型變成json
PrintWriter writer = resp.getWriter();
//JSONArray 阿里巴巴的JSON工具類 用途就是:轉(zhuǎn)換格式
writer.write(JSONArray.toJSONString(resultMap));
writer.flush();
writer.close();
}
//用戶管理模塊中的功能 —— 根據(jù)id查詢用戶信息
public void findById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//從前端獲取 要修改的用戶 的id
String uId = req.getParameter("uid");
int userId = 0;
try {
userId = Integer.parseInt(uId);
}catch (Exception e){
e.printStackTrace();
}
UserServiceImpl userService = new UserServiceImpl();
//查詢要更改的用戶信息
User user = userService.findById(userId);
//將用戶信息保存至 request中 讓usermodify.jsp顯示
req.setAttribute("user",user);
req.getRequestDispatcher("usermodify.jsp").forward(req,resp);
}
//用戶管理模塊中的子模塊 —— 更改用戶信息
public void modify(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
//從前端獲取 要修改的用戶 的id
String uId = req.getParameter("uid");
int userId = 0;
try {
userId = Integer.parseInt(uId);
}catch (Exception e){
e.printStackTrace();
}
//從修改信息的表單中封裝信息
User user = new User();
user.setUserName(req.getParameter("userName"));
user.setGender(Integer.parseInt(req.getParameter("gender")));
try {
user.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse(req.getParameter("birthday")));
}catch (ParseException e){
e.printStackTrace();
}
user.setPhone(req.getParameter("phone"));
user.setAddress(req.getParameter("address"));
user.setUserRole(Integer.parseInt(req.getParameter("userRole")));
//注意這兩個(gè)參數(shù)不在表單的填寫范圍內(nèi)
user.setModifyBy(((User)req.getSession().getAttribute(Constants.USER_SESSION)).getId());
user.setModifyDate(new Date());
UserServiceImpl userService = new UserServiceImpl();
if(userService.modify(userId,user)){
//如果執(zhí)行成功了 網(wǎng)頁重定向到 用戶管理頁面(即 查詢?nèi)坑脩袅斜?
resp.sendRedirect(req.getContextPath()+"/jsp/user.do?method=query");
}else{
//說明 添加失敗 轉(zhuǎn)發(fā)到此 添加頁面
req.getRequestDispatcher("usermodify.jsp").forward(req,resp);
}
}
//用戶管理模塊中的子模塊 —— 查詢用戶信息
public void viewUser(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//從前端獲取 要查詢用戶 的id
String id = req.getParameter("uid");
int userId = 0;
try {
userId = Integer.parseInt(id);
}catch (Exception e){
e.printStackTrace();
userId = 0;
}
//調(diào)用 根據(jù)id查詢用戶信息的方法
UserServiceImpl userService = new UserServiceImpl();
User user = userService.findById(userId);
//將此user發(fā)送到展示前端 的頁面進(jìn)行展示
req.setAttribute("user",user);
//跳轉(zhuǎn)到前端 的展示頁面
req.getRequestDispatcher("userview.jsp").forward(req,resp);
}
}
com.chen.util.Constants
package com.chen.util;/*
*
*/
//常量放置處
public class Constants {
public final static String USER_SESSION = "userSession";
}
com.chen.util.PageSupport
package com.chen.util;/*
*/
public class PageSupport {
//當(dāng)前頁面 來自于用戶輸入
private int currentPageNo = 1;
//總數(shù)量(表)
private int totalCount = 0;
//頁面容量
private int pageSize = 0;
//總共顯示的頁數(shù) 為總表數(shù)量/單頁容量 +1
private int totalPageCount =1;
public int getCurrentPageNo() {
return currentPageNo;
}
public void setCurrentPageNo(int currentPageNo) {
if(currentPageNo>0){
this.currentPageNo = currentPageNo;
}
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
if(totalCount>0){
this.totalCount = totalCount;
this.setTotalPageCountByRs();
}
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
if(pageSize>0){
this.pageSize = pageSize;
}
}
public int getTotalPageCount() {
return totalPageCount;
}
public void setTotalPageCount(int totalPageCount) {
this.totalPageCount = totalPageCount;
}
public void setTotalPageCountByRs(){
if(this.totalCount % this.pageSize == 0){
this.totalPageCount = this.totalCount / this.pageSize;
}else if(this.totalCount % this.pageSize > 0){
this.totalPageCount = this.totalCount / this.pageSize +1;
}else{
this.totalPageCount = 0;
}
}
}
db.properties
driver = com.mysql.cj.jdbc.Driver
url =jdbc:mysql://localhost:3306/smbms?\
useUnicode=true&characterEncoding=UTF8&useSSL=false&\
serverTimezone=UTC&rewriteBatchedStatements=true
username = root
password = password
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.chen.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--設(shè)置用戶登錄界面為訪問的第一個(gè)界面-->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!-- 注冊(cè)用戶登錄的Servlet-->
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.chen.servlet.User.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login.do</url-pattern>
</servlet-mapping>
<!-- 注銷用戶登錄的Servlet-->
<servlet>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>com.chen.servlet.User.LogoutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LogoutServlet</servlet-name>
<url-pattern>/jsp/logout.do</url-pattern>
</servlet-mapping>
<!-- 判斷用戶是否登錄的過濾器-->
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>com.chen.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/jsp/*</url-pattern>
</filter-mapping>
<!--注冊(cè) 復(fù)用的servlet -->
<servlet>
<servlet-name>UserServlet</servlet-name>
<servlet-class>com.chen.servlet.User.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserServlet</servlet-name>
<url-pattern>/jsp/user.do</url-pattern>
</servlet-mapping>
<!--注冊(cè) 供應(yīng)商的Servlet-->
<servlet>
<servlet-name>ProviderServlet</servlet-name>
<servlet-class>com.chen.servlet.Provider.ProviderServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ProviderServlet</servlet-name>
<url-pattern>/jsp/provider.do</url-pattern>
</servlet-mapping>
<!--注冊(cè) 訂單管理的Servlet-->
<servlet>
<servlet-name>BillServlet</servlet-name>
<servlet-class>com.chen.servlet.Bill.BillServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BillServlet</servlet-name>
<url-pattern>/jsp/bill.do</url-pattern>
</servlet-mapping>
</web-app>
error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2 style="text-align: center;color: red;">你要訪問的頁面,已經(jīng)飛往火星!</h2>
<a href="${pageContext.request.contextPath}/login.jsp"> <img src="images/error.png" alt="">重新登錄</a>
</body>
</html>
login.jsp文章來源:http://www.zghlxwxcb.cn/news/detail-487050.html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>系統(tǒng)登錄 - 超市管理系統(tǒng)</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<script type="text/javascript">
/* if(top.location!=self.location){
top.location=self.location;
} */
</script>
</head>
<body class="login_bg">
<%-- <%--%>
<%-- Object attribute = request.getAttribute("error");--%>
<%-- %>--%>
<section class="loginBox">
<header class="loginHeader">
<h1>超市管理系統(tǒng)</h1>
</header>
<section class="loginCont">
<form class="loginForm" action="${pageContext.request.contextPath}/login.do" name="actionForm" id="actionForm" method="post" >
<%-- <div class="info">${error}</div>--%>
<div class="inputbox">
<label for="userCode">用戶名</label>
<input type="text" class="input-text" id="userCode" name="userCode" placeholder="請(qǐng)輸入用戶名" required/>
</div>
<div class="inputbox">
<label for="userPassword">密碼</label>
<input type="password" id="userPassword" name="userPassword" placeholder="請(qǐng)輸入密碼" required/>
</div>
<div class="info" style="text-align: center;">${error}</div>
<div class="subBtn">
<input type="submit" value="登錄"/>
<input type="reset" value="重置"/>
</div>
</form>
</section>
</section>
</body>
</html>
pom.xml文章來源地址http://www.zghlxwxcb.cn/news/detail-487050.html
<?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.csnz</groupId>
<artifactId>smbms</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- jsp-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.24</version>
</dependency>
<!-- JSTL表達(dá)式-->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<!-- standard-->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- Junit單元測(cè)試-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- 阿里巴巴的fastjson:用于轉(zhuǎn)換json格式-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.61</version>
</dependency>
</dependencies>
<!-- <build>
<plugins>
<plugin>
<groupId></groupId>
<artifactId>maven</artifactId>
<version></version>
<configuration>
<!– 對(duì)丟失web.xml檢測(cè)機(jī)制進(jìn)行忽略, Dynamic Web Module 3.0 工程時(shí)代不需要web.xml文件注冊(cè)相關(guān)內(nèi)容的,所以工程默認(rèn)不生成web.xml。–>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!–maven-war-plugin–>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<!– 使用jdk1版本時(shí)使用該配置,如果要使用jdk1.8,則下面2行要修改為1.8 –>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>-->
</project>
到了這里,關(guān)于JSP+Servlet+MySql超市管理系統(tǒng)項(xiàng)目源碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!