作者主页:源码空间站2022
简介: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版本;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
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/ 登录
运行截图
管理员角色
用户角色
相关代码
GongaoController
package graduation.design.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import graduation.design.model.*;
import graduation.design.mapper.*;
import system.common.util.PageModel;
@Controller
@RequestMapping(value = "Gongao")
public class GongaoController {
@Autowired
private GongaoMapper gongaoMapper;
@RequestMapping(value = "/initUtil.do")
public String initUtil(HttpServletRequest request, Model model) {
return "Gongao/saveOrUpdate";
}
@RequestMapping(value = "/selectUtil.do")
public String selectUtil(HttpServletRequest request, Gongao util, Model model) {
util = gongaoMapper.selectObject(util.getId());
model.addAttribute("util", util);
return "Gongao/saveOrUpdate";
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = "/getAllUtil.do")
public String getAllUtil(HttpServletRequest request, Model model) {
String field = request.getParameter("field");
String fieldValue = request.getParameter("fieldValue");
try {
fieldValue = new String(fieldValue.getBytes("UTF-8"), "UTF-8");
} catch (Exception e) {}
String pageNo = request.getParameter("pageModel.currentPageNo");
int currentPageNo = 1;
try{
currentPageNo = Integer.parseInt(pageNo);
}catch(Exception e){
}
List<Gongao> list = gongaoMapper.getObjectList(field, fieldValue);
PageModel pageModel = new PageModel();
pageModel = pageModel.getUtilByController(list, currentPageNo);
model.addAttribute("pageModel", pageModel);
model.addAttribute("fieldValue", fieldValue);
model.addAttribute("field", field);
return "Gongao/find";
}
@RequestMapping(value = "/deleteUtil.do")
public String deleteUtil(HttpServletRequest request, Gongao util, Model model) {
try{
gongaoMapper.deleteObject(util.getId());
}catch(Exception e){
}
return this.getAllUtil(request, model);
}
@RequestMapping(value = "/deleteManyUtil.do")
public String deleteManyUtil(HttpServletRequest request, User util,
Model model) {
String ids[] = request.getParameterValues("id");
for (String id : ids) {
util = new User();
util.setId(Integer.parseInt(id));
try{
gongaoMapper.deleteObject(util.getId());
}catch(Exception e){}
}
return this.getAllUtil(request, model);
}
@RequestMapping(value = "/saveOrUpdateObject.do")
public String saveOrUpdateObject(HttpServletRequest request, Gongao util, Model model) {
List<Gongao> list = gongaoMapper.getObjectList("s_0", util.getS_0());
if (0 == util.getId()) {
if (list.size() > 0) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "Gongao/saveOrUpdate";
}
gongaoMapper.insertObject(util);
} else {
if (list.size() > 1) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "Gongao/saveOrUpdate";
}
gongaoMapper.updateObject(util);
}
return this.getAllUtil(request, model);
}
}
GxxfbController
package graduation.design.controller;
import java.util.List;
import java.util.ArrayList;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import graduation.design.model.*;
import graduation.design.mapper.*;
import system.common.util.PageModel;
@Controller
@RequestMapping(value = "Gxxfb")
public class GxxfbController {
@Autowired
private GxxfbMapper gxxfbMapper;
@Autowired
private GxxTypeMapper gxxTypeMapper;
@Autowired
private UserMapper userMapper;
@RequestMapping(value = "/initUtil.do")
public String initUtil(HttpServletRequest request, Model model) {
List<GxxType> listGxxType = gxxTypeMapper.getObjectList(null, null);
model.addAttribute("listGxxType", listGxxType);
List<User> listUser = userMapper.getObjectList(null, null);
model.addAttribute("listUser", listUser);
return "Gxxfb/saveOrUpdate";
}
@RequestMapping(value = "/selectUtil.do")
public String selectUtil(HttpServletRequest request, Gxxfb util, Model model) {
util = gxxfbMapper.selectObject(util.getId());
model.addAttribute("util", util);
List<GxxType> listGxxType = gxxTypeMapper.getObjectList(null, null);
model.addAttribute("listGxxType", listGxxType);
List<User> listUser = userMapper.getObjectList(null, null);
model.addAttribute("listUser", listUser);
return "Gxxfb/saveOrUpdate";
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = "/getAllUtil.do")
public String getAllUtil(HttpServletRequest request, Model model) {
String field = request.getParameter("field");
String fieldValue = request.getParameter("fieldValue");
try {
fieldValue = new String(fieldValue.getBytes("UTF-8"), "UTF-8");
} catch (Exception e) {}
String pageNo = request.getParameter("pageModel.currentPageNo");
int currentPageNo = 1;
try{
currentPageNo = Integer.parseInt(pageNo);
}catch(Exception e){
}
List<Gxxfb> list = gxxfbMapper.getObjectList(field, fieldValue);
List<Gxxfb> listGxxfb = new ArrayList<Gxxfb>();
HttpSession session = request.getSession();
int user_id = (Integer) session.getAttribute("user_id");
String user_type = (String) session.getAttribute("user_type");
for (Gxxfb temp : list) {
if (user_id == temp.getUser().getId()) {
listGxxfb.add(temp);
}
}
if (!"admin".equals(user_type)) {
//list = listGxxfb;
}
PageModel pageModel = new PageModel();
pageModel = pageModel.getUtilByController(list, currentPageNo);
model.addAttribute("pageModel", pageModel);
model.addAttribute("fieldValue", fieldValue);
model.addAttribute("field", field);
return "Gxxfb/find";
}
@RequestMapping(value = "/deleteUtil.do")
public String deleteUtil(HttpServletRequest request, Gxxfb util, Model model) {
try{
gxxfbMapper.deleteObject(util.getId());
}catch(Exception e){
}
return this.getAllUtil(request, model);
}
@RequestMapping(value = "/deleteManyUtil.do")
public String deleteManyUtil(HttpServletRequest request, User util,
Model model) {
String ids[] = request.getParameterValues("id");
for (String id : ids) {
util = new User();
util.setId(Integer.parseInt(id));
try{
gxxfbMapper.deleteObject(util.getId());
}catch(Exception e){}
}
return this.getAllUtil(request, model);
}
@RequestMapping(value = "/saveOrUpdateObject.do")
public String saveOrUpdateObject(HttpServletRequest request, Gxxfb util, Model model) {
List<Gxxfb> list = gxxfbMapper.getObjectList("s_0", util.getS_0());
List<GxxType> listGxxType = gxxTypeMapper.getObjectList(null, null);
model.addAttribute("listGxxType", listGxxType);
List<User> listUser = userMapper.getObjectList(null, null);
model.addAttribute("listUser", listUser);
if (0 == util.getId()) {
if (list.size() > 0) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "Gxxfb/saveOrUpdate";
}
gxxfbMapper.insertObject(util);
} else {
if (list.size() > 1) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "Gxxfb/saveOrUpdate";
}
gxxfbMapper.updateObject(util);
}
return this.getAllUtil(request, model);
}
}
ShiwufbglFileController
package graduation.design.controller;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.ArrayList;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import graduation.design.model.*;
import graduation.design.mapper.*;
import system.common.util.PageModel;
@Controller
@RequestMapping(value = "ShiwufbglFile")
public class ShiwufbglFileController {
@Autowired
private ShiwufbglFileMapper shiwufbglFileMapper;
@Autowired
private WupinTypeMapper wupinTypeMapper;
@Autowired
private UserMapper userMapper;
@RequestMapping(value = "/initUtil.do")
public String initUtil(HttpServletRequest request, Model model) {
List<WupinType> listWupinType = wupinTypeMapper.getObjectList(null, null);
model.addAttribute("listWupinType", listWupinType);
List<User> listUser = userMapper.getObjectList(null, null);
model.addAttribute("listUser", listUser);
return "ShiwufbglFile/saveOrUpdate";
}
@RequestMapping(value = "/selectUtil.do")
public String selectUtil(HttpServletRequest request, ShiwufbglFile util, Model model) {
util = shiwufbglFileMapper.selectObject(util.getId());
model.addAttribute("util", util);
List<WupinType> listWupinType = wupinTypeMapper.getObjectList(null, null);
model.addAttribute("listWupinType", listWupinType);
List<User> listUser = userMapper.getObjectList(null, null);
model.addAttribute("listUser", listUser);
return "ShiwufbglFile/saveOrUpdate";
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = "/getAllUtil.do")
public String getAllUtil(HttpServletRequest request, Model model) {
String field = request.getParameter("field");
String fieldValue = request.getParameter("fieldValue");
try {
fieldValue = new String(fieldValue.getBytes("UTF-8"), "UTF-8");
} catch (Exception e) {}
String pageNo = request.getParameter("pageModel.currentPageNo");
int currentPageNo = 1;
try{
currentPageNo = Integer.parseInt(pageNo);
}catch(Exception e){
}
List<ShiwufbglFile> list = shiwufbglFileMapper.getObjectList(field, fieldValue);
List<ShiwufbglFile> listShiwufbglFile = new ArrayList<ShiwufbglFile>();
HttpSession session = request.getSession();
int user_id = (Integer) session.getAttribute("user_id");
String user_type = (String) session.getAttribute("user_type");
for (ShiwufbglFile temp : list) {
if (user_id == temp.getUser().getId()) {
listShiwufbglFile.add(temp);
}
}
if (!"admin".equals(user_type)) {
//list = listShiwufbglFile;
}
PageModel pageModel = new PageModel();
pageModel = pageModel.getUtilByController(list, currentPageNo);
model.addAttribute("pageModel", pageModel);
model.addAttribute("fieldValue", fieldValue);
model.addAttribute("field", field);
return "ShiwufbglFile/find";
}
@RequestMapping(value = "/deleteUtil.do")
public String deleteUtil(HttpServletRequest request, ShiwufbglFile util, Model model) {
try{
shiwufbglFileMapper.deleteObject(util.getId());
}catch(Exception e){
}
return this.getAllUtil(request, model);
}
@RequestMapping(value = "/deleteManyUtil.do")
public String deleteManyUtil(HttpServletRequest request, User util,
Model model) {
String ids[] = request.getParameterValues("id");
for (String id : ids) {
util = new User();
util.setId(Integer.parseInt(id));
try{
shiwufbglFileMapper.deleteObject(util.getId());
}catch(Exception e){}
}
return this.getAllUtil(request, model);
}
@RequestMapping(value = "/saveOrUpdateObject.do")
public String saveOrUpdateObject(HttpServletRequest request, ShiwufbglFile util, Model model) {
List<ShiwufbglFile> list = shiwufbglFileMapper.getObjectList("s_0", util.getS_0());
List<WupinType> listWupinType = wupinTypeMapper.getObjectList(null, null);
model.addAttribute("listWupinType", listWupinType);
List<User> listUser = userMapper.getObjectList(null, null);
model.addAttribute("listUser", listUser);
if (0 == util.getId()) {
if (list.size() > 0) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "ShiwufbglFile/saveOrUpdate";
}
shiwufbglFileMapper.insertObject(util);
} else {
if (list.size() > 1) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "ShiwufbglFile/saveOrUpdate";
}
shiwufbglFileMapper.updateObject(util);
}
return this.getAllUtil(request, model);
}
@RequestMapping(value = "/upload.do")
public String upload(@RequestParam MultipartFile[] myfiles, HttpServletRequest request, ShiwufbglFile util, Model model) throws IOException{
for (MultipartFile file : myfiles) {
if (!file.isEmpty()) {
String fileName = file.getOriginalFilename();
String path = request.getSession().getServletContext()
.getRealPath("upload")
+ File.separator;
String uploadName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
+ fileName;
File localFile = new File(path + uploadName);
file.transferTo(localFile);
util.setS_0(uploadName);
util.setS_1(fileName);
util.setS_2(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}else{
List<ShiwufbglFile> list = shiwufbglFileMapper.getObjectList("s_3", util.getS_3());
List<WupinType> listWupinType = wupinTypeMapper.getObjectList(null, null);
model.addAttribute("listWupinType", listWupinType);
List<User> listUser = userMapper.getObjectList(null, null);
model.addAttribute("listUser", listUser);
if (0 == util.getId()) {
if (list.size() > 0) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "ShiwufbglFile/saveOrUpdate";
}
util.setS_0("None");
util.setS_1("None");
util.setS_2(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
} else {
if (list.size() > 1) {
model.addAttribute("util", util);
model.addAttribute("errMsg", "该信息已存在!");
return "ShiwufbglFile/saveOrUpdate";
}
ShiwufbglFile utilTmp = shiwufbglFileMapper.selectObject(util
.getId());
util.setS_0(utilTmp.getS_0());
util.setS_1(utilTmp.getS_1());
util.setS_2(utilTmp.getS_2());
}
}
if (0 == util.getId()) {
shiwufbglFileMapper.insertObject(util);
} else {
shiwufbglFileMapper.updateObject(util);
}
return "ShiwufbglFile/ok";
}
return "ShiwufbglFile/ok";
}
}
如果也想学习本系统,下面领取。关注并回复:086ssm