基于javaweb+mysql的ssm+maven大学生创新项目管理系统(java+ssm+bootstrap+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven大学生创新项目管理系统(java+ssm+bootstrap+jsp+mysql)
项目介绍
本项目包含管理员、学生、专家三种角色; 管理员角色包含以下功能: 管理员登录,学院管理,专业管理,班级管理,用户管理,创新计划查看,查看项目申请,项目申请审核等功能。
学生角色包含以下功能: 学生登录,查看创新计划,申请和查看我的项目,创新创业计划书填写等功能。
专家角色包含以下功能: 专家登录,查看创新计划,申请项目,学生项目列表,管理预算记录等功能。
环境需要
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项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jQuery+bootstrap
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/ssm_schoolproject_sys 登录
if (countset.get(project.getXueyuanid()) == null) {
countset.put(project.getXueyuanname(), 1);
} else {
countset.put(project.getXueyuanname(), countset.get(project.getXueyuanname()) + 1);
}
if (project.getTeaid() == null) {
Preuser preuser = preuserService.getPreuserById(project.getUserid());
if (preuser.getType() == 2) {
zcount++;
}
if (preuser.getType() == 3) {
tcount++;
}
} else {
scount++;
}
}
List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(countset.entrySet());
//然后通过比较器来实现排序
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
//升序排序
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
}
});
model.addAttribute("tcount", tcount);
model.addAttribute("zcount", zcount);
model.addAttribute("scount", scount);
try {
model.addAttribute("topname1", list.get(0).getKey());
model.addAttribute("topcount1", list.get(0).getValue());
model.addAttribute("topname2", list.get(1).getKey());
model.addAttribute("topcount2", list.get(1).getValue());
model.addAttribute("topname3", list.get(2).getKey());
model.addAttribute("topcount3", list.get(2).getValue());
}catch (Exception e){
}
return "admin/index";
}
/**
* 后台登录
* @version 1.0
* controller
*/
@Controller
@RequestMapping(value = "/admin/yjslog")
public class AdminYjslogController {
@Resource
private IYjslogService yjslogService;
@Resource
private IProjectService projectService;
@Resource
private IPreuserService preuserService;
/**
* 列表
*/
@RequestMapping(value = "", method = {RequestMethod.GET, RequestMethod.POST})
public String index(HttpServletRequest request, ModelMap model, Yjslog searchParam, Integer page, Integer pageSize) {
PageSearchParam pageSearch = new PageSearchParam();
pageSearch.setPage(page == null ? 1 : page);
pageSearch.setPagesize(pageSize == null ? 20 : pageSize);
pageSearch.setParams(searchParam);
PageResult pageResult = yjslogService.getPages(pageSearch);
model.addAttribute("datas", pageResult);
model.addAttribute("record", searchParam);
model.addAttribute("project", projectService.getProjectById(searchParam.getProjectid()));
return "admin/yjslog/page";
}
//新增
@RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
public String add(HttpServletRequest request, Yjslog record, ModelMap model) {
if ("post".equals(request.getMethod().toLowerCase())) {
record.setCreated(new Date());
String msg = yjslogService.save(record);
if (msg.equals("添加成功")) {
return "redirect:/admin/yjslog";
}
model.addAttribute("msg", msg);
}
if (record.getProjectid() != null) {
record.setProjectname(projectService.getProjectById(record.getProjectid()).getName());
}
model.addAttribute("projects", projectService.all());
if(file!=null){
if (file.getSize() != 0) {
String url = "";
try {
String staticPath =
request.getSession().getServletContext().getRealPath("static/admin/images/");
String fileName = file.getOriginalFilename();
String[] filestr = fileName.split("\\.");
String fileurl = System.currentTimeMillis() + "." + filestr[1];
java.io.File targetFile = new java.io.File(staticPath, fileurl);
file.transferTo(targetFile);
url = "http://localhost:" + request.getLocalPort() +
request.getSession().getServletContext().getContextPath() +
"/static/admin/images/" + fileurl;
} catch (Exception e) {
e.printStackTrace();
}
record.setFileurl(url);
}
}
}
planService.update(record);
return "redirect:/admin/plan";
}
//删除
@RequestMapping(value = "/del")
public String del(HttpServletRequest request,ModelMap model,Integer id) {
Plan plan=planService.getPlanById(id);
planService.delete(id);
return "redirect:/admin/plan";
}
}
// }
//
/**
* 后台首页
*/
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String index(ModelMap model) {
List<Project> all = projectService.all();
int tcount = 0;
int zcount = 0;
int scount = 0;
String topname1 = "";
int topcount1 = 0;
String topname2 = "";
int topcount2 = 0;
String topname3 = "";
int topcount3 = 0;
HashMap<String, Integer> countset = new HashMap<>();
for (Project project : all) {
if (countset.get(project.getXueyuanid()) == null) {
countset.put(project.getXueyuanname(), 1);
} else {
countset.put(project.getXueyuanname(), countset.get(project.getXueyuanname()) + 1);
}
if (project.getTeaid() == null) {
Preuser preuser = preuserService.getPreuserById(project.getUserid());
if (preuser.getType() == 2) {
zcount++;
}
if (preuser.getType() == 3) {
tcount++;
}
} else {
scount++;
}
}
List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(countset.entrySet());
//然后通过比较器来实现排序
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
//升序排序
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2) {
return o1.getValue().compareTo(o2.getValue());
return "admin/project/page";
}
//新增
@RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
public String add(HttpServletRequest request, Project record, ModelMap model) {
if ("post".equals(request.getMethod().toLowerCase())) {
record.setCreated(new Date());
String msg = projectService.save(record);
if (msg.equals("添加成功")) {
return "redirect:/admin/project";
}
model.addAttribute("msg", msg);
}
if (record.getUserid() != null) {
record.setUsername(preuserService.getPreuserById(record.getUserid()).getName());
}
model.addAttribute("users", preuserService.all());
if (record.getPlanid() != null) {
record.setPlanname(planService.getPlanById(record.getPlanid()).getName());
}
model.addAttribute("plans", planService.all());
if (record.getTeaid() != null) {
record.setTeaname(preuserService.getPreuserById(record.getTeaid()).getName());
}
List<Preuser> preusers = preuserService.allByType(2);
preusers.addAll(preuserService.allByType(3));
model.addAttribute("teas", preusers);
model.addAttribute("record", record);
return "admin/project/form";
}
@RequestMapping(value = "/save", method = {RequestMethod.GET, RequestMethod.POST})
public String save(HttpServletRequest request, HttpServletResponse response, Project record) {
request.setAttribute("record", record);
if ("post".equals(request.getMethod().toLowerCase())) {
record.setCreated(new Date());
if (record.getUserid() != null) {
record.setUsername(preuserService.getPreuserById(record.getUserid()).getName());
}
if (record.getPlanid() != null) {
Plan plan = planService.getPlanById(record.getPlanid());
record.setPlanname(plan.getName());
record.setType(plan.getType());
}
if (record.getTeaid() != null) {
record.setTeaname(preuserService.getPreuserById(record.getTeaid()).getName());
}
if (record.getParentid() != null) {
record.setParentname(projectService.getProjectById(record.getParentid()).getName());
}
@RequestMapping(value = "/download")
public ResponseEntity<byte[]> download(HttpServletRequest request, ModelMap model, Integer projectid) throws IOException {
String filePath = projectid + "_" + System.currentTimeMillis();
createdFileOne(request.getSession().getServletContext().getRealPath("files/" + filePath), filePath, request, projectid);
try {
File file = new File(request.getSession().getServletContext().getRealPath("files/" + filePath) + "2");
if (!file.exists()) {
file.mkdir();
}
zip(request.getSession().getServletContext().getRealPath("files/" + filePath), request.getSession().getServletContext().getRealPath("files/" + filePath) + "2/" + filePath + ".zip");
} catch (Exception ex) {
ex.printStackTrace();
}
HttpHeaders headers = new HttpHeaders();
//下载显示的文件名,解决中文名称乱码问题
//通知浏览器以attachment(下载方式)打开图片
headers.setContentDispositionFormData("attachment", filePath + ".zip");
//application/octet-stream : 二进制流数据(最常见的文件下载)。
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
File file = new File(request.getSession().getServletContext().getRealPath("files/" + filePath) + "2/" + filePath + ".zip");
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.CREATED);
}
@RequestMapping(value = "/downloadBatch")
public ResponseEntity<byte[]> downloadBatch(HttpServletRequest request, ModelMap model, String ids) throws IOException {
String filePath2 = System.currentTimeMillis() + "";
String allPath = request.getSession().getServletContext().getRealPath("files/" + filePath2);
File file2 = new File(allPath);
if (!file2.exists()) {
file2.mkdir();
}
for (String id : ids.split(",")) {
try {
Integer projectid = Integer.valueOf(id);
String filePath = projectid + "_" + filePath2;
createdFileOne(allPath + "/" + filePath, filePath, request, projectid);
File file = new File(allPath + "2");
if (!file.exists()) {
file.mkdir();
}
zip(allPath, allPath + "2/" + filePath2 + ".zip");
headers, HttpStatus.CREATED);
}
public static void zip(String inputFileName, String zipFileName) throws Exception {
zip(zipFileName, new File(inputFileName));
}
private static void zip(String zipFileName, File inputFile) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
zip(out, inputFile, "");
out.close();
}
private static void zip(ZipOutputStream out, File f, String base) throws Exception {
if (f.isDirectory()) { // 判断是否为目录
File[] fl = f.listFiles();
out.putNextEntry(new ZipEntry(base + "/"));
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < fl.length; i++) {
zip(out, fl[i], base + fl[i].getName());
}
} else { // 压缩目录中的所有文件
out.putNextEntry(new ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
in.close();
}
}
private void createdFileOne(String dir, String filePath, HttpServletRequest request, Integer projectid) {
Project project = projectService.getProjectById(projectid);
if (project.getType() > 0) {
Highapply record = highapplyService.getHighapplyByProId(projectid);
if (record != null) {
String url = "";
String staticPath =
request.getSession().getServletContext().getRealPath("files/highapply.doc");
String filename = "apply" + filePath + ".doc";
String fileurl = dir + "/" + filename;
createFile(staticPath, fileurl, dir, record.getClass(), record);
}
} else {
Projectapply record = projectapplyService.getProjectapplyByProjectId(projectid);
if (record != null) {
try {
map.put(f.getName(), String.valueOf(f.get(record)));
} catch (Exception e) {
e.printStackTrace();
}
}
HWPFDocument doc = new WriteWord().replaceDoc(staticPath, map);
try {
FileOutputStream out = new FileOutputStream(fileurl);
doc.write(out);
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpHeaders headers = new HttpHeaders();
//下载显示的文件名,解决中文名称乱码问题
//通知浏览器以attachment(下载方式)打开图片
headers.setContentDispositionFormData("attachment", filename);
//application/octet-stream : 二进制流数据(最常见的文件下载)。
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
File file = new File(fileurl);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.CREATED);
}
}
// /**
// * 前台个人中心修改信息
// */
// @RequestMapping(value = "/index/center2")
// public String update(HttpServletRequest request, Preuser record, ModelMap model, @RequestParam("file") MultipartFile file) {
// if (file.getSize() != 0) {
// String url = "";
//
// try {
// String staticPath = request.getSession().getServletContext().getRealPath("static/dist/img/");
// String fileName = file.getOriginalFilename();
// String[] filestr = fileName.split("\\.");
// String fileurl = System.currentTimeMillis() + "." + filestr[1];
// java.io.File targetFile = new java.io.File(staticPath, fileurl);
// file.transferTo(targetFile);
// url = "http://localhost:" + request.getLocalPort() + request.getSession().getServletContext().getContextPath() + "/static/dist/img/" + fileurl;
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// record.setPicurl(url);
// }
// preuserservice.update(record);
// request.getSession().setAttribute("indexUser",record);
// return "redirect:/index/center";
// }
//
/**
* 后台首页
*/
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String index(ModelMap model) {
List<Project> all = projectService.all();
int tcount = 0;
int zcount = 0;
int scount = 0;
String topname1 = "";
int topcount1 = 0;
String topname2 = "";
/**
* <br>
* ========================== <br>
* 开发:952396697@qq.com <br>
* 版本:1.0 <br>
* ==========================
*/
@Controller
public class IndexController {
@Resource
private IPreuserService preuserService;
@Resource
private IProjectService projectService;
//@Resource
// private IPreuserService preuserservice;
// @Resource
//private ICateService cateService;
//@Resource
// private IKechengService kechengService;
/**
*
*/
@RequestMapping(value = "/demo", method = RequestMethod.GET)
public String demo(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "admin/demo";
}
/**
* 前台首页
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String preindex(ModelMap model) {
// return "pre/login";//必须登录
// model.addAttribute("cates",cateService.all());//分类
// PageSearchParam psp = new PageSearchParam();
// psp.setPage(1);
// psp.setPagesize(9);
@RequestMapping(value = "/login")
public String login(HttpServletRequest request, HttpServletResponse response) {
String username = request.getParameter("u");
String psw = request.getParameter("p");
String v = request.getParameter("v");
Preuser u = preuserService.login(username, psw);
if (null == u) {
if (request.getMethod().equals("POST")) {
request.setAttribute("msg", "账号或密码错误");
}
return "admin/login";
}else{
if(v!=null&&!v.equals( request.getSession().getAttribute(VALIDATE_CODE))){
request.setAttribute("msg", "验证码错误");
return "admin/login";
}if(StringUtils.isEmpty(v)){
request.setAttribute("msg", "验证码不能为空");
return "admin/login";
}
}
request.getSession().setAttribute("loginUser", u);
return "redirect:/admin";
}
@Autowired
private Producer captchaProducer;
private final String VALIDATE_CODE = "VALIDATE_CODE";
private final String EXPIRE_TIME = "EXPIRE_TIME";
@RequestMapping(value = "/login/vcode", method = RequestMethod.GET)
public void loadValidateCode(HttpServletRequest request, HttpServletResponse response) {
try {
HttpSession session = request.getSession();
// 设置清除浏览器缓存
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/png");
}
HttpHeaders headers = new HttpHeaders();
//下载显示的文件名,解决中文名称乱码问题
//通知浏览器以attachment(下载方式)打开图片
headers.setContentDispositionFormData("attachment", filePath2 + ".zip");
//application/octet-stream : 二进制流数据(最常见的文件下载)。
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
File file = new File(allPath + "2/" + filePath2 + ".zip");
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),
headers, HttpStatus.CREATED);
}
public static void zip(String inputFileName, String zipFileName) throws Exception {
zip(zipFileName, new File(inputFileName));
}
private static void zip(String zipFileName, File inputFile) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
zip(out, inputFile, "");
out.close();
}
private static void zip(ZipOutputStream out, File f, String base) throws Exception {
if (f.isDirectory()) { // 判断是否为目录
File[] fl = f.listFiles();
out.putNextEntry(new ZipEntry(base + "/"));
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < fl.length; i++) {
zip(out, fl[i], base + fl[i].getName());
}
} else { // 压缩目录中的所有文件
out.putNextEntry(new ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
in.close();
}
}
private void createdFileOne(String dir, String filePath, HttpServletRequest request, Integer projectid) {
Project project = projectService.getProjectById(projectid);
if (project.getType() > 0) {
Highapply record = highapplyService.getHighapplyByProId(projectid);
if (record != null) {
if (preuser.getType() == 4) {
return "redirect:/admin/project?preuserid=" + preuser.getId();
}
return "redirect:/admin/project";
}
request.setAttribute("msg", msg);
}
return "admin/project/form";
}
//查看
@RequestMapping(value = "/view")
public String view(HttpServletRequest request, ModelMap model, Integer id) {
Project record = projectService.getProjectById(id);
model.addAttribute("record", record);
model.addAttribute("edit", false);
model.addAttribute("users", preuserService.all());
model.addAttribute("plans", planService.all());
List<Preuser> preusers = preuserService.allByType(2);
preusers.addAll(preuserService.allByType(3));
model.addAttribute("teas", preusers);
if (record.getType() == 0) {
model.addAttribute("apply", projectapplyService.getProjectapplyByProjectId(id));
} else {
model.addAttribute("apply", highapplyService.getHighapplyByProId(id));
}
model.addAttribute("midapply", midapplyService.getMidapplyByProId(id));
model.addAttribute("endapply", endapplyService.getEndapplyByProId(id));
model.addAttribute("changelog", changelogService.getChangelogByProId(id));
model.addAttribute("plan", planService.getPlanById(record.getPlanid()));
model.addAttribute("report", reportService.getReportByProId(id));
model.addAttribute("now", new Date());
return "admin/project/form";
}
//编辑
@RequestMapping(value = "/edit")
}
return "admin/comment/form";
}
//查看
@RequestMapping(value = "/view")
public String view(HttpServletRequest request, ModelMap model, Integer id) {
Comment record = commentService.getCommentById(id);
model.addAttribute("record", record);
model.addAttribute("edit", false);
model.addAttribute("projects", projectService.all());
model.addAttribute("users", preuserService.all());
return "admin/comment/form";
}
//编辑
@RequestMapping(value = "/edit")
public String edit(HttpServletRequest request, ModelMap model, Integer id) {
Comment record = commentService.getCommentById(id);
model.addAttribute("record", record);
model.addAttribute("edit", true);
model.addAttribute("projects", projectService.all());
model.addAttribute("users", preuserService.all());
return "admin/comment/form";
}
//更新
@RequestMapping(value = "/update", method = {RequestMethod.GET, RequestMethod.POST})
public String update(HttpServletRequest request, Comment record, ModelMap model) {
if ("post".equals(request.getMethod().toLowerCase())) {
}
if (record.getProjectid() != null) {
record.setProjectname(projectService.getProjectById(record.getProjectid()).getName());
}
if (record.getPreuserid() != null) {
record.setPreusername(preuserService.getPreuserById(record.getPreuserid()).getName());
}
commentService.update(record);
return "redirect:/admin/comment";
}
//删除
@RequestMapping(value = "/del")
public String del(HttpServletRequest request, ModelMap model, Integer id) {
private IPreuserService preuserService;
/**
* 列表
*/
@RequestMapping(value = "", method = {RequestMethod.GET, RequestMethod.POST})
public String index(HttpServletRequest request, ModelMap model, Highapply searchParam, Integer page, Integer pageSize) {
PageSearchParam pageSearch = new PageSearchParam();
pageSearch.setPage(page == null ? 1 : page);
pageSearch.setPagesize(pageSize == null ? 20 : pageSize);
pageSearch.setParams(searchParam);
PageResult pageResult = highapplyService.getPages(pageSearch);
model.addAttribute("datas", pageResult);
model.addAttribute("record", searchParam);
return "admin/highapply/page";
}
//新增
@RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
public String add(HttpServletRequest request, Highapply record, ModelMap model) {
if ("post".equals(request.getMethod().toLowerCase())) {
String msg = highapplyService.save(record);
if (msg.equals("添加成功")) {
return "redirect:/admin/highapply";
}
model.addAttribute("msg", msg);
}
if (record.getProjectid() != null) {
Project project = projectService.getProjectById(record.getProjectid());
record.setProjectname(project.getName());
record.setProtype(project.getType() + "");
record.setProlevel(project.getType() + "");
record.setPreusername(project.getUsername());
}
model.addAttribute("projects", projectService.all());
if (record.getPreuserid() != null) {
record.setPreusername(preuserService.getPreuserById(record.getPreuserid()).getName());
}
model.addAttribute("preusers", preuserService.all());
model.addAttribute("record", record);
return "admin/highapply/form";
}
@RequestMapping(value = "/save", method = {RequestMethod.GET, RequestMethod.POST})
public String save(HttpServletRequest request, HttpServletResponse response, Highapply record, int status) {
request.setAttribute("record", record);
if ("post".equals(request.getMethod().toLowerCase())) {
}
model.addAttribute("preusers", preuserService.all());
model.addAttribute("record", record);
return "admin/projectapply/form";
}
@RequestMapping(value = "/save", method = {RequestMethod.GET, RequestMethod.POST})
public String save(HttpServletRequest request, HttpServletResponse response, Projectapply record) {
request.setAttribute("record", record);
if ("post".equals(request.getMethod().toLowerCase())) {
Project projectById = projectService.getProjectById(record.getProjectid());
if (record.getProjectid() != null) {
record.setProjectname(projectById.getName());
}
if (record.getPreuserid() != null) {
record.setPreusername(preuserService.getPreuserById(record.getPreuserid()).getName());
}
if (record.getStatus() == 1) {
projectById.setProcess(1);
projectById.setStatus(1);
if (projectById.getTeaid() == null) {
projectById.setStatus(2);
}
projectService.update(projectById);
}
String msg = projectapplyService.save(record);
if (msg.equals("添加成功")) {
return "redirect:/admin/project";
}
request.setAttribute("msg", msg);
}
return "admin/projectapply/form";
}
//查看
@RequestMapping(value = "/view")
public String view(HttpServletRequest request, ModelMap model, Integer id) {
Projectapply record = projectapplyService.getProjectapplyById(id);
model.addAttribute("record", record);
model.addAttribute("edit", false);
model.addAttribute("projects", projectService.all());
model.addAttribute("preusers", preuserService.all());
return "admin/projectapply/form";
}
//新增
@RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
public String add(HttpServletRequest request, Project record, ModelMap model) {
if ("post".equals(request.getMethod().toLowerCase())) {
record.setCreated(new Date());
String msg = projectService.save(record);
if (msg.equals("添加成功")) {
return "redirect:/admin/project";
}
model.addAttribute("msg", msg);
}
if (record.getUserid() != null) {
record.setUsername(preuserService.getPreuserById(record.getUserid()).getName());
}
model.addAttribute("users", preuserService.all());
if (record.getPlanid() != null) {
record.setPlanname(planService.getPlanById(record.getPlanid()).getName());
}
model.addAttribute("plans", planService.all());
if (record.getTeaid() != null) {
record.setTeaname(preuserService.getPreuserById(record.getTeaid()).getName());
}
List<Preuser> preusers = preuserService.allByType(2);
preusers.addAll(preuserService.allByType(3));
model.addAttribute("teas", preusers);
model.addAttribute("record", record);
return "admin/project/form";
}
@RequestMapping(value = "/save", method = {RequestMethod.GET, RequestMethod.POST})
public String save(HttpServletRequest request, HttpServletResponse response, Project record) {
request.setAttribute("record", record);
if ("post".equals(request.getMethod().toLowerCase())) {
record.setCreated(new Date());
if (record.getUserid() != null) {
record.setUsername(preuserService.getPreuserById(record.getUserid()).getName());
}
if (record.getPlanid() != null) {
Plan plan = planService.getPlanById(record.getPlanid());
record.setPlanname(plan.getName());
record.setType(plan.getType());
}
if (record.getTeaid() != null) {
record.setTeaname(preuserService.getPreuserById(record.getTeaid()).getName());
}
if (record.getParentid() != null) {
record.setParentname(projectService.getProjectById(record.getParentid()).getName());
}
Preuser preuser = (Preuser) request.getSession().getAttribute("loginUser");
if (preuser != null) {
record.setUserid(preuser.getId());