代码我给大家贴过来,希望大家多费心帮忙看看,谢谢了……
===========================================
[color=#FF0000]Things.java[/color]
___________________________________________
package com.lg.bean;
import java.util.Date;
public class Things {
private Integer id;
private String name ;
private Date date ;
private Integer money;
private Integer dvalue;
private Integer mvalue ;
private Group group ;
private Integer gid ;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Integer getMoney() {
return money;
}
public void setMoney(Integer money) {
this.money = money;
}
public Integer getDvalue() {
return dvalue;
}
public void setDvalue(Integer dvalue) {
this.dvalue = dvalue;
}
public Integer getMvalue() {
return mvalue;
}
public void setMvalue(Integer mvalue) {
this.mvalue = mvalue;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public Integer getGid() {
return gid;
}
public void setGid(Integer gid) {
this.gid = gid;
}
}
[color=#FF0000]Things.hbm.xml[/color]
__________________________________________________
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.lg.bean.Things" table="lg_things">
<id name="id" type="java.lang.Integer" column="id">
<generator class="increment"></generator>
</id>
<property name="name" type="java.lang.String" length="50" column="name" />
<property name="date" type="java.util.Date" column="date" />
<property name="money" type="java.lang.Integer" column="money" />
<property name="dvalue" type="java.lang.Integer" column="dvalue" />
<property name="mvalue" type="java.lang.Integer" column="mvalue" />
<property name="gid" type="java.lang.Integer" column="gid" insert="false" update="false" />
<many-to-one name="group" class="com.lg.bean.Group" fetch="select">
<column name="gid" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
[color=#FF0000]ThingsDao.java[/color]
_____________________________________________________________
package com.lg.dao;
import java.util.List;
import com.lg.bean.Things;
public interface ThingsDao {
/**
* 保存一条记录
*/
public void save(Things thing) ;
/**
* 更新一条记录
*/
public void update(Things thing) ;
/**
* 删除一条记录
*/
public void delete(Integer id) ;
/**
* 查询单条记录
*/
public Things find(Integer id) ;
/**
* 查询所有记录
*/
public List<Things> findAll() ;
/**
* 按条件查询记录
*/
public List<Things> pointFind(Object[] obj) ;
}
[color=#FF0000]ThingsDaoImpl.java[/color]
_________________________________________________________
package com.lg.dao.impl;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.lg.bean.Things;
import com.lg.dao.ThingsDao;
public class ThingsDaoImpl extends HibernateDaoSupport implements ThingsDao {
public void delete(Integer id) {
this.getHibernateTemplate().delete(this.find(id)) ;
}
public Things find(Integer id) {
return (Things) this.getHibernateTemplate().get(Things.class, id);
}
@SuppressWarnings("unchecked")
public List<Things> findAll() {
String hql = "from Things things order by things.date" ;
List<Things> list = this.getHibernateTemplate().find(hql) ;
return list;
}
@SuppressWarnings("unchecked")
public List<Things> pointFind(Object[] obj) {
String tj = "" ;
for(int i = 0 ; i<obj.length ; i++){
tj += "and".toString()+obj[i].toString()+"=".toString()+obj[i+1] ;
i++ ;
}
String hql = "from Things things where 0=0"+tj ;
List<Things> list = this.getHibernateTemplate().find(hql) ;
return list;
}
public void save(Things things) {
this.getHibernateTemplate().save(things) ;
}
public void update(Things things) {
this.getHibernateTemplate().update(things) ;
}
}
[color=#FF0000]ThingsService.java[/color]
____________________________________________________________
package com.lg.service;
import java.util.List;
import com.lg.bean.Things;
public interface ThingsService {
/**
* 保存一条记录
*/
public void save(Things thing) ;
/**
* 更新一条记录
*/
public void update(Things thing) ;
/**
* 删除一条记录
*/
public void delete(Integer id) ;
/**
* 查询单条记录
*/
public Things find(Integer id) ;
/**
* 查询所有记录
*/
public List<Things> findAll() ;
/**
* 按条件查询记录
*/
public List<Things> pointFind(Object[] obj) ;
}
ThingsServiceImpl.java
________________________________________________________
package com.lg.service.impl;
import java.util.List;
import com.lg.bean.Things;
import com.lg.dao.ThingsDao;
import com.lg.service.ThingsService;
public class ThingsServiceImpl implements ThingsService {
private ThingsDao thingsDao ;
public void setThingsDao(ThingsDao thingsDao) {
this.thingsDao = thingsDao;
}
public void delete(Integer id) {
thingsDao.delete(id) ;
}
public Things find(Integer id) {
return thingsDao.find(id);
}
public List<Things> findAll() {
return thingsDao.findAll();
}
public List<Things> pointFind(Object[] obj) {
return thingsDao.pointFind(obj);
}
public void save(Things thing) {
thingsDao.save(thing) ;
}
public void update(Things thing) {
thingsDao.update(thing) ;
}
}
[color=#FF0000]ThingsAction.java[/color]
_________________________________________________________
package com.lg.action;
import java.util.Map;
import com.lg.bean.Group;
import com.lg.bean.Things;
import com.lg.service.GroupService;
import com.lg.service.ThingsService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class ThingsAction extends ActionSupport {
private Things things ;
private Group group ;
private ThingsService thingsService ;
private GroupService groupService ;
public void setThings(Things things) {
System.out.println("in setThings");
this.things = things;
}
public Things getThings() {
System.out.println("in getThings");
return things;
}
public void setThingsService(ThingsService thingsService) {
this.thingsService = thingsService;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public void setGroupService(GroupService groupService) {
this.groupService = groupService;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
public String save(){
System.out.println(things.getName());
System.out.println(things.getDate());
System.out.println(things.getMoney());
System.out.println(things.getMoney());
System.out.println(things.getGid());
System.out.println(things.getDvalue());
thingsService.save(things) ;
return SUCCESS ;
}
@SuppressWarnings("unchecked")
public String forsave(){
Map request = (Map)ActionContext.getContext().get("request") ;
request.put("glist", groupService.getList()) ;
return SUCCESS ;
}
public String update(){
thingsService.update(things) ;
return SUCCESS ;
}
@SuppressWarnings("unchecked")
public String findAll(){
Map request = (Map)ActionContext.getContext().get("request") ;
request.put("list", thingsService.findAll()) ;
return SUCCESS ;
}
@SuppressWarnings("unchecked")
public String find(){
Map request = (Map)ActionContext.getContext().get("request") ;
request.put("list", thingsService.find(things.getId())) ;
return SUCCESS ;
}
public String delete(){
thingsService.delete(things.getId()) ;
return SUCCESS ;
}
}
[color=#FF0000]UserValidateInterceptor.java[/color]
________________________________________________________
package com.lg.interceptor;
import java.util.Map;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
@SuppressWarnings("serial")
public class UserValidateInterceptor extends AbstractInterceptor {
@SuppressWarnings("unchecked")
public String intercept(ActionInvocation ai) throws Exception {
Map session = ai.getInvocationContext().getSession() ;
String result = null ;
if(null!=session.get("user")){
result = ai.invoke() ;
}else{
result = Action.LOGIN ;
}
return result;
}
}
[color=#FF0000]DateFormate.java[/color]
_________________________________________________________
package com.lg.utils;
import java.util.Date;
public class DateFormate {
public static Date getDate(){
return new java.sql.Date((new Date()).getYear(),(new Date()).getMonth(),(new Date()).getDay()) ;
}
}
[color=#FF0000]struts.xml[/color]
_______________________________________________________
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="lvg" extends="struts-default">
<interceptors>
<interceptor name="userValidateInterceptor" class="com.lg.interceptor.UserValidateInterceptor" />
</interceptors>
<global-results>
<result name="login" type="redirect">/index.jsp</result>
</global-results>
<!-- User 相关的action -->
<action name="register" class="register">
<result name="success" type="redirect">/index.jsp</result>
<result name="input">/register.jsp</result>
</action>
<action name="login" class="login">
<result name="success" type="redirect">/main.jsp</result>
<result name="input">/index.jsp</result>
</action>
<!-- Group 相关的action -->
<action name="grouplist" class="group" method="getList">
<result name="success">/grouplist.jsp</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="deleteGroup" class="group" method="delete">
<result name="success" type="redirect">grouplist.action</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="updateGroup" class="group" method="getOne">
<result name="success">/update.jsp</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="update" class="group" method="update">
<result name="success" type="redirect">grouplist.action</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="saveGroup" class="group" method="save">
<result name="success" type="redirect">grouplist.action</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<!-- Things 相关的action -->
<action name="thingslist" class="things" method="findAll">
<result name="success">/thingslist.jsp</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="forsave" class="things" method="forsave">
<result name="success">/record.jsp</result>
<result name="input">thingslist.action</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="savethings" class="things" method="save">
<result name="success" type="redirect">thingslist.action</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="forupdatethings" class="things" method="find">
<result name="success">/update.jsp</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="updatethings" class="things" method="update">
<result name="success" type="redirect">thingslist.action</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="deletethings" class="things" method="delete">
<result name="success" type="redirect">thingslist.action</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
<action name="detail" class="things" method="delete">
<result name="success" type="redirect">thingslist.action</result>
<result name="input">/main.jsp</result>
<interceptor-ref name="userValidateInterceptor" />
<interceptor-ref name="defaultStack" />
</action>
</package>
</struts>
[color=#FF0000]applicationContext.xml[/color]
_________________________________________________________-
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/lg_data"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
<property name="maxActive" value="100"></property><!-- 最大活动连接数 -->
<property name="maxIdle" value="30"></property><!-- 最大可空闲的连接数 -->
<property name="maxWait" value="500"></property><!-- 最大可以等待的连接数 -->
<property name="defaultAutoCommit" value="true"></property><!-- 默认自动提交,true每执行完一次数据操作之后就自动提交,相当于没有事物-->
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/lg/bean/User.hbm.xml</value>
<value>com/lg/bean/Group.hbm.xml</value>
<value>com/lg/bean/Things.hbm.xml</value>
</list>
</property>
</bean>
<!-- User 相关的bean -->
<bean id="userDao" class="com.lg.dao.impl.UserDaoImpl" scope="prototype">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="userService" class="com.lg.service.impl.UserServiceImpl" scope="prototype">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="register" class="com.lg.action.RegisterAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<bean id="login" class="com.lg.action.LoginAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<!-- Group 相关的bean -->
<bean id="groupDao" class="com.lg.dao.impl.GroupDaoImpl" scope="prototype">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="groupService" class="com.lg.service.impl.GroupServiceImpl" scope="prototype">
<property name="groupDao" ref="groupDao"></property>
</bean>
<bean id="group" class="com.lg.action.GroupAction" scope="prototype">
<property name="groupService" ref="groupService"></property>
</bean>
<!-- Things 相关的bean -->
<bean id="thingsDao" class="com.lg.dao.impl.ThingsDaoImpl" scope="prototype">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="thingsService" class="com.lg.service.impl.ThingsServiceImpl" scope="prototype">
<property name="thingsDao" ref="thingsDao" />
</bean>
<bean id="things" class="com.lg.action.ThingsAction" scope="prototype">
<property name="thingsService" ref="thingsService" />
<property name="groupService" ref="groupService" />
</bean>
</beans>
[color=#FF0000]record.jsp[/color]
____________________________________________________________
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="lg" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>V1.0</title>
<link rel="stylesheet" type="text/css" href="style/class.css">
</head>
<body>
<lg:label value="%{getText('add.things')}" cssClass="title"></lg:label>
<lg:form action="savethings" method="post">
<lg:hidden name="things.mvalue" value="1"></lg:hidden>
<lg:textfield name="things.name" label="%{getText('name.things')}" id="name" cssClass="text"></lg:textfield>
<lg:textfield name="things.date" label="%{getText('date.things')}" id="date" cssClass="text"></lg:textfield>
<lg:textfield name="things.money" label="%{getText('money.things')}" id="money" cssClass="text"></lg:textfield>
<lg:select list="#{'0':'没用','1':'拿不定','2':'有用'}" label="%{getText('dayvalue.things')}" name="things.dvalue" cssClass="text" id="dvalue" />
<lg:select list="#request.glist" listKey="gid" listValue="gname" label="%{getText('groupname')}" name="things.gid" cssClass="text" id="gid"></lg:select>
<lg:submit value="::%{getText('submit')}::" name="submit"></lg:submit>
</lg:form>
</body>
</html>
希望大家多帮忙看看,小弟先谢过了……