课题设计仅供参考学习使用,可以在此基础上进行扩展完善
开发环境:
代码已经上传github,下载地址:https://github.com/21503882/network-flower
Eclipse ,MYSQL,JDK1.8,Tomcat 7
涉及技术点:
MVC模式、SpringMvc、Mybatis、Spring、bootstrap、HTML、JavaScript、CSS、JQUERY、log4j、Ajax、maven等
系统采用Mybatis框架实现ORM对象关系映射,前台JSP实现,后台springMvc映射,使用Spring框架进行整合。适合学习J2EE的一段时间的熟手,代码思路清晰,注解详细,数据库用的是mysql5.1,服务器用的tomcat7,JDK版本1.8. 编程软件Eclispe J2EE版本。是典型MVC架构,并且前后台分离
package com.way.controller;
import com.alibaba.fastjson.JSON;
import com.way.domain.AdminEntity;
import com.way.domain.LostEntity;
import com.way.domain.StudentEntity;
import com.way.service.BgLostService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@Controller
@RequestMapping("/lost")
public class BgLostController {
int i=0;
@Autowired
private BgLostService bgLostService;
public void setBgLostService(BgLostService bgLostService) {
this.bgLostService = bgLostService;
}
// --------------------------------------------------------------------
// 添加信息,
@RequestMapping("/addLost")
@ResponseBody
public String addLost(LostEntity lostEntity,@RequestParam("limage") MultipartFile myfile, HttpServletRequest request){
String filename=myfile.getOriginalFilename();
lostEntity.setLimage("images/"+filename);
String path2=request.getServletContext().getRealPath("background//images");
File destFile=new File(path2+File.separator+filename);
try {
InputStream in=myfile.getInputStream();
FileUtils.copyInputStreamToFile(in,destFile);
} catch (IOException e) {
e.printStackTrace();
}
if (request.getSession().getAttribute("CURRENT_SESSION_KEY") instanceof AdminEntity){
AdminEntity adminEntity =(AdminEntity) request.getSession().getAttribute("CURRENT_SESSION_KEY");
lostEntity.setAid(adminEntity.getAid());
}else{
StudentEntity studentEntity=(StudentEntity)request.getSession().getAttribute("CURRENT_SESSION_KEY");
lostEntity.setSid(studentEntity.getSid());
}
if (bgLostService.addLost(lostEntity)){
i=1;
return JSON.toJSONString(i);
}
i=2;
return JSON.toJSONString(i);
}
// 分页以及查询
@RequestMapping("/listLost")
@ResponseBody
public String listLost(int currentpage, LostEntity lostEntity){
List<LostEntity>list=bgLostService.list(currentpage,lostEntity);
return JSON.toJSONString(list);
}
// 我发布的
@RequestMapping("/listMine")
@ResponseBody
public String listMine(LostEntity lostEntity, HttpServletRequest request){
if (request.getSession().getAttribute("CURRENT_SESSION_KEY") instanceof AdminEntity){
AdminEntity adminEntity =(AdminEntity) request.getSession().getAttribute("CURRENT_SESSION_KEY");
lostEntity.setAid(adminEntity.getAid());
}else{
StudentEntity studentEntity=(StudentEntity)request.getSession().getAttribute("CURRENT_SESSION_KEY");
lostEntity.setSid(studentEntity.getSid());
}
List<LostEntity>list=bgLostService.listMine(lostEntity);
return JSON.toJSONString(list);
}
// 改变状态
@RequestMapping("/changeLstatus")
@ResponseBody
public String changeLstatus(LostEntity lostEntity){
if(bgLostService.changeLstatus(lostEntity)){
i=1;
return JSON.toJSONString(i);
}
i=2;
return JSON.toJSONString(i);
}
}
代码已经上传github,下载地址:https://github.com/21503882/network-flower