package cn.itcast.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import cn.itcast.model.User;
import cn.itcast.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value="/add")
public String add(){
return "add";
}
/*
* @PathVariable:从restful风格的路径中获取参数
*/
@RequestMapping(value="/modify/{userid}")
public ModelAndView modify(@PathVariable("userid")Integer id){
ModelAndView modelAndView = new ModelAndView();
User user = userService.findById(id);
modelAndView.addObject("user", user);
modelAndView.setViewName("modify");
return modelAndView;
}
/*
* *@ModelAttribute("userForm1"):该注解在此处好像没有体现作用,该注解的参数为前台form表单的id
*/
@RequestMapping(value="/save",method=RequestMethod.POST)
public String save(/*@ModelAttribute("userForm1")*/User user){
int i = userService.save(user);
if(i == 1){
return "redirect:/user/list";
}
return "add";
}
@RequestMapping(value="/update",method=RequestMethod.POST)
public String update(User user){
int i = userService.update(user);
if(i == 1){
return "redirect:/user/list";
}
return "modify";
}
@RequestMapping(value="/delete/{userid}")
public String delete(@PathVariable("userid")Integer id){
userService.delete(id);
return "redirect:/user/list";
}
@RequestMapping(value="/list")
public ModelAndView list(){
ModelAndView modelAndView = new ModelAndView();
List<User> users = userService.findAll();
modelAndView.addObject("users", users);
modelAndView.setViewName("list");
return modelAndView;
}
//TODO 用户数据的分页、springmvc数据类型转化、springmvc数据验证、springmvc返回json数据、导入、导出
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
springmvc_annotation.zip (47个子文件)
springmvc_annotation
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 330B
src
jdbc.properties 174B
cn
itcast
dao
UserDao.java 2KB
model
User.java 1KB
controller
UserController.java 2KB
service
UserService.java 666B
springmvc-servlet.xml 1KB
applicationContext.xml 2KB
.project 1KB
WebRoot
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 2KB
view
list.jsp 2KB
modify.jsp 2KB
add.jsp 2KB
classes
jdbc.properties 174B
cn
itcast
dao
UserDao$1.class 2KB
UserDao.class 3KB
model
User.class 2KB
controller
UserController.class 3KB
service
UserService.class 1KB
springmvc-servlet.xml 1KB
applicationContext.xml 2KB
lib
com.springsource.org.apache.commons.logging-1.1.1.jar 60KB
org.springframework.asm-3.0.2.RELEASE.jar 52KB
org.springframework.context.support-3.0.2.RELEASE.jar 98KB
org.springframework.core-3.0.2.RELEASE.jar 350KB
org.springframework.transaction-3.0.2.RELEASE.jar 226KB
org.springframework.web.servlet-3.0.2.RELEASE.jar 394KB
org.springframework.expression-3.0.2.RELEASE.jar 153KB
org.springframework.aop-3.0.2.RELEASE.jar 313KB
org.springframework.jdbc-3.0.2.RELEASE.jar 369KB
com.springsource.org.aopalliance-1.0.0.jar 5KB
org.springframework.context-3.0.2.RELEASE.jar 642KB
mchange-commons-java-0.2.3.jar 556KB
com.springsource.javax.annotation-1.0.0.jar 6KB
org.springframework.web-3.0.2.RELEASE.jar 374KB
com.springsource.javax.servlet.jsp.jstl-1.1.2.jar 21KB
com.springsource.org.apache.taglibs.standard-1.1.2.jar 389KB
c3p0-0.9.2-pre5.jar 405KB
mysql-connector-java-5.1.22-bin.jar 813KB
org.springframework.beans-3.0.2.RELEASE.jar 537KB
index.jsp 1020B
.mymetadata 333B
.classpath 2KB
.myeclipse
共 47 条
- 1
资源评论
- 提笔_写深情2014-10-23还不错的书籍
- Asia11002016-11-26坑人而已,白白浪费积分,我只能说,艹 尼 吗
- qq_192763772015-08-27去你妹的,就一个没写方法的空壳也套分。。。。
情非得已1991
- 粉丝: 54
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功