基于javaweb的SSH校园失物招领平台(java+spring+springmvc+hibernate+mysql+jsp)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

052023412309

072023412309

082023412309

092023412309

102023412309

112023412309

122023412309

132023412309

142023412309

152023412309

基于javaweb的SSH校园失物招领平台(java+spring+springmvc+hibernate+mysql+jsp)

Spring MVC 框架(Spring + Spring MVC + Hibernate)+ MYSQL

管理员:
admin 123456

用户:
user1 123456
user2 123456
user3 123456

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36




/**
* 图片验证码 (并把图像验证码设置在Session域中,Key=code)
*/
@Controller
public class ImageCodeController {

public static final int WIDTH = 120;// 生成的图片的宽度
public static final int HEIGHT = 30;// 生成的图片的高度

@RequestMapping(value = "/code.do")
public void getCode(HttpServletRequest request, HttpServletResponse response)
throws IOException {
String createTypeFlag = request.getParameter("createTypeFlag");// 接收客户端传递的createTypeFlag标识
// 1.在内存中创建一张图片
BufferedImage bi = new BufferedImage(WIDTH, HEIGHT,
BufferedImage.TYPE_INT_RGB);
// 2.得到图片
Graphics g = bi.getGraphics();
// 3.设置图片的背影色
setBackGround(g);
// 4.设置图片的边框
setBorder(g);
// 5.在图片上画干扰线
drawRandomLine(g);
// 6.写在图片上随机数
// String random = drawRandomNum((Graphics2D) g,"ch");//生成中文验证码图片
// String random = drawRandomNum((Graphics2D) g,"nl");//生成数字和字母组合的验证码图片
// String random = drawRandomNum((Graphics2D) g,"n");//生成纯数字的验证码图片
// String random = drawRandomNum((Graphics2D) g,"l");//生成纯字母的验证码图片
String random = drawRandomNum((Graphics2D) g, createTypeFlag);// 根据客户端传递的createTypeFlag标识生成验证码图片
// 7.将随机数存在session中
request.getSession().setAttribute(Constants.CODE, random);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

@Controller
@RequestMapping(value = "/user")
public class UserController extends BaseController{

@Autowired
@Qualifier("userService")
private IUserService userService;

@Autowired
@Qualifier("pickThingsService")
private IPickThingsService pickThingsService;

@Autowired
@Qualifier("lostThingsService")
private ILostThingsService lostThingsService;

@Autowired
@Qualifier("expressThanksService")
private IExpressThanksService expressThanksService;

// 用户中心
@SystemControllerLog(description = "进入用户中心")
@RequestMapping(value = { "/user-center.html" })
public String userCenter(Model model) {

return "user/user-center";
}

// 获取默认视图
@RequestMapping(value = { "/default.html" })
public String defaultView() {

return "user/default";
}

// 获取用户信息视图
@RequestMapping(value = { "/user-info.do" }, method =RequestMethod.POST)
public String userInfoView() {

return "user/user-info";
}

// 查询用户信息
@RequestMapping(value = { "/user-query.do" }, method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Controller层切点  
@Pointcut("@annotation(com.lin.lostandfound.annotation.SystemControllerLog)")
public void controllerAspect() {
}

/**
* 前置通知 用于拦截Controller层记录用户的操作
*
* @param joinPoint 切点
*/
@Before("controllerAspect()")
public void doBefore(JoinPoint joinPoint) {

HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = request.getSession();
//读取session中的用户
User user = (User) session.getAttribute(Constants.USER);
//请求的IP
String ip = UserAgentParserUtil.getRemoteHost(request);
try {
//*========控制台输出=========*//
System.out.println("=====前置通知开始=====");
System.out.println("请求方法:" + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
System.out.println("方法描述:" + getControllerMethodDescription(joinPoint));
System.out.println("请求人:" + (user == null ? null : user.getUserName()));
System.out.println("请求IP:" + ip);
//*========数据库日志=========*//
SystemLog systemLog = new SystemLog();
systemLog.setDescription(getControllerMethodDescription(joinPoint));
systemLog.setMethod((joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()"));
systemLog.setType("0");
systemLog.setRequestIp(ip);
systemLog.setExceptionCode(null);
systemLog.setExceptionDetail(null);
systemLog.setParams(null);
systemLog.setCreateBy(user == null ? null : user.getUserName());
systemLog.setCreateDate(new Date());
//保存数据库
systemLogService.add(systemLog);
System.out.println("=====前置通知结束=====");
} catch (Exception e) {
e.printStackTrace();
//记录本地异常日志
logger.error("==前置通知异常==");
logger.error("异常信息:{}", e.getMessage());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	
model.addAttribute("notices", notices);

return "index";
}

// 搜索List
//此处为记录AOP拦截Controller记录操作
@SystemControllerLog(description = "搜索")
@RequestMapping(value = { "/search-list.html" })
public String searchAll(Map<String, Object> map, Model model,String keywords) {
System.out.println("search-list..." +keywords);

List<PickThings> searchPickThingsList = pickThingsService.queryAllByKeywords(keywords, 1, Constants.PAGE_SIZE_15, true);
List<LostThings> searchLostThingsList = lostThingsService.queryAllByKeywords(keywords, 1, Constants.PAGE_SIZE_15, true);
int totalPick = (int) pickThingsService.queryAllByKeywordsCount(keywords);
int totalLost = (int) lostThingsService.queryAllByKeywordsCount(keywords);

model.addAttribute("keywords", keywords);
this.initPickPage(map, 1, Constants.PAGE_SIZE_15, totalPick);
this.initLostPage(map, 1, Constants.PAGE_SIZE_15, totalLost);
super.initResult(model, "searchPickThingsList", searchPickThingsList, map);
super.initResult(model, "searchLostThingsList", searchLostThingsList, map);

return "search-list";
}

// 搜索AllList(分页)
@RequestMapping(value = { "/search-list.html/{pageNo}/{pageSize}/{page}"})
public String searchAllList(@PathVariable String pageNo,
@PathVariable String pageSize, @PathVariable String page, String keywords, Map<String,
Object> map, Model model) {
System.out.println("search-list...AllList" +keywords + pageNo + " " + pageSize + " "+ page);

List<PickThings> searchPickThingsList = pickThingsService.queryAllByKeywords(keywords, 1, Constants.PAGE_SIZE_15, true);
List<LostThings> searchLostThingsList = lostThingsService.queryAllByKeywords(keywords, 1, Constants.PAGE_SIZE_15, true);

int totalPick = (int) pickThingsService.queryAllByKeywordsCount(keywords);
int totalLost = (int) lostThingsService.queryAllByKeywordsCount(keywords);

int currentPage = 1;
int pSize = Constants.PAGE_SIZE_15;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
	Integer totalPage = (totalCount + pageSize - 1) / pageSize;
if (null == pageNum) {
pageNum = 1;
} else if (pageNum > totalPage) {
pageNum = totalPage;
}
map.put("pickstartIndex", PagerTag.getStartIndex(pageNum, pageSize));
map.put("pickpageNum", pageNum);
map.put("picktotalPage", totalPage);
map.put("pickpageSize", pageSize);
map.put("picktotalCount", totalCount);
}

// 初始化分页相关信息
private void initLostPage(Map<String, Object> map, Integer pageNum, Integer pageSize, Integer totalCount) {
if (null == pageSize || pageSize.equals("")) {
pageSize = Constants.PAGE_SIZE_15;
}
if (pageSize > 50) {
pageSize = 50;
}
Integer totalPage = (totalCount + pageSize - 1) / pageSize;
if (null == pageNum) {
pageNum = 1;
} else if (pageNum > totalPage) {
pageNum = totalPage;
}
map.put("loststartIndex", PagerTag.getStartIndex(pageNum, pageSize));
map.put("lostpageNum", pageNum);
map.put("losttotalPage", totalPage);
map.put("lostpageSize", pageSize);
map.put("losttotalCount", totalCount);
}

// 获取leave-thanks视图
@RequestMapping(value = {"/leave-thanks.html"}, method = RequestMethod.GET)
public String thanksView() {
System.out.println("leave-thanks.html...GET");

return "leave-thanks";
}

// thanks列表
@RequestMapping(value = {"/thanks.do"}, method = RequestMethod.POST)
public @ResponseBody String thanks(Integer pageIndex, Integer pageSize) {
System.out.println("thanks.do...POST" + pageIndex + " " +pageSize);
Map<String, Object> jsonMap = expressThanksService.queryAll(null, pageIndex, pageSize, "id", "desc");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

if (!lostThingsService.add(lostThings)) {
request.setAttribute("lostThings", lostThings);
request.setAttribute("saveErr", "发帖失败!");

return "user/lost-publish";
}

return "user/user-center";
}

// 快速下一贴
@SystemControllerLog(description = "快速查看寻物信息下一贴")
@RequestMapping(value = { "/lost-details.html/next/{id}" }, method = RequestMethod.POST)
public @ResponseBody List<LostThings> next(@PathVariable String id, Model model) {
System.out.println("next.html..." +id);
LostThings lostThings = lostThingsService.queryOneRecord(Long.parseLong(id), true);
List<LostThings> list = new ArrayList<LostThings>();
list.add(lostThings);

return list;
}

// 快速上一贴
@SystemControllerLog(description = "快速查看寻物信息上一贴")
@RequestMapping(value = { "/lost-details.html/previous/{id}"}, method = RequestMethod.POST)
public @ResponseBody List<LostThings> previous(@PathVariable String id, Model model){
System.out.println("previous.html..." +id);
LostThings lostThings = lostThingsService.queryOneRecord(Long.parseLong(id), false);
List<LostThings> list = new ArrayList<LostThings>();
list.add(lostThings);

return list;
}

}


项目链接:
https://javayms.github.io?id=052023412309201fe
https://javayms.pages.dev?id=052023412309201fe