作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
管理员角色包含以下功能:
管理员登录,修改个人密码,用户管理,课程管理,课程添加,订单管理,留言管理,公告管理,添加公告等功能。
用户角色包含以下功能:
查看首页,查看特价课程,购买课程,提交订单,查看我的购物车,查看我的订单,修改个人信息,查看系统公告,提交留言等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:否;
技术栈
1. 后端:mysql+Spring+hibernate+Struts 2
2. 前端:HTML+CSS+JavaScript+jsp
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
运行截图
相关代码
PjAction
package com.my.pro.action;
import java.util.HashMap;
import org.springframework.beans.BeanUtils;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.my.pro.utils.Pager;
import com.opensymphony.xwork2.ModelDriven;
import java.util.*;
import com.my.pro.model.*;
import com.my.pro.dao.*;
import com.my.pro.service.*;
/**
* @ClassName:
* @Description:
* @author administrator
*
*/
@Controller("pjAction")
@Scope("prototype")
public class PjAction extends BaseAction implements ModelDriven<Pj>{
private static final long serialVersionUID = 1L;
//==========model==============
private Pj pj;
@Override
public Pj getModel() {
if(pj==null) pj = new Pj();
return pj;
}
//==========model==============
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private PjService pjService;
//依赖注入 end dao/service/===
//-------------------------华丽分割线---------------------------------------------
//============自定义参数start=============
//============自定义参数end=============
//-------------------------华丽分割线---------------------------------------------
//============文件上传start=======================================================
private File file;
//提交过来的file的名字
private String fileFileName;
//提交过来的file的MIME类型
private String fileContentType;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
//============文件上传end=========================================================
public String jsonAction() {
// dataMap中的数据将会被Struts2转换成JSON字符串,所以这里要先清空其中的数据
jsonMap.clear();
jsonMap.put("success", true);
return JSON_TYPE;
}
//-------------------------华丽分割线---------------------------------------------//
//=============公=======共=======方=======法==========区=========start============//
/**
* 列表分页查询 and isDelete = 0
*
*/
public String pj(){
Map<String,Object> alias = new HashMap<String,Object>();
StringBuffer sb = new StringBuffer();
sb = sb.append("from Pj where 1=1 ");
if(pj !=null && pj.getName() !=null){
sb.append(" and name like :realName ");
alias.put("realName", "%" + pj.getName()+ "%" );
}
sb = sb.append("order by id desc");
Pager<Pj> pagers = pjService.findByAlias(sb.toString(),alias);
ActionContext.getContext().put("pagers", pagers);
ActionContext.getContext().put("Obj", pj);
return SUCCESS;
}
/**
* 跳转到添加页面
* @return
*/
public String add(){
return SUCCESS;
}
/**
* 执行添加
* @return
*/
public String exAdd(){
pj.setAddTime(new Date());
pj.setUpdayteTime(new Date());
pjService.save(pj);
ActionContext.getContext().put("url", "/pj_pj.do");
return "redirect";
}
/**
* 查看详情页面
* @return
*/
public String view(){
Pj n = pjService.getById(pj.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 跳转修改页面
* @return
*/
public String update(){
Pj n = pjService.getById(pj.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 执行修改
* @return
*/
public String exUpdate(){
Pj n = pjService.getById(pj.getId());
n.setUpdayteTime(new Date());
BeanUtils.copyProperties(pj, n, getNullPropertyNames(pj));
pjService.update(n);
ActionContext.getContext().put("url", "/pj_pj.do");
return "redirect";
}
/**
* 删除
* @return
*/
public String delete(){
pjService.delete(pj.getId());
//n.setIsDelete(1);
ActionContext.getContext().put("url", "/pj_pj.do");
return "redirect";
}
//=============公=======共=======方=======法==========区=========end============//
//-------------------------华丽分割线---------------------------------------------//
//=============自=======定=======义=========方=======法==========区=========start============//
//=============自=======定=======义=========方=======法==========区=========end============//
}
SpAction
package com.my.pro.action;
import java.util.HashMap;
import org.springframework.beans.BeanUtils;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.my.pro.utils.Pager;
import com.my.pro.utils.UUIDUtils;
import com.opensymphony.xwork2.ModelDriven;
import java.util.*;
import com.my.pro.model.*;
import com.my.pro.dao.*;
import com.my.pro.service.*;
/**
* @ClassName:
* @Description:
* @author administrator
*
*/
@Controller("spAction")
@Scope("prototype")
public class SpAction extends BaseAction implements ModelDriven<Sp>{
private static final long serialVersionUID = 1L;
//==========model==============
private Sp sp;
@Override
public Sp getModel() {
if(sp==null) sp = new Sp();
return sp;
}
//==========model==============
/**
* 依赖注入 start dao/service/===
*/
@Autowired
private SpService spService;
//依赖注入 end dao/service/===
//-------------------------华丽分割线---------------------------------------------
//============自定义参数start=============
//============自定义参数end=============
//-------------------------华丽分割线---------------------------------------------
//============文件上传start=======================================================
private File file;
//提交过来的file的名字
private String fileFileName;
//提交过来的file的MIME类型
private String fileContentType;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
//============文件上传end=========================================================
public String jsonAction() {
// dataMap中的数据将会被Struts2转换成JSON字符串,所以这里要先清空其中的数据
jsonMap.clear();
jsonMap.put("success", true);
return JSON_TYPE;
}
//-------------------------华丽分割线---------------------------------------------//
//=============公=======共=======方=======法==========区=========start============//
/**
* 列表分页查询 and isDelete = 0
*
*/
public String sp(){
Map<String,Object> alias = new HashMap<String,Object>();
StringBuffer sb = new StringBuffer();
sb = sb.append("from Sp where 1=1 and isDelelet = 0 ");
sb = sb.append("order by id desc");
Pager<Sp> pagers = spService.findByAlias(sb.toString(),alias);
ActionContext.getContext().put("pagers", pagers);
ActionContext.getContext().put("Obj", sp);
return SUCCESS;
}
public String sp2(){
Map<String,Object> alias = new HashMap<String,Object>();
StringBuffer sb = new StringBuffer();
sb = sb.append("from Sp where 1=1 and isDelelet = 0 ");
sb = sb.append("order by id desc");
List<Sp> pagers = spService.listByAlias(sb.toString(),alias);
ActionContext.getContext().put("pagers", pagers);
ActionContext.getContext().put("Obj", sp);
List<Sp> listByAlias = spService.listByAlias("from Sp where 1=1 and isDelelet = 0 order by id desc",null);
if (!isEmpty(listByAlias) && listByAlias.size() >=5){
listByAlias = listByAlias.subList(0, 5);
}
ActionContext.getContext().put("news", listByAlias);
return SUCCESS;
}
/**
* 跳转到添加页面
* @return
*/
public String add(){
return SUCCESS;
}
/**
* 执行添加
* @return
* @throws IOException
*/
public String exAdd() throws IOException{
String root = "D:/my/upload";
InputStream is = new FileInputStream(file);
fileFileName = UUIDUtils.create()+fileFileName;
OutputStream os = new FileOutputStream(new File(root, fileFileName));
System.out.println("fileFileName: " + fileFileName);
System.out.println("file: " + file.getName());
System.out.println("file: " + file.getPath());
byte[] buffer = new byte[500];
int length = 0;
while(-1 != (length = is.read(buffer, 0, buffer.length)))
{
os.write(buffer);
}
os.close();
is.close();
sp.setUrls("\\upload\\"+fileFileName);
sp.setIsDelelet(0);
spService.save(sp);
ActionContext.getContext().put("url", "/sp_sp.do");
return "redirect";
}
/**
* 查看详情页面
* @return
*/
public String view(){
Sp n = spService.getById(sp.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 跳转修改页面
* @return
*/
public String update(){
Sp n = spService.getById(sp.getId());
ActionContext.getContext().put("Obj", n);
return SUCCESS;
}
/**
* 执行修改
* @return
* @throws IOException
*/
public String exUpdate() throws IOException{
Sp n = spService.getById(sp.getId());
String root = "D:/my/upload";
InputStream is = new FileInputStream(file);
fileFileName = UUIDUtils.create()+fileFileName;
OutputStream os = new FileOutputStream(new File(root, fileFileName));
System.out.println("fileFileName: " + fileFileName);
System.out.println("file: " + file.getName());
System.out.println("file: " + file.getPath());
byte[] buffer = new byte[500];
int length = 0;
while(-1 != (length = is.read(buffer, 0, buffer.length)))
{
os.write(buffer);
}
os.close();
is.close();
n.setUrls("\\upload\\"+fileFileName);
BeanUtils.copyProperties(sp, n, getNullPropertyNames(sp));
spService.update(n);
ActionContext.getContext().put("url", "/sp_sp.do");
return "redirect";
}
/**
* 删除
* @return
*/
public String delete(){
//spService.delete(sp.getId());
Sp n = spService.getById(sp.getId());
//n.setIsDelete(1);
spService.update(n);
ActionContext.getContext().put("url", "/sp_sp.do");
return "redirect";
}
//=============公=======共=======方=======法==========区=========end============//
//-------------------------华丽分割线---------------------------------------------//
//=============自=======定=======义=========方=======法==========区=========start============//
//=============自=======定=======义=========方=======法==========区=========end============//
}
如果也想学习本系统,下面领取。关注并回复:034ssh