package com.wg.test;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.wg.bean.User;
import com.wg.service.UserService;
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping(value = "regist", method = RequestMethod.POST)
public ModelAndView regist(HttpServletRequest request, User user) {
try {
userService.saveUser(user);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("username", user.getUsername());
request.setAttribute("password", user.getPassword());
System.out.println(user.toString());
return new ModelAndView("succ");
}
/***
* 用户登陆
* <p>
* 注解配置,只允许POST提交到该方法
*
* @param username
* @param password
* @return
*/
@RequestMapping(value = "login", method = RequestMethod.POST)
public ModelAndView login(String username, String password) {
// 验证传递过来的参数是否正确,否则返回到登陆页面。
if (this.checkParams(new String[] { username, password })) {
// 指定要返回的页面为succ.jsp
ModelAndView mav = new ModelAndView("succ");
// 将参数返回给页面
mav.addObject("username", username);
mav.addObject("password", password);
System.out
.println("username=" + username + " password=" + password);
return mav;
}
return new ModelAndView("home");
}
/***
* 验证参数是否为空
*
* @param params
* @return
*/
private boolean checkParams(String[] params) {
for (String param : params) {
if (param == "" || param == null || param.isEmpty()) {
return false;
}
}
return true;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SpringMVC入门+myBatis简单示例分享
共59个文件
jar:21个
xml:12个
class:6个
5星 · 超过95%的资源 需积分: 16 3.0k 下载量 188 浏览量
2015-05-13
12:42:29
上传
评论 20
收藏 6.79MB RAR 举报
温馨提示
SpringMVC+myBatis入门简单示例分享,轻量级 SpringMVC入门+myBatis简单示例分享
资源推荐
资源详情
资源评论
收起资源包目录
SpringMVC.rar (59个子文件)
SpringMVC
.project 2KB
user.sql 1KB
.mymetadata 300B
src
user-context.xml 772B
root-context.xml 2KB
com
wg
service
impl
UserServiceImpl.java 906B
UserService.java 681B
dao
UserDao.java 691B
test
HomeController.java 502B
UserController.java 2KB
bean
User.java 617B
UserMapper.xml 1KB
impl
mybatis-config.xml 337B
mvc-context.xml 881B
WebRoot
WEB-INF
classes
user-context.xml 772B
root-context.xml 2KB
com
wg
service
UserService.class 446B
impl
UserServiceImpl.class 2KB
dao
UserDao.class 388B
test
UserController.class 3KB
HomeController.class 762B
bean
User.class 1KB
UserMapper.xml 1KB
impl
mybatis-config.xml 337B
mvc-context.xml 881B
lib
org.springframework.web.servlet-3.1.1.RELEASE.jar 560KB
org.springframework.web-3.1.1.RELEASE.jar 532KB
org.springframework.beans-3.1.1.RELEASE.jar 576KB
commons-pool.jar 61KB
mysql-connector-java-5.1.10-bin.jar 707KB
org.springframework.expression-3.1.1.RELEASE.jar 172KB
jstl.jar 20KB
org.springframework.jdbc-3.1.1.RELEASE.jar 395KB
commons-dbcp.jar 119KB
mybatis-spring-1.2.0.jar 48KB
org.springframework.asm-3.1.1.RELEASE.jar 52KB
aspectjweaver.jar 1.47MB
mybatis-3.2.2.jar 683KB
org.springframework.context-3.1.1.RELEASE.jar 812KB
commons-logging-1.1.3.jar 61KB
aspectjrt.jar 114KB
aopalliance.jar 4KB
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
org.springframework.core-3.1.1.RELEASE.jar 439KB
web.xml 2KB
index.jsp 860B
page
succ.jsp 410B
login.jsp 684B
home.jsp 368B
META-INF
MANIFEST.MF 36B
.myeclipse
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.jdt.core.prefs 395B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 465B
.jsdtscope 500B
.classpath 2KB
共 59 条
- 1
IOT-farmer
- 粉丝: 28
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页