package com.xwx.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xwx.model.User;
import com.xwx.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
//设置log
private static Logger log = Logger.getLogger(UserController.class.getName());
@Autowired
private UserService userService;
public UserService getUser() {
return userService;
}
public void setUser(UserService user) {
userService = user;
}
@RequestMapping(value="/index", method={RequestMethod.GET})
public String index(HttpServletRequest request, ModelMap modelMap, @RequestParam(value="name", required=false) String name, @RequestParam(value="page", defaultValue="1") String paramPage){
if(null == paramPage){
paramPage = "1";
}
int page = Integer.parseInt(paramPage);
int pageSize = 3;
log.debug("name="+name);
log.debug("page"+page);
PageHelper.startPage(page, pageSize);
List<User> u = null;
if(null !=name && !name.equals("")){
User user = new User();
user.setName(name);
u = userService.selectAll(user);
} else {
u = userService.selectAll(null);
}
PageInfo<User> pageInfo = new PageInfo<User>(u);
log.debug(u);
log.debug(pageInfo);
modelMap.addAttribute("user", u);
modelMap.addAttribute("name", name);
modelMap.addAttribute("pageInfo", pageInfo.getNavigatepageNums());
return "user/index";
}
@RequestMapping("/update")
public String update(int id, HttpServletRequest request){
User user = userService.getUserById(id);
request.setAttribute("user", user);
log.debug(user);
return "user/update";
}
@RequestMapping("/doUpdate")
public String doUpdate(HttpServletRequest request, ModelMap modelMap, @Validated User user, BindingResult bindingResult){
if(bindingResult.hasErrors()){
List<ObjectError> errors = bindingResult.getAllErrors();
log.error(bindingResult.getAllErrors().toString());
modelMap.addAttribute("errors",errors);
return "user/update";
}
userService.updateByPrimaryKey(user);
return "redirect:index.do";
}
@RequestMapping("/add")
public String add(){
return "user/add";
}
@RequestMapping("/doAdd")
public String doAdd(HttpServletRequest request, ModelMap modelMap, @Validated User user, BindingResult bindingResult) {
log.debug(user);
if(bindingResult.hasErrors()){
List<ObjectError> errors = bindingResult.getAllErrors();
log.error(bindingResult.getAllErrors().toString());
modelMap.addAttribute("errors",errors);
return "user/add";
}
userService.insert(user);
return "redirect:index.do";
}
@RequestMapping("/delete")
public String delete(int id){
userService.deleteByPrimaryKey(id);
return "redirect:index.do";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SpringMVC+Spring4+Mybatis3 Maven整合源码
共43个文件
xml:13个
properties:7个
jsp:6个
3星 · 超过75%的资源 需积分: 31 85 下载量 172 浏览量
2017-09-12
17:48:48
上传
评论 1
收藏 128KB ZIP 举报
温馨提示
SpringMVC+Spring4+Mybatis3 Maven整合教程 SpringMVC+Spring4+Mybatis3 Maven整合教程 SpringMVC+Spring4+Mybatis3 Maven整合教程
资源推荐
资源详情
资源评论
收起资源包目录
MavenDemo.zip (43个子文件)
MavenDemo
.project 1KB
src
test
resources
java
com
xwx
text
main
webapp
WEB-INF
jsp
user
page.jsp 485B
index.jsp 2KB
add.jsp 828B
update.jsp 855B
web.xml 3KB
index.jsp 349B
css
404.jsp 345B
resources
config.properties 184B
spring-mybatis.xml 2KB
spring-mvc.xml 2KB
log4j.properties 759B
mybatisPlugin.xml 2KB
spring.xml 673B
hibernate
validator
ValidationMessages.properties 121B
java
com
xwx
service
UserService.java 941B
model
User.java 1KB
controller
UserController.java 3KB
dao
UserMapper.java 411B
util
mapping
UserMapper.xml 3KB
mybatis.log 1.15MB
target
m2e-wtp
web-resources
META-INF
MANIFEST.MF 114B
maven
com.xwx
MavenDemo
pom.properties 212B
pom.xml 5KB
classes
config.properties 184B
spring-mybatis.xml 2KB
spring-mvc.xml 2KB
log4j.properties 759B
mybatisPlugin.xml 2KB
spring.xml 673B
hibernate
validator
ValidationMessages.properties 121B
test-classes
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 292B
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 430B
org.eclipse.wst.validation.prefs 50B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.runtime.prefs 52B
org.eclipse.core.resources.prefs 384B
org.eclipse.wst.common.component 683B
.jsdtscope 639B
pom.xml 5KB
.classpath 2KB
共 43 条
- 1
资源评论
- 李小穷2019-03-01好东西学习了_xiaoxiong2019-03-06坚持学习
- lhdgtg2017-10-09我先下载看看_xiaoxiong2018-11-06放心下载吧
_xiaoxiong
- 粉丝: 89
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python语言教程1-python批量图片重命名,将后缀某几个不想要的字去除
- Space Combat Kit 太空战斗套件Unity游戏开发插件资源unitypackage C#
- Universal Device Preview 通用设备预览Unity游戏开发插件资源unitypackage
- Paladin Anim Set 圣骑士动画集Unity游戏动作动画插件资源unitypackage
- 计算机财务管理期末考报表部分题目及答案.doc
- 计算机软件维护论文.doc
- 计算机软件著作权授权书.docx
- 计算机键盘教学案例.doc
- 计算流体力学软件平台方案.pptx
- 计量自动化系统介绍.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功