• 客户信息维护jsp


    搭建好SSH环境后,实现对客户信息的操作:

    applicationContext.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"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.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/dbssh">
      </property>
      <property name="username" value="root"></property>
      <property name="password" value="123456"></property>
      <property name="maxActive" value="100"></property>
      <property name="maxWait" value="500"></property>
      <property name="defaultAutoCommit" value="true"></property>
     </bean>
     <!--sessionFactory配置与管理  -->
     <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/crm/bean/Cust.hbm.xml</value>
       </list>
      </property>
     </bean>
     
     <!--配置DAO  -->
     <bean id="custDao" class="com.crm.impl.CustDaoImpl">
      <property name="sessionFactory">
       <ref bean="sessionFactory"/>
      </property>
     </bean>
     
     <!--配置service  -->
     <bean id="custService" class="com.crm.service.impl.CustServiceImpl">
      <property name="custDao" ref="custDao"></property>
     </bean>
     
     <!--配置-新增SaveAction  -->
     <bean id="custSaveAction" class="com.crm.action.CustSaveAction">
      <property name="service" ref ="custService"></property>
     </bean>
     
     <!-- 配置-查询ListCustAction -->
     <bean id="listCustAction" class="com.crm.action.ListCustAction">
        <property name="custService" ref="custService"></property>
     </bean>
     <!--配置-删除deleteAction  -->
     <bean id="removeCustAction" class="com.crm.action.RemoveCustAction">
      <property name="service" ref="custService"></property>
     </bean>
     <!--配置-条件查询findCdtAction  -->
     <bean id="findCdtAction" class="com.crm.action.FindCustByCdtAction">
      <property name="findCdtService" ref="custService"></property>
     </bean>
     <!--配置-typeAction  -->
     <bean id="typeAction" class="com.crm.action.TypeAction">
     </bean> 
    </beans>

    struts.xml

    <?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="customer" extends="struts-default">
    <action name="saveCust" class="custSaveAction">
     <result name="input">/custAdd.jsp</result>
    </action>
    <!-- 查询 -->
    <action name="listCust" class="listCustAction">
    <result>/jsp/custInfo.jsp</result>
    </action>
    <!-- 删除 -->
    <action name="delectCust" class="removeCustAction">
    <result>/jsp/custInfo.jsp</result>
    </action>
    <!-- typeAction下拉列表 -->
    <action name="typeAction" class="typeAction">
    <result></result>
    </action>
    <!-- 条件查询 -->
    <action name="findCdtCustList" class="findCdtAction">
     <result>/jsp/custInfo.jsp</result>
    </action>
    </package>
    </struts>

    信息存储类CustSaveAction.java

    package com.crm.action;
    import com.crm.bean.Cust;
    import com.crm.service.CustService;
    import com.opensymphony.xwork2.ActionSupport;
    public class CustSaveAction extends ActionSupport{
     private CustService service;
     private Cust cust; 
     public Cust getCust() {
      return cust;
     }

     public void setCust(Cust cust) {
      this.cust = cust;
     }

     public CustService getService() {
      return service;
     }

     public void setService(CustService service) {
      this.service = service;
     }
     @Override
     public String execute() throws Exception {
      // TODO Auto-generated method stub
      this.service.saveCustomer(cust);
      return SUCCESS;
     } 
    }

    信息删除类RemoveCustAction.java

    package com.crm.action;
    import java.util.Map;
    import com.crm.service.CustService;
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;
    public class ListCustAction extends ActionSupport{
     /**
      *
      */
     private static final long serialVersionUID = 1L;
     private CustService custService; 
     public CustService getCustService() {
      return custService;
     }

     public void setCustService(CustService custService) {
      this.custService = custService;
     }
     @SuppressWarnings("unchecked")
     @Override
     public String execute() throws Exception {
      Map map = (Map)ActionContext.getContext().get("request");
      map.put("list", this.custService.findAllCust());
      return SUCCESS;
     }

    }

    按条件查询FindCustByCdtAction.java

    package com.crm.action;
    import java.util.Map;
    import com.crm.bean.Cust;
    import com.crm.service.CustService;
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;
    public class FindCustByCdtAction extends ActionSupport{
     private Cust cust;
     private CustService findCdtService;
     public Cust getCust() {
      return cust;
     }
     public void setCust(Cust cust) {
      this.cust = cust;
     }
     public CustService getFindCdtService() {
      return findCdtService;
     }
     public void setFindCdtService(CustService findCdtService) {
      this.findCdtService = findCdtService;
     }
     @SuppressWarnings({ "unchecked", "unchecked" })
     @Override
     public String execute() throws Exception {
      // TODO Auto-generated method stub
      Map map = (Map)ActionContext.getContext().get("request");
      map.put("list", this.findCdtService.findCustByCondition(cust));
      return SUCCESS;
     } 
    }

  • 相关阅读:
    hdu4971 流-最大权闭包
    hdu4971 流-最大权闭包
    hdu4950 打怪(简单题目)
    hdu4950 打怪(简单题目)
    hdu4941 map交换行列
    hdu4941 map交换行列
    hdu4966 最小树形图(最少辅导花费)
    hdu4966 最小树形图(最少辅导花费)
    hdu4965 巧用矩阵乘法结合律
    POJ 1077 && HDU 1043 Eight A*算法,bfs,康托展开,hash 难度:3
  • 原文地址:https://www.cnblogs.com/vincent-chan/p/7105733.html
Copyright © 2020-2023  润新知