package com.bdqn.controller;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.bdqn.pojo.Code;
import com.bdqn.pojo.Paper;
import com.bdqn.pojo.User;
import com.bdqn.service.CodeService;
import com.bdqn.service.PaperService;
@Controller
@RequestMapping("")
public class PaperController {
@Autowired
PaperService paperService;
@Autowired
CodeService codeService;
@RequestMapping("toMain")
public ModelAndView toMain(HttpServletRequest request) {
Object user = request.getSession().getAttribute("user");
ModelAndView mav = new ModelAndView();
if(user==null) {
mav.setViewName("redirect:/toLogin");
}else {
mav.setViewName("main");
}
return mav;
}
@RequestMapping("listPaper")
public ModelAndView listPaper(HttpServletRequest request) {
ModelAndView mav = new ModelAndView();
String title = request.getParameter("title");
String type = request.getParameter("type");
String pageNum = request.getParameter("pageNum");
if(title==null) {
title = "";
}
if(type==null) {
type = "0";
}
if(pageNum==null||"".equals(pageNum)||"-1".equals(pageNum)) {
pageNum = "0";
}
Map<String, Object> result = paperService.list(title,Integer.parseInt(type),Integer.parseInt(pageNum));
List<Code> codeList = codeService.getBy("02");
result.put("pageNum", pageNum);
result.put("title", title);
result.put("type", type);
result.put("typeList", codeList);
mav.addObject("result", result);
mav.setViewName("paperList");
return mav;
}
@RequestMapping(value="/toAdd",method=RequestMethod.GET)
public ModelAndView toAdd() {
ModelAndView mav = new ModelAndView();
List<Code> codeList = codeService.getBy("02");
mav.addObject("codeList", codeList);
mav.setViewName("add");
return mav;
}
@RequestMapping(value="/toUpdate",method=RequestMethod.GET)
public ModelAndView toUpdate(HttpServletRequest request) {
String id = request.getParameter("id");
ModelAndView mav = new ModelAndView();
List<Code> codeList = codeService.getBy("02");
Map<String, Object> result = paperService.get(Integer.parseInt(id));
mav.addObject("codeList", codeList);
mav.addObject("paper",result);
mav.setViewName("update");
return mav;
}
@RequestMapping(value="/deletePaper",method=RequestMethod.GET)
public String deletePaper(HttpServletRequest request) {
String id = request.getParameter("id");
paperService.delete(Integer.parseInt(id));
return "redirect:/listPaper";
}
@ResponseBody
@RequestMapping(value="/hasTitle",method=RequestMethod.GET)
public String hasTitle(HttpServletRequest request) {
String title = request.getParameter("title");
int result = paperService.hasTitle(title);
return result+"";
}
@RequestMapping(value="/add",method=RequestMethod.POST)
public String add(@ModelAttribute Paper paper,@RequestParam("file") MultipartFile file,HttpServletRequest request) {
String filePath = "";
String filename = "";
if(!file.isEmpty()) {
String path = request.getServletContext().getRealPath("/images/");
filename = file.getOriginalFilename();
File filepath = new File(path,filename);
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
try {
filePath = path + File.separator + filename;
file.transferTo(new File(filePath));
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
User user = (User)request.getSession().getAttribute("user");
paper.setCreatedBy(user.getUserName());
paper.setPaperPath(filePath);
paper.setFileName(filename);
paperService.add(paper);
return "redirect:/listPaper";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Spring+SpringMVC+MyBatis项目参考案例(三合一)
共241个文件
jar:82个
xml:38个
java:32个
4星 · 超过85%的资源 需积分: 10 80 下载量 105 浏览量
2018-09-05
09:47:03
上传
评论 5
收藏 36.74MB RAR 举报
温馨提示
包含三个Spring+SpringMVC+MyBatis(SSM)项目整合案例,可供初学者参考。
资源推荐
资源详情
资源评论
收起资源包目录
Spring+SpringMVC+MyBatis项目参考案例(三合一) (241个子文件)
PaperController.class 6KB
QuestionController.class 4KB
User.class 3KB
UserController.class 3KB
User.class 3KB
Code.class 3KB
Paper.class 3KB
UserController.class 2KB
PaperServiceImpl.class 2KB
Code.class 2KB
Paper.class 2KB
QuestionServiceImpl.class 2KB
Question.class 1KB
Answer.class 1KB
UserServiceImpl.class 1KB
AnswerServiceImpl.class 1KB
UserServiceImpl.class 1KB
CodeServiceImpl.class 974B
PaperMapper.class 783B
UserMapper.class 492B
QuestionDao.class 490B
PaperService.class 485B
QuestionService.class 436B
AnswerDao.class 425B
CodeMapper.class 366B
UserService.class 337B
AnswerService.class 330B
UserDao.class 288B
CodeService.class 256B
UserService.class 197B
PaperDao.class 109B
CodeDao.class 107B
.classpath 3KB
.classpath 3KB
.classpath 758B
org.eclipse.wst.common.component 576B
org.eclipse.wst.common.component 556B
org.eclipse.wst.common.component 485B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
druid-1.0.15.jar 1.86MB
aspectjweaver-1.6.9.jar 1.59MB
aspectjweaver-1.6.9.jar 1.59MB
jackson-databind-2.5.4.jar 1.09MB
spring-core-3.2.16.RELEASE.jar 865KB
spring-core-3.2.13.RELEASE.jar 865KB
spring-core-3.2.13.RELEASE.jar 865KB
spring-context-3.2.16.RELEASE.jar 848KB
spring-context-3.2.13.RELEASE.jar 848KB
spring-context-3.2.13.RELEASE.jar 848KB
mysql-connector-java-5.1.6-bin.jar 687KB
mybatis-3.2.2.jar 683KB
mybatis-3.2.2.jar 683KB
mybatis-3.1.1.jar 636KB
spring-webmvc-3.2.16.RELEASE.jar 627KB
spring-webmvc-3.2.13.RELEASE.jar 626KB
spring-webmvc-3.2.13.RELEASE.jar 626KB
spring-web-3.2.13.RELEASE.jar 617KB
spring-web-3.2.13.RELEASE.jar 617KB
spring-web-3.2.16.RELEASE.jar 617KB
spring-beans-3.2.13.RELEASE.jar 600KB
spring-beans-3.2.13.RELEASE.jar 600KB
spring-beans-3.2.16.RELEASE.jar 600KB
mysql-connector-java-5.1.0-bin.jar 553KB
mysql-connector-java-5.1.0-bin.jar 553KB
log4j-1.2.17.jar 478KB
log4j-1.2.17.jar 478KB
spring-test-3.2.16.RELEASE.jar 448KB
fastjson-1.2.7.jar 407KB
jstl-1.2.jar 405KB
spring-jdbc-3.2.16.RELEASE.jar 397KB
spring-jdbc-3.2.13.RELEASE.jar 396KB
spring-jdbc-3.2.13.RELEASE.jar 396KB
com.springsource.org.apache.log4j-1.2.15.jar 387KB
standard.jar 384KB
standard.jar 384KB
fastjson-1.2.13.jar 384KB
fastjson-1.2.13.jar 384KB
spring-aop-3.2.16.RELEASE.jar 331KB
spring-aop-3.2.13.RELEASE.jar 331KB
spring-aop-3.2.13.RELEASE.jar 331KB
junit-4.12.jar 308KB
hamcrest-all-1.3.jar 299KB
spring-tx-3.2.16.RELEASE.jar 237KB
spring-tx-3.2.13.RELEASE.jar 237KB
spring-tx-3.2.13.RELEASE.jar 237KB
jackson-core-2.5.4.jar 225KB
commons-io-2.6.jar 210KB
servlet-api.jar 193KB
servlet-api.jar 193KB
servlet-api.jar 193KB
spring-expression-3.2.16.RELEASE.jar 192KB
spring-expression-3.2.13.RELEASE.jar 192KB
spring-expression-3.2.13.RELEASE.jar 192KB
commons-io-2.4.jar 181KB
commons-io-2.4.jar 181KB
spring-context-support-3.2.13.RELEASE.jar 126KB
spring-context-support-3.2.13.RELEASE.jar 126KB
commons-dbcp.jar 119KB
共 241 条
- 1
- 2
- 3
资源评论
- 汤昵2020-08-07靠谱,参考使用没问题
- semeichenyan2018-10-23靠谱,参考使用没问题
- jun_bai2019-04-09还可以,能够使用,不错的学习资料。
- vivicai5202018-09-12不错的资料
卜老怪
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功