簡單的struts+spring+hibernate配置實(shí)例 |
更新:2005-04-16 13:03:35 版本: 1.0 |
|
本文不關(guān)心必須的JAR包,這個(gè)東東在網(wǎng)上能夠找到很多,本文只關(guān)心如何配置,才能夠讓STRUTS SPRING HIBERNATE和MYSQL相關(guān)連。
<web.xml> --------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java./dtd/web-app_2_3.dtd"> <web-app id="WebApp"> <display-name>MVC_BPEL_MODELWeb</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/Hibernate_Context.xml</param-value> </context-param> <servlet> <servlet-name>SpringContextServlet</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>2</param-value> </init-param> <init-param> <param-name>validate</param-name> <param-value>true</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri> <taglib-location>/WEB-INF/struts-template.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri> <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> </taglib>
</web-app> ----------------------------------- <action-servlet.xml> ---------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www./dtd/spring-beans.dtd">
<beans> <bean name="/User" class="com.yaya.action.UserAction" singleton="false"> <property name="userManager"> <ref bean="userManager" /> </property> </bean>
</beans> ------------------------------------------------------------------- <hibernate_context.xml> -------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www./dtd/spring-beans.dtd">
<beans> <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> <property name="prefix"><value>/WEB-INF/jsp/</value></property> <property name="suffix"><value>.jsp</value></property> </bean> -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property>
<property name="url"> <value>jdbc:mysql://localhost/pdm</value> </property>
<property name="username"> <value>root</value> </property>
<property name="password"> <value></value> </property> </bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"> <ref local="dataSource" /> </property>
<property name="mappingResources"> <list> <value>hbm_tb/TSysuser.hbm.xml</value> </list> </property>
<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean>
<!-- Spring的數(shù)據(jù)訪問異常轉(zhuǎn)換器(Data Access Exception Translator)定義 --> <bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator"> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean>
<!-- Hibernate Template定義 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate.HibernateTemplate"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> <property name="jdbcExceptionTranslator"> <ref bean="jdbcExceptionTranslator" /> </property> </bean>
<!--baseTransactionProxy --> <bean abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" id="baseTransactionProxy"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="find*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean>
<bean id="userDao" class="com.yaya.service.dao.hibernate.UserHibernateDao"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean>
<bean id="userManagerTarget" class="com.yaya.service.spring.UserManagerImpl"> <property name="userDao"> <ref local="userDao" /> </property> </bean>
<bean id="userManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="transactionManager" /> </property>
<property name="target"> <ref local="userManagerTarget" /> </property>
<property name="proxyTargetClass"> <value>true</value> </property> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean>
</beans> ------------------------------------------------------------------- <struts-config.xml> ------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta./struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- 數(shù)據(jù)源 --> <data-sources></data-sources>
<!-- 表單 Bean --> <form-beans> <form-bean name="UserActionForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="User" type="com.yaya.actionform.UserActionForm" /> </form-bean> </form-beans>
<!-- 全局異常 --> <global-exceptions></global-exceptions>
<!-- 全局轉(zhuǎn)發(fā) --> <global-forwards></global-forwards>
<!-- 操作映射 --> <action-mappings> <action path="/User" type="org.springframework.web.struts.DelegatingActionProxy" name="UserActionForm" scope="request" parameter="method" validate="false"> <forward name="list" path="/userlist.jsp" /> <forward name="edit" path="/userform.jsp" /> </action>
</action-mappings>
<!-- 消息資源 --> <message-resources parameter="mvc_bpel_modelweb.resources.ApplicationResources" /> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml" /> </plug-in>
</struts-config> ------------------------------------------------------------------ UserHibernateDao.java ------------------------------------------------------------------ /* * 創(chuàng)建日期 2005-4-7 * * 更改所生成文件模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ package com.yaya.service.dao.hibernate;
import java.util.List;
import org.springframework.orm.ObjectRetrievalFailureException; import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.yaya.hb.TSysuser; import com.yaya.service.dao.IUserDao; import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/** * @author Administrator * * 更改所生成類型注釋的模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ public class UserHibernateDao extends HibernateDaoSupport implements IUserDao {
private Log log = LogFactory.getLog(UserHibernateDao.class);
/* (非 Javadoc)
* @see com.jandar.dao.IUserDAO#getUsers()
*/
public List getUsers() {
return getHibernateTemplate().find("from TSysuser");
}
/* (非 Javadoc)
* @see com.jandar.dao.IUserDAO#getUser(java.lang.Long)
*/
public TSysuser getUser(String username) {
// TODO 自動(dòng)生成方法存根 //String msg = getHibernateTemplate().get(TSysuser.class,username).toString(); TSysuser user = (TSysuser) getHibernateTemplate().get(TSysuser.class,username); //TSysuser user = (TSysuser) getHibernateTemplate().find("from TSysuser where username = ?",username); System.out.println(user.getUserdesc()); System.out.println(user.getHeadship()); if (user == null) { throw new ObjectRetrievalFailureException(TSysuser.class, username); } return user; }
/* (非 Javadoc)
* @see com.jandar.dao.IUserDAO#saveUser(com.jandar.model.User)
*/
public void saveUser(TSysuser user) {
log.debug("xxxxxxx");
System.out.println("yyyy");
getHibernateTemplate().saveOrUpdate(user);
if (log.isDebugEnabled()) {
log.debug("username set to " + user.getUsername());
}
}
/* (非 Javadoc)
* @see com.jandar.dao.IUserDAO#removeUser(java.lang.Long)
*/
public void removeUser(String username) {
Object user = getHibernateTemplate().load(TSysuser.class, username);
getHibernateTemplate().delete(user);
if (log.isDebugEnabled()) {
log.debug("del user " + username);
}
}
} ------------------------------------------------------------------- useraction.java -------------------------------------------------------------------- /* * 創(chuàng)建日期 2005-4-11 * * 更改所生成文件模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ package com.yaya.action;
import java.util.Date;
import org.apache.struts.actions.DispatchAction; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.locale.converters.DateLocaleConverter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; import org.apache.struts.action.DynaActionForm; import org.apache.struts.util.MessageResources;
import com.yaya.hb.TSysuser; import com.yaya.service.spring.UserManagerImpl; /** * @author Administrator * * 更改所生成類型注釋的模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ public class UserAction extends DispatchAction {
private static Log log = LogFactory.getLog(UserAction.class); private UserManagerImpl mgr = null; public void setUserManager(UserManagerImpl userManager) { this.mgr = userManager; }
public ActionForward delete( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("entering ‘delete‘ method..."); } mgr.removeUser(request.getParameter("user.username")); ActionMessages messages = new ActionMessages(); messages.add( ActionMessages.GLOBAL_MESSAGE, new ActionMessage("user.deleted")); saveMessages(request, messages); return list(mapping, form, request, response); }
public ActionForward edit( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("entering ‘edit‘ method..."); }
DynaActionForm userForm = (DynaActionForm) form; String username = request.getParameter("username");
// null userId indicates an add if (username != null) { try { TSysuser user = mgr.getUser(username); if (user == null) { ActionMessages errors = new ActionMessages(); errors.add( ActionMessages.GLOBAL_MESSAGE, new ActionMessage("user.missing")); saveErrors(request, (ActionErrors) errors); return mapping.findForward("list"); } userForm.set("user", user); request.setAttribute("user",user); } catch(Exception e) { e.printStackTrace(); }
} return mapping.findForward("edit"); }
public ActionForward list( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("entering ‘list‘ method..."); } request.setAttribute("users", mgr.getUsers()); return mapping.findForward("list"); }
public ActionForward save( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (log.isDebugEnabled()) { log.debug("entering ‘save‘ method..."); }
if (isCancelled(request)) { return list(mapping, form, request, response); }
// run validation rules on this form ActionMessages errors = form.validate(mapping, request);
if (!errors.isEmpty()) { saveErrors(request, (ActionErrors) errors);
return mapping.findForward("edit"); } DynaActionForm userForm = (DynaActionForm) form; TSysuser user = (TSysuser) userForm.get("username");
mgr.saveUser(user);
ActionMessages messages = new ActionMessages(); messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("user.saved", user.getUsername())); saveMessages((HttpServletRequest) request.getSession(), messages);
return mapping.findForward("users"); }
public ActionForward unspecified( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return list(mapping, form, request, response); }
} ------------------------------------------------------------------- UserMenuActionForm.java ------------------------------------------------------------------- /* * 創(chuàng)建日期 2005-3-28 * * 更改所生成文件模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ package com.yaya.actionform;
import java.sql.Date;
import org.apache.struts.action.ActionForm;
/** * @author Administrator * * 更改所生成類型注釋的模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ public class UserMenuActionForm extends ActionForm {
/** identifier field */ private String username;
/** identifier field */ private String fitemcode;
/** identifier field */ private String itemcode;
/** identifier field */ private String itemdesc;
/** identifier field */ private String itemtype;
/** identifier field */ private Integer itemid;
/** identifier field */ private String lastmodif;
/** identifier field */ private Date lastmdate;
/** identifier field */ private String creadtor;
/** identifier field */ private Date creatdate;
/** identifier field */ private String title;
/** identifier field */ private String url;
/** identifier field */ private String target;
/** identifier field */ private String icon;
/** identifier field */ private String iconopen;
/** identifier field */ private Integer open;
/** identifier field */ private Integer id;
/** identifier field */ private Integer pid;
public String getUsername() { return this.username; }
public void setUsername(String username) { this.username = username; }
public String getFitemcode() { return this.fitemcode; }
public void setFitemcode(String fitemcode) { this.fitemcode = fitemcode; }
public String getItemcode() { return this.itemcode; }
public void setItemcode(String itemcode) { this.itemcode = itemcode; }
public String getItemdesc() { return this.itemdesc; }
public void setItemdesc(String itemdesc) { this.itemdesc = itemdesc; }
public String getItemtype() { return this.itemtype; }
public void setItemtype(String itemtype) { this.itemtype = itemtype; }
public Integer getItemid() { return this.itemid; }
public void setItemid(Integer itemid) { this.itemid = itemid; }
public String getLastmodif() { return this.lastmodif; }
public void setLastmodif(String lastmodif) { this.lastmodif = lastmodif; }
public Date getLastmdate() { return this.lastmdate; }
public void setLastmdate(Date lastmdate) { this.lastmdate = lastmdate; }
public String getCreadtor() { return this.creadtor; }
public void setCreadtor(String creadtor) { this.creadtor = creadtor; }
public Date getCreatdate() { return this.creatdate; }
public void setCreatdate(Date creatdate) { this.creatdate = creatdate; }
public String getTitle() { return this.title; }
public void setTitle(String title) { this.title = title; }
public String getUrl() { return this.url; }
public void setUrl(String url) { this.url = url; }
public String getTarget() { return this.target; }
public void setTarget(String target) { this.target = target; }
public String getIcon() { return this.icon; }
public void setIcon(String icon) { this.icon = icon; }
public String getIconopen() { return this.iconopen; }
public void setIconopen(String iconopen) { this.iconopen = iconopen; }
public Integer getOpen() { return this.open; }
public void setOpen(Integer open) { this.open = open; } public Integer getId() { return this.id; }
public void setId(Integer id) { this.id = id; }
public Integer getPid() { return this.pid; }
public void setPid(Integer pid) { this.pid = pid; }
} ------------------------------------------------------------------ package com.yaya.hb;
import java.io.InputStream; import java.io.Serializable; import java.util.Date; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */ public class TSysuser implements Serializable {
/** identifier field */ private String username;
/** identifier field */ private String userdesc;
/** identifier field */ private String passwords;
/** identifier field */ private String deptno;
/** identifier field */ private String headship;
/** identifier field */ private String sex;
/** identifier field */ private String tel;
/** identifier field */ private String email;
/** identifier field */ private String url;
/** identifier field */ private String pcall;
/** identifier field */
/** identifier field */ private String userphoto;
/** identifier field */ private Integer facerefutime;
/** identifier field */ private String facelanguage;
/** identifier field */ private String lastmodif;
/** identifier field */ private Date lastmdate;
/** identifier field */ private String creadtor;
/** identifier field */ private Date creatdate;
/** full constructor */ public TSysuser(String username, String userdesc, String passwords, String deptno, String headship, String sex, String tel, String email, String url, String pcall, InputStream userimage, String userphoto, Integer facerefutime, String facelanguage, String lastmodif, Date lastmdate, String creadtor, Date creatdate) { this.username = username; this.userdesc = userdesc; this.passwords = passwords; this.deptno = deptno; this.headship = headship; this.sex = sex; this.tel = tel; this.email = email; this.url = url; this.pcall = pcall; this.userphoto = userphoto; this.facerefutime = facerefutime; this.facelanguage = facelanguage; this.lastmodif = lastmodif; this.lastmdate = lastmdate; this.creadtor = creadtor; this.creatdate = creatdate; }
/** default constructor */ public TSysuser() { }
public String getUsername() { return this.username; }
public void setUsername(String username) { this.username = username; }
public String getUserdesc() { return this.userdesc; }
public void setUserdesc(String userdesc) { this.userdesc = userdesc; }
public String getPasswords() { return this.passwords; }
public void setPasswords(String passwords) { this.passwords = passwords; }
public String getDeptno() { return this.deptno; }
public void setDeptno(String deptno) { this.deptno = deptno; }
public String getHeadship() { return this.headship; }
public void setHeadship(String headship) { this.headship = headship; }
public String getSex() { return this.sex; }
public void setSex(String sex) { this.sex = sex; }
public String getTel() { return this.tel; }
public void setTel(String tel) { this.tel = tel; }
public String getEmail() { return this.email; }
public void setEmail(String email) { this.email = email; }
public String getUrl() { return this.url; }
public void setUrl(String url) { this.url = url; }
public String getPcall() { return this.pcall; }
public void setPcall(String pcall) { this.pcall = pcall; }
public String getUserphoto() { return this.userphoto; }
public void setUserphoto(String userphoto) { this.userphoto = userphoto; }
public Integer getFacerefutime() { return this.facerefutime; }
public void setFacerefutime(Integer facerefutime) { this.facerefutime = facerefutime; }
public String getFacelanguage() { return this.facelanguage; }
public void setFacelanguage(String facelanguage) { this.facelanguage = facelanguage; }
public String getLastmodif() { return this.lastmodif; }
public void setLastmodif(String lastmodif) { this.lastmodif = lastmodif; }
public Date getLastmdate() { return this.lastmdate; }
public void setLastmdate(Date lastmdate) { this.lastmdate = lastmdate; }
public String getCreadtor() { return this.creadtor; }
public void setCreadtor(String creadtor) { this.creadtor = creadtor; }
public Date getCreatdate() { return this.creatdate; }
public void setCreatdate(Date creatdate) { this.creatdate = creatdate; }
public String toString() { return new ToStringBuilder(this) .append("username", getUsername()) .append("userdesc", getUserdesc()) .append("passwords", getPasswords()) .append("deptno", getDeptno()) .append("headship", getHeadship()) .append("sex", getSex()) .append("tel", getTel()) .append("email", getEmail()) .append("url", getUrl()) .append("pcall", getPcall()) .append("userphoto", getUserphoto()) .append("facerefutime", getFacerefutime()) .append("facelanguage", getFacelanguage()) .append("lastmodif", getLastmodif()) .append("lastmdate", getLastmdate()) .append("creadtor", getCreadtor()) .append("creatdate", getCreatdate()) .toString(); }
public boolean equals(Object other) { if ( !(other instanceof TSysuser) ) return false; TSysuser castOther = (TSysuser) other; return new EqualsBuilder() .append(this.getUsername(), castOther.getUsername()) .append(this.getUserdesc(), castOther.getUserdesc()) .append(this.getPasswords(), castOther.getPasswords()) .append(this.getDeptno(), castOther.getDeptno()) .append(this.getHeadship(), castOther.getHeadship()) .append(this.getSex(), castOther.getSex()) .append(this.getTel(), castOther.getTel()) .append(this.getEmail(), castOther.getEmail()) .append(this.getUrl(), castOther.getUrl()) .append(this.getPcall(), castOther.getPcall()) .append(this.getUserphoto(), castOther.getUserphoto()) .append(this.getFacerefutime(), castOther.getFacerefutime()) .append(this.getFacelanguage(), castOther.getFacelanguage()) .append(this.getLastmodif(), castOther.getLastmodif()) .append(this.getLastmdate(), castOther.getLastmdate()) .append(this.getCreadtor(), castOther.getCreadtor()) .append(this.getCreatdate(), castOther.getCreatdate()) .isEquals(); }
public int hashCode() { return new HashCodeBuilder() .append(getUsername()) .append(getUserdesc()) .append(getPasswords()) .append(getDeptno()) .append(getHeadship()) .append(getSex()) .append(getTel()) .append(getEmail()) .append(getUrl()) .append(getPcall()) .append(getUserphoto()) .append(getFacerefutime()) .append(getFacelanguage()) .append(getLastmodif()) .append(getLastmdate()) .append(getCreadtor()) .append(getCreatdate()) .toHashCode(); }
} --------------------------------------------------------------------- /* * 創(chuàng)建日期 2005-4-11 * * 更改所生成文件模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ package com.yaya.service;
import java.util.List;
import com.yaya.hb.TSysuser; import com.yaya.service.dao.IUserDao;
/** * @author Administrator * * 更改所生成類型注釋的模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ public interface IUserManager { public void setUserDAO(IUserDao dao); public TSysuser getUser(String username); public List getUsers(); public TSysuser saveUser(TSysuser user); public void removeUser(String username);
} -------------------------------------------------------------------- /* * 創(chuàng)建日期 2005-4-7 * * 更改所生成文件模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ package com.yaya.service.dao; /** * @author Administrator * * 更改所生成類型注釋的模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ public interface IDAO {
} -------------------------------------------------------------- /* * 創(chuàng)建日期 2005-4-11 * * 更改所生成文件模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ package com.yaya.service.dao;
import java.util.List;
import com.yaya.hb.TSysuser;
/** * @author Administrator * * 更改所生成類型注釋的模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ public interface IUserDao extends IDAO {
public List getUsers(); public TSysuser getUser(String username); public void saveUser(TSysuser user); public void removeUser(String username); } ---------------------------------------------------------- /* * 創(chuàng)建日期 2005-4-11 * * 更改所生成文件模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ package com.yaya.service.spring;
import com.yaya.hb.TSysuser; import com.yaya.service.IUserManager; import com.yaya.service.dao.IUserDao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; /** * @author Administrator * * 更改所生成類型注釋的模板為 * 窗口 > 首選項(xiàng) > Java > 代碼生成 > 代碼和注釋 */ public class UserManagerImpl implements IUserManager { private static Log log = LogFactory.getLog(UserManagerImpl.class);
public IUserDao userDao;
/**
* @return 返回 userDao。
*/
public void setUserDAO(IUserDao dao) { this.userDao = dao; }
public IUserDao getUserDao() { return userDao; } /**
* @param userDao 要設(shè)置的 userDao。
*/
public void setUserDao(IUserDao userDao) {
this.userDao = userDao;
}
public TSysuser getUser(String username) {
try { TSysuser user = userDao.getUser(username); return user; } catch(Exception e) { e.printStackTrace(); } return userDao.getUser(username);
}
/* (非 Javadoc)
* @see com.jandar.service.IUserManager#getUsers()
*/
public List getUsers() { // TODO 自動(dòng)生成方法存根 return userDao.getUsers(); } /* (非 Javadoc)
* @see com.jandar.service.IUserManager#saveUser(com.jandar.model.User)
*/
public TSysuser saveUser(TSysuser user) { // TODO 自動(dòng)生成方法存根 userDao.saveUser(user); return user; }
/* (非 Javadoc)
* @see com.jandar.service.IUserManager#removeUser(java.lang.String)
*/ public void removeUser(String username) { // TODO 自動(dòng)生成方法存根 userDao.removeUser(username); } }
|
|
|
|