spring mvc实现新增用户
spring mvc实现新增用户
1、先在展示页面(查询出来的结果页)添加一个连接<a href="add">添加</a>
2、在后台添加一个添加的方法,点击添加,是跳转到add.jsp页面,刚过去没数据,应该是get方法请求
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(){
//这个页面点击add跳转就会报500的错,传入的是空的
return "user/add"; }
//链接到add页面时,为get请求,访问以下代码(两种方式)
@RequestMapping(value="/add",method=RequestMethod.GET)
/* 方式一:
public String add(Model model){
model.addAttribute(new User());
return "user/add";
}
*/
// 方式二:把一个对象放入到model中,key 就是 user
public String add(@ModelAttribute("user") User user){
//model.addAttribute(new User());
return "user/add";
}
//add方法,根据get和post请求来调用哪个方法
//提交数据的时候时post请求
//如果页面有提交到action,这边的value就是action的值
@RequestMapping(value="/add",method=RequestMethod.POST)
public String add(User user){
//把user对象放进去key(id)
userList.put(user.getId(), user); // return "user/userlist";//返回到逻辑视图名
//(添加后,不能把添加过的数据展示出来)服务器端行为
return "redirect:user/list";//客户端重新发送请求(把添加进去的展示出来)
}
3、在add.jsp中添加form表单
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
这句话在spring-framework-3.2.1.RELEASE-dist\spring-framework-3.2.1.RELEASE\docs\spring-framework-reference\html\view.html中
<body>
<!-- 不指定action,那么请求提交到/add -->
<!-- modelAttribute添加的对象(我们添加用户,就是添加到user中) -->
<form:form modelAttribute = "user" method="post">
ID:<form:input path="id"/><br/>
userName:<form:input path="userName"/><br/>
password:<form:input path="password"/><br/>
email:<form:input path="email"/><br/>
<input type="submit" value="提交"/>
</form:form>
</body>
处理编码问题
<!-- 处理中文编码的filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
验证添加页面(注释方法)
public class User {
private String id;
private String userName;
private String password;
private String email; public User(){ }
public User(String id, String userName, String password, String email) {
this.id = id;
this.userName = userName;
this.password = password;
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@NotEmpty(message="用户名不能为空")
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Size(min=4,max=10,message="密码长度4-10位")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Email(message="邮箱格式不正确")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
@NotEmpty(message="用户名不能为空")
public String getUserName() {
return userName;
}
@Size(min=4,max=10,message="密码长度4-10位")
public String getPassword() {
return password;
}
@Email(message="邮箱格式不正确")
public String getEmail() {
return email;
}
在控制器那得加一个验证注释
@Validated User user,BindingResult bindingResult
//添加用户是,为post请求,访问以下代码
@RequestMapping(value="/add",method=RequestMethod.POST)
public String add(@Validated User user,BindingResult bindingResult){//紧跟validate之后写验证结果
if(bindingResult.hasErrors()){
//若有错误,直接掉转到add 视图
return "user/add";
}
userList.put(user.getUserName(), user);
return "redirect:/user/userlist";
}
最后在页面上提示错误
<body>
<!-- 没有写action,直接提交给/add -->
<form:formmethod="post" modelAttribute="user">
UserName:<sf:input path="userName"/><form:errors path="userName"/><br/>
password:<sf:password path="password"/><sf:errors path="password"/><br/>
email:<sf:input path="email"/><form:errors path="email"/><br/>
<input type="submit" value="保存"/>
</form:form>
</body>
添加的控制器(完整代码)
@Controller
@RequestMapping("/user")
public class UserController {
private Map<String, User> userList= new HashMap<String, User>(); public UserController() {
userList.put("hl", new User("hl","123456","部门经理","hanlu@bdqn.cn"));
userList.put("zs", new User("zs","123456","质量经理","zhangsan@bdqn.cn"));
userList.put("zw", new User("zw","123456","开发工程师","zhangwei@bdqn.cn"));
userList.put("ly", new User("ly","123456","实施顾问","liyu@bdqn.cn"));
}
//上面的value是url,下面的userlist是视图逻辑名
@RequestMapping(value="/userlist",method=RequestMethod.GET)
public String list(Model model){
model.addAttribute("userlist",userList);
return "user/list";//逻辑视图名
} //链接到add页面时,为get请求,访问以下代码(两种方式)
@RequestMapping(value="/adduser",method=RequestMethod.GET)
/* 方式一:
public String add(Model model){
model.addAttribute(new User());
return "user/add";
}
*/
// 方式二:把一个对象放入到model中,key 就是 user
public String add(@ModelAttribute("user") User user){
//model.addAttribute(new User());
return "user/add";
} //添加用户是,为post请求,访问以下代码
@RequestMapping(value="/adduser",method=RequestMethod.POST)
public String add(@Validated User user,BindingResult bindingResult){//紧跟validate之后写验证结果
if(bindingResult.hasErrors()){
//若有错误,直接掉转到add 视图
return "user/add";
}
userList.put(user.getUserName(), user);
return "redirect:/user/userlist";//客户端重新发送请求
} }
别忘了添加验证的3个jar包aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkYAAABjCAIAAADxQViXAAAeoElEQVR4nO2d/W8cx3nH+U+oKAwYBQIUSNAfkiYIkGtRNGjRNL+oQdGggNO0kOtekNRmiqho4rYI0No1LzbiK2vJhoqaWYkSFMQ9kmIu51udKYmyKCchKx/cyvQ5jUs21Tkyzcjkve7t7Z76w97uzjPzzOzs8XhvfD44CLzZeb/d+e48M5pnyiGIo0q7PewaHA2onwfDUetntL1TA68GQRAEQRwKJGkEQRDEhECSRhAEQUwIJGkEQRDEhECSRhAEQUwIJGkEQRDEhECSRhAEQUwIJGkEQRDEhECSRhAEQUwIJGkEQRDEhAAkbVXO1atXC4XCsGpJEARBEJHwkua0247Tdl3HdZ1Ox+10XMdpdzru+vq6aZqkagRBEMTIAiTt2rVr7bYtqlqn4968ebPRaOTz+ZWVlSFVlSAIgiBUAEm7cuWKbbdQVSsUCqZpSiZq2eRUIl2CYaV0ohtYSiemktnDbMQhkk16dQ+bI1zHgscSWRtV+P1zoEwIYliUzdS0URTDiwYaPADKZmo6ZZaHWodxBkjaysqK3bKu3yqtb25tbG5vbG6vv7m1sbm9vrn16utvv1sub29tkaTx1wczgJfSiSlZDTzQPg6uiklL6cRUSCJdIkkLKJup6S7MoFI0umH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/3d3/s8qRpBEMSIQJLWOw88+NHyu3dJ1QiCIEaE/wejArlowFqfIQAAAABJRU5ErkJggg==" alt="" />
1、在userlist.jsp的展示页面添加链接
<a href="view/${ul.value.id }">userName:${ul.value.userName }</a><br/>
2、实现view.jsp页面
<body>
=============查看用户信息===========
ID:${user.id }<br/>
userName:${user.userName }<br/>
password:${user.password }<br/>
email:${user.email }<br/>
</body>
在userController中再加上如下代码:实现查看每条记录
//地址中的参数用{id}来写
//REST风格 是/user/list/{id} 网页那是?id=3
@RequestMapping(value="/view/{id}",method=RequestMethod.GET)
public String view(@PathVariable String id,Model model){
//userlist。get就是拿到key(id)的值
model.addAttribute(userList.get(id));
return "user/view";
}
增加后的查看view.jsp
spring mvc实现新增用户的更多相关文章
- Spring MVC学习笔记——用户增删该查和服务器端验证
建立一个动态web项目,起名为SpringMVC_crud 导包,其中包括jstl的一些包等 1.先写一个User.java,是用户类 文件User.java文件 package org.common ...
- Spring Boot 构建电商基础秒杀项目 (二) 使用 Spring MVC 方式获取用户信息
SpringBoot构建电商基础秒杀项目 学习笔记 修改 DOMapper 在 UserPasswordDOMapper.xml 添加: <select id="selectByUse ...
- Spring MVC教程——检视阅读
Spring MVC教程--检视阅读 参考 Spring MVC教程--一点--蓝本 Spring MVC教程--c语言中午网--3.0版本太老了 Spring MVC教程--易百--4.0版本不是通 ...
- spring mvc+myBatis配置详解
一.spring mvc Spring框架(框架即:编程注解+xml配置的方式)MVC是Spring框架的一大特征,Spring框架有三大特征(IOC(依赖注入),AOP(面向切面),MVC(建模M- ...
- Hibernate validator使用和自定义validator及整合Spring MVC
http://blog.csdn.net/lwphk/article/details/43983669 Hibernate validator使用 导入validation-api-xxx.jar 以 ...
- Spring MVC之简单入门
一.Spring MVC简介: 1.什么是MVC 模型-视图-控制器(MVC)是一个众所周知的以设计界面应用程序为基础的设计模式.它主要通过分离模型(Model).视图(View)及控制器(Contr ...
- Java Web 学习(4) —— Spring MVC 概览
Spring MVC 概览 一. Spring MVC Spring MVC 是一个包含了 Dispatcher Servlet 的 MVC 框架. Dispatcher Servlet 实现了 : ...
- Spring MVC -- Spring MVC入门
本篇博客首先介绍Spring MVC的优点,然后介绍Spring MVC的基本组件,包括DispatcherServlet,并学习如何开发一个“传统风格”的控制器,这是在Spring 2.5版本之前开 ...
- 一、Spring MVC起步——IntelliJ IDEA 搭建Spring MVC环境(手把手搭建)
本机环境: JDK 1.7 IntelliJ IDEA 2017.2 1.新建项目 Create New Project 选择Spring MVC 填写项目名和项目存放位置 然后点击Fin ...
随机推荐
- C#中小数点后保留两位小数,四舍五入的函数及使用方法
Math.Round(45.367,2) //Returns 45.37 Math.Round(45.365,2) //Returns 45.36 C#中的Round()不是我 ...
- [CareerCup] 14.4 Templates Java模板
14.4 Explain the difference between templates in C++ and generics in Java. 在Java中,泛式编程Generic Progra ...
- 浪潮之巅IT那点事之三——神奇的规律
“道可道,非常道”是老子在<道德经>中的开篇第一句话,这句话的意思是:万事万物其真理是可以探索并道说得出来的,但这些真理并非是永恒的,天道轮转,没有永恒不变的真理(来自百度百科).在IT行 ...
- UIAccessibilityElement
UIaccessibilityElement类封装的项目信息对一些特殊的人可见,默认情况下是不可访问的.例如,一个图标或文字图像不会自动访问,因为它没有继承的UIView(或UIControl).一个 ...
- c# 模拟get和post
private string HttpPost(string Url, string postDataStr) { HttpWebRequest request ...
- 微信小程序开发:http请求
在微信小程序进行网络通信,只能和指定的域名进行通信,微信小程序包括四种类型的网络请求. 普通HTTPS请求(wx.request) 上传文件(wx.uploadFile) 下载文件(wx.downlo ...
- offsetWidth与scrollLeft
有两个值一个是:scrollTop一个是scrollLeft第一个代表页面利用滚动条滚动到下方时,隐藏在滚动条上方的页面的高度:第二个代表页面利用滚动条滚动到右侧时,隐藏在滚动条左侧的页面的宽度 do ...
- [工具类]泛型集合转换为DataTable
写在前面 在实际项目中,用到了将集合转换为DataTable,就试着封装了一个方法,记录一下. 代码 using System; using System.Collections.Generic; u ...
- 第一次作业---安卓开发工具Android studio发展演变
Android studio2013年由谷歌推出,用于安卓端的开发,我所使用的版本为2015年5月推出的1.3.2. 1.安装.配置.作为麻瓜的我,刚刚接触Android studio时在安装方面走了 ...
- JavaScript、CSS、JSP 实现用户注册页面与信息校验
参考:http://blog.csdn.net/fightfaith/article/details/50277337 需求:实现用户注册页面并作出逻辑校验.要求: (1)完成注册页面样式如下: (2 ...