Action部分,这个部分关于id的处理很不好,但愿有同志能看到给提个醒,怎样做能好一点
package com.james.action;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.james.domain.User;
import com.james.service.UserService;
@Component("usermgr")
@Scope("prototype")
public class UserAction {
public List<User> users;
public String userName;
public String passWord;
public String telphone;
public String context;
public String address;
public String id;
public UserService userService;
public boolean success=true;
public User user=new User();
public String save(){
System.out.println("action method save get id is:"+id);
try {
int vid=Integer.parseInt(id);
this.updata();
} catch (NumberFormatException e) {
user.setAddress(address);
user.setContext(context);
user.setPassWord(passWord);
user.setTelphone(telphone);
user.setUserName(userName);
userService.save(user);
// TODO Auto-generated catch block
//e.printStackTrace();
}
return "success";
}
public String del(){
int vid=Integer.parseInt(id);
userService.del(vid);
return "success";
}
public String updata(){
System.out.println("action method update get id is:"+id);
int vid=Integer.parseInt(id);
user.setAddress(address);
user.setContext(context);
user.setPassWord(passWord);
user.setTelphone(telphone);
user.setUserName(userName);
user.setId(vid);
userService.update(user);
return "success";
}
public String findById(){
return "success";
}
public String findAll(){
users=userService.findAll();
return "success";
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getTelphone() {
return telphone;
}
public void setTelphone(String telphone) {
this.telphone = telphone;
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String findByName(){
return "success";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
@Resource
public void setUserService(UserService userService) {
this.userService = userService;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.james"/>
<!-- 数据库配置部分 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/mydb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>a</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>com.james.domain.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
extjs部分
Ext.ns("com.james");
com.james.UserPanel = Ext.extend(Ext.Panel, {
fields : ['id', 'userName', 'passWord', 'telphone', 'context',
'address'],
createEdit:function(){
this.win = new Ext.Window({
width : 300,
height : 300,
title : "用户维护",
items : {
xtype : "form",
layout : "form",
items : [
{xtype:"hidden",name:"id"},
{
xtype : "textfield",
fieldLabel : "姓名",
name : "userName",
anchor : "70%"
}, {
xtype : "textfield",
fieldLabel : "密码",
name : "passWord",
anchor : "70%"
}, {
xtype : "textfield",
fieldLabel : "电话",
name : "telphone",
anchor : "70%"
}, {
xtype : "textfield",
fieldLabel : "地址",
name : "address",
anchor : "70%"
}, {
xtype : "textarea",
fieldLabel : "附录",
name : "context",
anchor : "70%"
}]
},
buttons : [{
text : "提交",
handler : function() {
this.win.getComponent(0).getForm()
.submit({
url : "usermgr!save",
success : function() {
Ext.Msg
.alert("添加成功");
this.win.close();
this.vstore.reload();
},scope:this
});
},scope:this
}, {
text : "重置"
}, {
text : "取消",
handler : function() {
this.win.close();
}
}]
});
},
// *********************************************添加用户用户**************************************************************
//这种方式只要是有回调函数的地方都必须写 scope:this
adduser : function() {
this.createEdit();
this.win.show();
// ***********************************************************************************************************
},
deluser : function() {
var record =this.grid.getSelectionModel().getSelected();
var vid = record.get("id");
Ext.Ajax.request({
url : "usermgr!del",
params : {
id : vid
},
callback : function() {
Ext.Msg.alert("信息提示", "删除成功");
this.vstore.reload();
},scope:this
});
},
// ************************************修改用户***********************************************************************
updateuser : function() {
this.createEdit();
this.win.show();
// 获取当前鼠标选择记录
var record = this.grid.getSelectionModel().getSelected();
this.win.getComponent(0).getForm().loadRecord(record);
},
// ***************************初始化窗口********************************************************************************
initComponent : function() {
com.james.UserPanel.superclass.initComponent.call(this);
this.vstore = new Ext.data.JsonStore({
url : "usermgr!findAll",
root : "users",
idProperty : "id",
fields :this.fields
});
var p1 = new Ext.Panel({
title : "panel1",
height : 100,
collapsible : true
});
var p2 = new Ext.Panel({
title : "panel2",
height : 100,
collapsible : true
});
var p3 = new Ext.Panel({
title : "panel3",
height : 100,
collapsible : true,
animCollapse : true
});
this. grid = new Ext.grid.GridPanel({
tbar : [{
text : "添加",
handler : this.adduser,scope:this
}, "-", {
text : "删除",
handler : this.deluser,scope:this
}, "-", {
text : "修改",
handler : this.updateuser,scope:this
}],
store : this.vstore,
autoHeight : true,
columns : [{
header : "编号",
dataIndex : "id"
}, {
header : "姓名",
dataIndex : "userName"
}, {
header : "电话",
dataIndex : "telphone"
}, {
header : "密码",
dataIndex : "passWord"
}, {
header : "备注",
dataIndex : "context"
}, {
header : "地址",
dataIndex : "address"
}]
});
this.add(this.grid);
this.vstore.load();
}
});
Ext.onReady(function() {
var up = new com.james.UserPanel({
title : "jlksfdjklasfdj"
});
var vp = new Ext.Viewport({
layout : "border",
items : [{
region : "north",
height : 200
}, {
region : "west",
width : 200
}, {
region : "center",
items : [up]
}]
});
})
分享到:
相关推荐
Struts2 Spring Hibernate Extjs 物资管理系统采用MSSQL数据库,需要自己安装jar包,没有数据库不好意思,文件太大上传不了
Struts2、Spring、Hibernate整合ExtJS
struts spring hibernate jquery extJs简单教程超值
Hibernate+Spring+Struts2+ExtJS整合开发实例 非常经典!学习的好帮助!
struts2.3 spring4 hibernate4.3 EXTJS4项目,用户管理权限系统。
struts2 hibernate spring extjs 项目的应用,是很好的学习资料哦
Struts2、Spring、Hibernate整合ExtJS
人力资源管理系统Struts_Spring_Hibernate_Extjs 人力资源管理系统Struts_Spring_Hibernate_Extjs 人力资源管理系统Struts_Spring_Hibernate_Extjs 人力资源管理系统Struts_Spring_Hibernate_Extjs 人力资源管理系统...
Struts2+Spring+Hibernate+ExtJS开发CRUD功能
前提是数据库test必修存在,一般mysql默认是有这个数据库的, 数据表的名字是person,如果你有相同的表的话请备份,...限于上传的限制,spring.jar 和 webwork.2.2.jar还没加进来 欢迎交流:百度hi java_web群 1028944
本系统采用Struts+Spring+Hibernate+Extjs结合技术,严格按照软件工程学的方法进行开发,应用数据库为Oracle 10g。既采用Oracle数据库的坚强数据核心,又结合Struts+Spring+Hibernate框架的稳定性和实用性,还...
Spring+Struts+hibernate+Extjs的客户关系管理系统源代码
这是用ExtJs2.0+struts2+hibernate3.0+spring2.5搭建起来的一个简单的图书管理系统,仅供参考,其中,我在里面尝试了两种定时任务
extjs,struts,spring项目代码 extjs,struts,spring项目代码 extjs,struts,spring项目代码
Struts+Spring+Hibernate+ExtJs毕业系统
Hibernate+Spring+Struts2+extjs开发的图文管理系统,里面有很多实用的业务逻辑代码,
本例子采用Struts2+hibernate+spring整合开发,用到了目前很流行的Extjs,实现了一个音乐库,对于Java深入学习者有极大的极大的帮助。本例中的lib包随后上传
J2EE最新精品项目源码Struts2.0+Hibernate+Spring+ExtJS
Struts2+Spring+Hibernate+ExtJS开发实例.pdf
Struts+Spring+Hibernate+ExtJs学生学籍系统毕业设计