package cn.pss.action;
import java.io.File;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;
import cn.pss.service.UserService;
import cn.pss.vo.User;
@Controller
@RequestMapping("/user")
// requestMapping(value="")中value可以直接省略不写
public class UserAction {
@Resource
private UserService userservice;
//采用外部重定向进行页面跳转,也就是说执行一次返回的方法名称
private final String LIST="redirect:/user/list";
// modelAttribute("user") 表示直接获取到的属性放到session中 页面通过${user.username}取得
@RequestMapping("/login")
public ModelAndView login(@ModelAttribute("user") User user,
HttpSession session) {
User name = userservice.login(user);
if (name != null) {
// session.setAttribute("user", name);
List<User> listUser = userservice.findAll();
return new ModelAndView("user/list", "listUser", listUser);
} else {
return new ModelAndView("error");
}
}
@RequestMapping("/list")
public ModelAndView list(){
List<User> listUser = userservice.findAll();
if(listUser!=null){
return new ModelAndView("user/list", "listUser", listUser);
} else {
return new ModelAndView("error");
}
}
// method代表请求方式
@RequestMapping("/add")
public ModelAndView add() {
return new ModelAndView("user/add");
}
@RequestMapping("/insert")
public ModelAndView insert(@Validated User user) {
userservice.insert(user);
return new ModelAndView(LIST);
}
@RequestMapping("/delete/{uname}")
public ModelAndView delete(@PathVariable String uname) {
userservice.delete(uname);
return new ModelAndView(LIST);
}
@RequestMapping("/edit/{uname}")
public ModelAndView edit(@PathVariable String uname) {
User user = userservice.findByid(uname);
return new ModelAndView("user/update", "user", user);
}
@RequestMapping("/update")
public ModelAndView update(@Validated User user) {
userservice.update(user);
return new ModelAndView(LIST);
}
@RequestMapping(value = "/upload")
// 将文件上传请求映射到该方法
// 设置请求参数的名称和类型
public ModelAndView upload(@RequestParam("file") CommonsMultipartFile mFile) { // 请求参数一定要与form中的参数名对应
if (!mFile.isEmpty()) {
// 获取本地存储路径
File file = new File("D:/myfile");
if (!file.exists())
file.mkdirs();
File file1 = new File("d:/myfile/" + new Date().getTime() + ".xls"); // 新建一个文件
try {
mFile.getFileItem().write(file1); // 将上传的文件写入新建的文件中
//mFile.transferTo(file1); // 将上传的文件写入新建的文件中
} catch (Exception e) {
e.printStackTrace();
}
}
return new ModelAndView("upload");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SpringMVC1.rar (94个子文件)
SpringMVC1
.project 1KB
.springBeans 462B
.mymetadata 303B
src
sqlMap
User.xml 2KB
sqlmap-config.xml 263B
cn
pss
service
impl
UserServiceImpl.java 869B
UserService.java 320B
action
UserAction.java 3KB
dao
impl
UserDAOImpl.java 1KB
UserDAO.java 312B
vo
User.java 584B
applicationContext.xml 4KB
log4j.properties 1KB
WebRoot
WEB-INF
spring-form.tld 69KB
pages
user
fileupload.jsp 1KB
add.jsp 1KB
update.jsp 1KB
list.jsp 1KB
spring.tld 17KB
classes
sqlMap
User.xml 2KB
sqlmap-config.xml 263B
cn
pss
service
UserService.class 424B
impl
UserServiceImpl.class 1KB
action
UserAction.class 4KB
dao
UserDAO.class 412B
impl
UserDAOImpl.class 2KB
vo
User.class 1KB
applicationContext.xml 4KB
log4j.properties 1KB
lib
org.springframework.instrument-3.1.1.RELEASE.jar 7KB
org.springframework.expression-3.0.1.RELEASE-A.jar 152KB
org.springframework.binding-2.0.8.RELEASE.jar 154KB
org.springframework.instrument.tomcat-3.0.1.RELEASE-A.jar 5KB
org.springframework.core-3.0.1.RELEASE-A.jar 347KB
org.springframework.web.servlet-3.1.1.RELEASE.jar 560KB
org.springframework.web-3.1.1.RELEASE.jar 532KB
org.springframework.oxm-3.1.1.RELEASE.jar 71KB
jotm.jar 121KB
org.springframework.jms-3.0.1.RELEASE-A.jar 179KB
org.springframework.aop-3.0.1.RELEASE-A.jar 313KB
org.springframework.beans-3.1.1.RELEASE.jar 576KB
org.springframework.web-3.0.1.RELEASE-A.jar 352KB
org.springframework.test-3.1.1.RELEASE.jar 224KB
jstl-1.2.jar 405KB
com.springsource.org.apache.commons.pool-1.5.3.jar 95KB
org.springframework.expression-3.1.1.RELEASE.jar 172KB
persistence.jar 69KB
com.springsource.org.apache.commons.httpclient-3.1.0.jar 301KB
org.springframework.beans-3.0.1.RELEASE-A.jar 535KB
org.springframework.context-3.0.1.RELEASE-A.jar 642KB
ognl-2.6.9.jar 166KB
org.springframework.aspects-3.0.1.RELEASE-A.jar 29KB
org.springframework.jdbc-3.1.1.RELEASE.jar 395KB
org.springframework.webflow-2.0.8.RELEASE.jar 507KB
com.springsource.org.codehaus.jackson.mapper-1.0.0.jar 264KB
org.springframework.web.struts-3.0.1.RELEASE-A.jar 524KB
org.springframework.transaction-3.0.1.RELEASE-A.jar 223KB
com.springsource.org.apache.commons.lang-2.4.0.jar 258KB
org.springframework.context.support-3.1.1.RELEASE.jar 105KB
commons-dbcp.jar 119KB
org.springframework.asm-3.0.1.RELEASE-A.jar 52KB
org.springframework.asm-3.1.1.RELEASE.jar 52KB
org.springframework.web.servlet-3.0.1.RELEASE-A.jar 389KB
xapool.jar 90KB
org.springframework.jdbc-3.0.1.RELEASE-A.jar 369KB
org.springframework.orm-3.0.1.RELEASE-A.jar 324KB
com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar 603KB
org.springframework.aspects-3.1.1.RELEASE.jar 49KB
org.springframework.instrument-3.0.1.RELEASE-A.jar 2KB
org.springframework.context-3.1.1.RELEASE.jar 812KB
org.springframework.web.portlet-3.0.1.RELEASE-A.jar 169KB
org.springframework.jms-3.1.1.RELEASE.jar 195KB
com.springsource.org.aopalliance-1.0.0.jar 5KB
com.springsource.org.apache.commons.fileupload-1.2.0.jar 53KB
org.springframework.js-2.0.8.RELEASE.jar 1.15MB
com.springsource.net.sf.cglib-2.2.0.jar 319KB
org.springframework.aop-3.1.1.RELEASE.jar 324KB
org.springframework.transaction-3.1.1.RELEASE.jar 241KB
org.springframework.orm-3.1.1.RELEASE.jar 370KB
com.springsource.org.apache.commons.logging-1.1.1.jar 60KB
org.springframework.instrument.tomcat-3.1.1.RELEASE.jar 11KB
com.springsource.org.apache.log4j-1.2.15.jar 387KB
mysql-connector-java-5.1.12-bin.jar 716KB
com.springsource.com.ibatis-2.3.4.726.jar 377KB
org.springframework.core-3.1.1.RELEASE.jar 439KB
org.springframework.web.portlet-3.1.1.RELEASE.jar 186KB
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar 1.57MB
org.springframework.oxm-3.0.1.RELEASE-A.jar 56KB
web.xml 2KB
index.jsp 1KB
img
tt70.jpg 60KB
META-INF
MANIFEST.MF 36B
.myeclipse
.settings
org.eclipse.jdt.core.prefs 330B
.classpath 4KB
共 94 条
- 1
微笑而学
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
- 基于matlab+DWT的图像水印项目,数字水印+源代码+文档说明+图片+报告pdf
- (优秀毕业设计)基于python实现的数字图像可视化水印系统的设计与实现,多种数字算法实现+源代码+文档说明+理论演示pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页