2016.7.1
2016-07-04 21:06
281 查看
一、修改用户信息(1个页面+2个control)
一个页面:用于显示用户信息(display.jsp)
一个control:用户信息在后台从session中拿到(
User user = request.getSession.getAttribute(“user”); )
然后放到request中(
Request.setattribute(“user_name”, username);````)
在前台通过jquery拿到$(user_name)
显示出来
另一个control:修改信息的链接:updateInfo.do
从session中拿到用户信息,从前端拿到修改的信息。通过用户信息中的ID去修改用户信息,然后重新设置session。返回用户信息页面。
二、写sql传参数(传的参数是个对象)
1、
public interface UpdateMapper {
@UpdateProvider(method =
"updateInfo", type =
UpdateSQL.class)
public int updateInfo(@Param("userId")int uerId,
@Param("uerNewInfo")Enterprise_user uerNewInfo);
//当传入的值是个对象,在sql中用map映射
}
2、 //设置值得时候要加引号
public String updateInfo(Map<String,Object>
map) {
Enterprise_user uerNewInfo = (Enterprise_user)
map.get("uerNewInfo");//使用map拿到参数对象
String sql = "update z_enterprinse_users set
user_name='"+uerNewInfo.getUser_name()+"',
passwd='"+uerNewInfo.getPasswd()+"', email='"+uerNewInfo.getEmail()+"', mobile='"+uerNewInfo.getMobile()+"'
where id=#{userId}";
return sql;
}
3. Model map的作用
Public String getAllPaper(HttpServletRequest
request,Map<String,Object> model){
model.put("passwd", passwd);
}
ModelMap
ModelMap对象主要用于传递控制方法处理数据到结果页面,也就是说我们把结果页面上需要的数据放到ModelMap对象中即可,他的作用类似于 request对象的setAttribute方法的作用,用来在一个请求过程中传递处理的数据。通过以下方法向页面传递参数:
addAttribute(String key,Object value);
在页面上可以通过el变量方式$key或者bboss的一系列数据展示标签获取并展示modelmap中的数据。
4.从session中获取值,得到的值是个对象
String username =
request.getSession().getAttribute("username").toString();
5.验证sql写的是否正确
StringBuffer sb=new StringBuffer();
sb.append("select count(userId) from user where 1=1 ");
Sb.append(“”);
Sb.append(“”);
System.out.println("sql::::::::::"+sb.toString());
6.在mysql中,时间的数据类型是:datetime
7.设置rowcount时,设置pagecount
public void setRowCount(int rowCount)
{
this.rowCount = rowCount;
setPageCount();
}
public void setPageCount() {
if(rowCount%pageSize==0){
this.pageCount =
rowCount/pageSize;
}else{
this.pageCount = (rowCount/pageSize)+1;
}
}
8.form直接提交
<form action="<%=basePath%>test/test.do">
<input name="name" value="nihao">
<input name="age" value="26">
<button type="submit">测试</button>
</form>
一个页面:用于显示用户信息(display.jsp)
一个control:用户信息在后台从session中拿到(
User user = request.getSession.getAttribute(“user”); )
然后放到request中(
Request.setattribute(“user_name”, username);````)
在前台通过jquery拿到$(user_name)
显示出来
另一个control:修改信息的链接:updateInfo.do
从session中拿到用户信息,从前端拿到修改的信息。通过用户信息中的ID去修改用户信息,然后重新设置session。返回用户信息页面。
二、写sql传参数(传的参数是个对象)
1、
public interface UpdateMapper {
@UpdateProvider(method =
"updateInfo", type =
UpdateSQL.class)
public int updateInfo(@Param("userId")int uerId,
@Param("uerNewInfo")Enterprise_user uerNewInfo);
//当传入的值是个对象,在sql中用map映射
}
2、 //设置值得时候要加引号
public String updateInfo(Map<String,Object>
map) {
Enterprise_user uerNewInfo = (Enterprise_user)
map.get("uerNewInfo");//使用map拿到参数对象
String sql = "update z_enterprinse_users set
user_name='"+uerNewInfo.getUser_name()+"',
passwd='"+uerNewInfo.getPasswd()+"', email='"+uerNewInfo.getEmail()+"', mobile='"+uerNewInfo.getMobile()+"'
where id=#{userId}";
return sql;
}
3. Model map的作用
Public String getAllPaper(HttpServletRequest
request,Map<String,Object> model){
model.put("passwd", passwd);
}
ModelMap
ModelMap对象主要用于传递控制方法处理数据到结果页面,也就是说我们把结果页面上需要的数据放到ModelMap对象中即可,他的作用类似于 request对象的setAttribute方法的作用,用来在一个请求过程中传递处理的数据。通过以下方法向页面传递参数:
addAttribute(String key,Object value);
在页面上可以通过el变量方式$key或者bboss的一系列数据展示标签获取并展示modelmap中的数据。
4.从session中获取值,得到的值是个对象
String username =
request.getSession().getAttribute("username").toString();
5.验证sql写的是否正确
StringBuffer sb=new StringBuffer();
sb.append("select count(userId) from user where 1=1 ");
Sb.append(“”);
Sb.append(“”);
System.out.println("sql::::::::::"+sb.toString());
6.在mysql中,时间的数据类型是:datetime
7.设置rowcount时,设置pagecount
public void setRowCount(int rowCount)
{
this.rowCount = rowCount;
setPageCount();
}
public void setPageCount() {
if(rowCount%pageSize==0){
this.pageCount =
rowCount/pageSize;
}else{
this.pageCount = (rowCount/pageSize)+1;
}
}
8.form直接提交
<form action="<%=basePath%>test/test.do">
<input name="name" value="nihao">
<input name="age" value="26">
<button type="submit">测试</button>
</form>
相关文章推荐
- PHP电商购物车(一:建立数据表)
- 每天一个linux命令(34)--top命令
- FJ省队集训DAY2 T1
- java1.7集合源码阅读: Stack
- Ubuntu桌面版与服务器版的区别
- NOIP2012 D2 T2 借教室 线段树 OR 二分法
- OOP-----封装,继承,多态
- NOIP2012 D2 T2 借教室 线段树 OR 二分法
- Java中的String字符串,异常处理,和泛型
- 解决maven以及eclipse的jar以及exe中文乱码问题
- 使用UISearchController的时候 cellForRow 崩溃
- Android 漂浮类动效的分析与实现
- 面向对象
- struts2的原理
- HTML5笔记-(常用元素)
- 文件的删除
- autoConfig
- 进程与线程
- 导出Excel
- Linux 进程/端口监控 自动重启