作者主页:夜未央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. 后端:Spring+SpringMVC+Mybatis
2. 前端:JSP+CSS+JavaScript+jquery+easyUI
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中jdbc-druid-config.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入http://localhost:8080/ssm_sims 登录
管理员账号/密码:admin/admin
运行截图
代码相关
用户管理控制器
/*
* 用户操作页面
*
*/
@Controller
@RequestMapping("/user")
public class UserContriller {
@Autowired
UserService userService;
//跳转个人首页首页
@RequestMapping("index.do")
public String index(HttpServletRequest request) {
if(Tool.ismobile(request)){
return "jsp/mobile/user/user";
}else{
return "jsp/index/user/user-ziliao";
}
}
//查看个人资料
@RequestMapping("ziliao.do")
public String ziliao(HttpServletRequest request) {
if(Tool.ismobile(request)){
return "jsp/mobile/user/user-ziliao";
}else{
return "jsp/index/user/user-ziliao";
}
}
//修改用户
@RequestMapping("update.do")
public String update(HttpServletRequest request, Model model,User user) {
User sessionuser=(User)request.getSession().getAttribute(PublicStatic.USER);
user.setId(sessionuser.getId());
userService.update(user);
user=userService.findbyuserid(sessionuser.getId());
request.getSession().setAttribute(PublicStatic.USER, user);
return "redirect:/user/index.do";
}
//退出
@RequestMapping("logout.do")
public String logout(HttpServletRequest request,HttpServletResponse response) {
HttpSession session = request.getSession();
session.invalidate();
Cookie[] cookies=request.getCookies();
for(Cookie cookie: cookies){
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
}
return "redirect:/";
}
//跳转修改密码
@RequestMapping("topwd.do")
public String topwd(HttpServletRequest request) {
return "jsp/index/user/user-pwd";
}
//修改密码
@ResponseBody
@RequestMapping("pwd.do")
public String pwd(HttpServletRequest request,String pwd ,String newpwd) {
User sessionuser=(User)request.getSession().getAttribute(PublicStatic.USER);
User user=new User();
user.setId(sessionuser.getId());
user.setPwd(pwd);
String login = userService.login(user, request);
if("1".equals(login)){
user.setPwd(Tool.MD5(newpwd));
userService.update(user);
return "1";
}else{
return "0";
}
}
}
上传管理控制器
public class Uploader {
// 输出文件地址
private String url = "";
// 上传文件名
private String fileName = "";
// 状态
private String state = "";
// 文件类型
private String type = "";
// 原始文件名
private String originalName = "";
// 文件大小
private long size = 0;
private HttpServletRequest request = null;
private String title = "";
// 保存路径
private String savePath = "upload";
// 文件允许格式
private String[] allowFiles = { ".rar", ".doc", ".docx", ".zip", ".pdf",".txt", ".swf", ".wmv", ".gif", ".png", ".jpg", ".jpeg", ".bmp" };
// 文件大小限制,单位KB
private int maxSize = 10000;
private HashMap<String, String> errorInfo = new HashMap<String, String>();
public Uploader(HttpServletRequest request) {
this.request = request;
HashMap<String, String> tmp = this.errorInfo;
tmp.put("SUCCESS", "SUCCESS"); //默认成功
tmp.put("NOFILE", "未包含文件上传域");
tmp.put("TYPE", "不允许的文件格式");
tmp.put("SIZE", "文件大小超出限制");
tmp.put("ENTYPE", "请求类型ENTYPE错误");
tmp.put("REQUEST", "上传请求异常");
tmp.put("IO", "IO异常");
tmp.put("DIR", "目录创建失败");
tmp.put("UNKNOWN", "未知错误");
}
public void upload() throws Exception {
boolean isMultipart = ServletFileUpload.isMultipartContent(this.request);
if (!isMultipart) {
this.state = this.errorInfo.get("NOFILE");
return;
}
DiskFileItemFactory dff = new DiskFileItemFactory();
String formater = "/cj" +new SimpleDateFormat("yyyyMMdd").format(new Date());
dff.setRepository(new File(savePath));
try {
ServletFileUpload sfu = new ServletFileUpload(dff);
sfu.setSizeMax(this.maxSize * 1024);
sfu.setHeaderEncoding("utf-8");
FileItemIterator fii = sfu.getItemIterator(this.request);
while (fii.hasNext()) {
FileItemStream fis = fii.next();
if (!fis.isFormField()) {
this.originalName = fis.getName().substring(fis.getName().lastIndexOf(System.getProperty("file.separator")) + 1);
if (!this.checkFileType(this.originalName)) {
this.state = this.errorInfo.get("TYPE");
continue;
}
this.fileName = this.getName(this.originalName);
this.type = this.getFileExt(this.fileName);
this.url = this.request.getContextPath()+"/download/downloadimg.do?f="+formater + "/" + this.fileName;
File files = new File(this.savePath+formater);
if (!files.exists()) {
files.mkdirs();
}
BufferedInputStream in = new BufferedInputStream(fis.openStream());
File file = new File(this.savePath+formater+"/"+this.fileName);
FileOutputStream out = new FileOutputStream( file );
BufferedOutputStream output = new BufferedOutputStream(out);
Streams.copy(in, output, true);
this.state=this.errorInfo.get("SUCCESS");
this.size = file.length();
//UE中只会处理单张上传,完成后即退出
break;
} else {
String fname = fis.getFieldName();
//只处理title,其余表单请自行处理
if(!fname.equals("pictitle")){
continue;
}
BufferedInputStream in = new BufferedInputStream(fis.openStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer result = new StringBuffer();
while (reader.ready()) {
result.append((char)reader.read());
}
this.title = new String(result.toString().getBytes(),"utf-8");
reader.close();
}
}
} catch (SizeLimitExceededException e) {
this.state = this.errorInfo.get("SIZE");
} catch (InvalidContentTypeException e) {
this.state = this.errorInfo.get("ENTYPE");
} catch (FileUploadException e) {
this.state = this.errorInfo.get("REQUEST");
} catch (Exception e) {
this.state = this.errorInfo.get("UNKNOWN");
e.printStackTrace();
}
}
/**
* 接受并保存以base64格式上传的文件
* @param fieldName
*/
public void uploadBase64(String fieldName){
String savePath = this.getFolder(this.savePath);
String base64Data = this.request.getParameter(fieldName);
this.fileName = this.getName("test.png");
this.url = savePath + "/" + this.fileName;
BASE64Decoder decoder = new BASE64Decoder();
try {
File outFile = new File(this.getPhysicalPath(this.url));
OutputStream ro = new FileOutputStream(outFile);
byte[] b = decoder.decodeBuffer(base64Data);
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
b[i] += 256;
}
}
ro.write(b);
ro.flush();
ro.close();
this.state=this.errorInfo.get("SUCCESS");
} catch (Exception e) {
this.state = this.errorInfo.get("IO");
}
}
/**
* 文件类型判断
*
* @param fileName
* @return
*/
private boolean checkFileType(String fileName) {
Iterator<String> type = Arrays.asList(this.allowFiles).iterator();
while (type.hasNext()) {
String ext = type.next();
if (fileName.toLowerCase().endsWith(ext)) {
return true;
}
}
return false;
}
/**
* 获取文件扩展名
*
* @return string
*/
private String getFileExt(String fileName) {
return fileName.substring(fileName.lastIndexOf("."));
}
/**
* 依据原始文件名生成新文件名
* @return
*/
private String getName(String fileName) {
Random random = new Random();
return this.fileName = "" + random.nextInt(10000)
+ System.currentTimeMillis() + this.getFileExt(fileName);
}
/**
* 根据字符串创建本地目录 并按照日期建立子目录返回
* @param path
* @return
*/
private String getFolder(String path) {
SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
path += "/" + formater.format(new Date());
File dir = new File(this.getPhysicalPath(path));
if (!dir.exists()) {
try {
dir.mkdirs();
} catch (Exception e) {
this.state = this.errorInfo.get("DIR");
return "";
}
}
return path;
}
/**
* 根据传入的虚拟路径获取物理路径
*
* @param path
* @return
*/
private String getPhysicalPath(String path) {
String servletPath = this.request.getServletPath();
String realPath = this.request.getSession().getServletContext()
.getRealPath(servletPath);
return new File(realPath).getParent() +"/" +path;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public void setAllowFiles(String[] allowFiles) {
this.allowFiles = allowFiles;
}
public void setMaxSize(int size) {
this.maxSize = size;
}
public long getSize() {
return this.size;
}
public String getUrl() {
return this.url;
}
public String getFileName() {
return this.fileName;
}
public String getState() {
return this.state;
}
public String getTitle() {
return this.title;
}
public String getType() {
return this.type;
}
public String getOriginalName() {
return this.originalName;
}
}
管理员管理控制器
@Controller
@RequestMapping("/admin/user")
public class AdminUserContriller {
@Autowired
UserService userService;
@Autowired
GroupService groupService;
@Autowired
JifenGroupService jifenGroupService;
//跳转首页
@RequestMapping("index.do")
public String add(HttpServletRequest request, Model model,User user,PageBean<User> page) {
page = userService.findpage(user,page);
model.addAttribute("page", page);
model.addAttribute("quser", user);
return "jsp/admin/user/index";
}
//更新
@RequestMapping("update.do")
public String update(HttpServletRequest request, Model model,User user) {
User sessionuser=(User)request.getSession().getAttribute(PublicStatic.USER);
user.setId(sessionuser.getId());
userService.update(user);
return "redirect:/user/index.do";
}
//删除
@ResponseBody
@RequestMapping("del.do")
public String del(HttpServletRequest request, Model model,User user) {
return userService.delete(user.getId());
}
//重置密码
@ResponseBody
@RequestMapping("updatepwd.do")
public String updatepwd(HttpServletRequest request, Model model,User user) {
String pwd="123456";
user.setPwd(Tool.MD5(pwd));
userService.update(user);
return "1";
}
//重置密码
@ResponseBody
@RequestMapping("updateflag.do")
public String updateflag(HttpServletRequest request, Model model,User user) {
userService.update(user);
return "1";
}
//设置管理员
@ResponseBody
@RequestMapping("updategroup.do")
public String updategroup(HttpServletRequest request, Model model,User user,int groupid) {
boolean b = groupService.updategroupbyuser(user.getId(), groupid);
if(b){
return "1";
}else{
return "0";
}
}
//删除用户帖子 留言 回帖 图片等信息信息
@ResponseBody
@RequestMapping("deluserallinfo.do")
public String deluserallinfo(HttpServletRequest request, Model model,User user) {
boolean b = userService.deluserallinfo(user.getId());
if(b){
return "1";
}else{
return "0";
}
}
@RequestMapping("tooptions.do")
public String tooptions(HttpServletRequest request, Model model,User user){
user = userService.findbyid(user);
model.addAttribute("user", user);
return "jsp/admin/user/option";
}
/**
* 设置用户vip等级
* @param request
* @param model
* @param user
* @return
*/
@RequestMapping(value="set_vip.do",method=RequestMethod.GET)
public String setVip(Model model,User user){
user = userService.findbyid(user);
model.addAttribute("user", user);
model.addAttribute("jifenGroupList", jifenGroupService.find(null));
return "jsp/admin/user/set_vip";
}
/**
* 设置用户vip等级表单提交
* @param userId
* @param jifen
* @return
*/
@RequestMapping(value="set_vip.do",method=RequestMethod.POST)
public String setVip(Integer userId, String vipLevel){
User user = new User();
user.setId(userId);
user = userService.findbyid(user);
user.setVipLevel(vipLevel);
userService.update(user);
return "redirect:index.do";
}
}
如果也想学习本系统,下面领取。关注并回复:120ssm