• ssh集成


    导入pom依赖

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.hmc</groupId>
      <artifactId>ssh2</artifactId>
      <packaging>war</packaging>
      <version>0.0.1-SNAPSHOT</version>
      <name>ssh2 Maven Webapp</name>
      <url>http://maven.apache.org</url>
      
      <properties>
      <!--1.hibernate相关  -->
      <hibernate.version>5.2.12.Final</hibernate.version>
      <!--mysql+  -->
      <mysql.version>5.1.44</mysql.version>
      <!--2.spring相关  -->
       <spring.vesion>5.0.1.RELEASE </spring.vesion>
      <!--3.struts2相关  -->
      <struts2.vesion>2.5.16</struts2.vesion>
      <!--4.lo4j+slf4j相关  -->
      <slf4j.version>1.7.7</slf4j.version>
      <log4j.version>2.9.1</log4j.version>
      <log4j.disruptor.version>3.2.0</log4j.disruptor.version>
      <!--5.junit+servlet  -->
       <junit.vesion>4.12</junit.vesion>
       <servlet.vesion>4.0.0</servlet.vesion>
      <!--6.jstl+standard  -->
      <jstl.version>1.2</jstl.version>
       <standard.version>1.1.2</standard.version>
      <!--7.tomcat-jsp-api  -->
       <tomcat.jsp.version>8.0.46</tomcat.jsp.version>
      <!--8.jackson  -->
     
      
      
     
      </properties>
       <dependencies>
       <!--1.hibernate相关  -->
       <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
      </dependency>
       
       
        <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>${hibernate.version}</version>
       </dependency>
       
        <!--ehche  -->
         <dependency>
              <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.10.0</version>
         </dependency>
       
       <!--hibernate与ehcache的二级缓存配置  -->
         <dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-ehcache</artifactId>
            <version>${hibernate.version}</version>
          </dependency>
          
          
         <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>${mysql.version}</version>
        </dependency> 
          
          
         <!--2.spring相关  -->
          <!--spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.vesion}</version>
        </dependency>
       
       <!--spring -core  -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core </artifactId>
            <version>${spring.vesion}</version>
        </dependency>
        
       <!--spring-orm  -->
       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm </artifactId>
            <version>${spring.vesion}</version>
        </dependency>
       <!--spring-web  -->
       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web </artifactId>
            <version>${spring.vesion}</version>
        </dependency>
       <!--spring-aspects  -->
       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects </artifactId>
            <version>${spring.vesion}</version>
        </dependency>
       
         <!--3.struts2相关  -->
        <dependency>
          <groupId>org.apache.struts</groupId>
          <artifactId>struts2-core</artifactId>
          <version>${struts2.vesion}</version>
        </dependency>
         
          <dependency>
          <groupId>org.apache.struts</groupId>
          <artifactId>struts2-spring-plugin</artifactId>
          <version>${struts2.vesion}</version>
        </dependency>
         
         <!--4.lo4j+slf4j相关  -->
         <!-- log配置:Log4j2 + Slf4j -->
            <!-- slf4j核心包 -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>${slf4j.version}</version>
                <scope>runtime</scope>
            </dependency>
    
            <!--用于与slf4j保持桥接 -->
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-slf4j-impl</artifactId>
                <version>${log4j.version}</version>
            </dependency>
    
            <!--核心log4j2jar包 -->
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-core</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            
            <!--web工程需要包含log4j-web,非web工程不需要 -->
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-web</artifactId>
                <version>${log4j.version}</version>
                <scope>runtime</scope>
            </dependency>
            <!--需要使用log4j2的AsyncLogger需要包含disruptor -->
            <dependency>
                <groupId>com.lmax</groupId>
                <artifactId>disruptor</artifactId>
                <version>${log4j.disruptor.version}</version>
            </dependency>
         
         
         
         <!--5.junit+servlet  -->
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>${junit.vesion}</version>
          <scope>test</scope>
        </dependency>
        
        
        
        
        <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
       <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet.vesion}</version>
        <scope>provided</scope>
       </dependency>
       
       
       <!--6.jstl+standard  -->
       <!-- https://mvnrepository.com/artifact/jstl/jstl -->
       <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>${jstl.version}</version>
       </dependency>
        
        
        <!-- https://mvnrepository.com/artifact/taglibs/standard -->
       <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>${standard.version}</version>
       </dependency>
      
       <!--7.tomcat-jsp-api  -->
      <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jsp-api</artifactId>
        <version>${tomcat.jsp.version}</version>
       </dependency>
      </dependencies>
      <build>
        <finalName>ssh2</finalName>
         <plugins>
         <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
        </plugins>
      </build>
    </project>

    spring-hibernate.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:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    
        <!--1.注入数据库配置文件db.properties -->
        <context:property-placeholder
            location="classpath:db.properties" />
        <!--2.配置c3p0连接池 -->
        <bean id="dataSource"
            class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="user" value="${db.username}"></property>
            <property name="password" value="${db.password}"></property>
            <property name="driverClass" value="${db.driverClass}"></property>
            <property name="jdbcUrl" value="${db.jdbcUrl}"></property>
    
            <!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
            <property name="initialPoolSize"
                value="${db.initialPoolSize}"></property>
            <!--连接池中保留的最大连接数。Default: 15 -->
            <property name="maxPoolSize" value="${db.maxPoolSize}"></property>
            <!--连接池中保留的最小连接数。 -->
            <property name="minPoolSize" value="${db.minPoolSize}" />
            <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
            <property name="maxIdleTime" value="${db.maxIdleTime}" />
    
            <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
            <property name="acquireIncrement"
                value="${db.acquireIncrement}" />
    
            <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。 
                所以设置这个参数需要考虑到多方面的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 
                0 -->
            <property name="maxStatements" value="${db.maxStatements}" />
    
            <!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
            <property name="idleConnectionTestPeriod"
                value="${db.idleConnectionTestPeriod}" />
    
            <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->
            <property name="acquireRetryAttempts"
                value="${db.acquireRetryAttempts}" />
    
            <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。 
                如果设为true,那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
            <property name="breakAfterAcquireFailure"
                value="${db.breakAfterAcquireFailure}" />
    
            <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod 
                或automaticTestTable 等方法来提升连接测试的性能。Default: false -->
            <property name="testConnectionOnCheckout"
                value="${db.breakAfterAcquireFailure}" />
        </bean>
    
        <!--3.注册LocalSessionFactoryBean,spring与hibernate集成,舍弃hibernate.cfg.xml核心配置文件 -->
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <!-- 数据源 -->
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
            <!-- hibernate相关属性 -->
            <property name="hibernateProperties">
                <props>
                    <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <!--spring与Hibernate集成无法显示sql语句问题,请见集成后hibernate无法显示sql语句.txt -->
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hibernate.connection.autocommit">false</prop>
                </props>
            </property>
            <!-- 实体映射文件 -->
            <property name="mappingResources">
                <list>
                    <!-- <value>com/hmc/book/entity/Book/hbm/xml</value> -->
                    <value>com/hmc/book/entity/Book.hbm.xml</value>
                </list>
            </property>
        </bean>
    
    
        <!--4.spring声明式事务 -->
        <!--1) 开启自动代理 -->
        <aop:aspectj-autoproxy />
    
        <!--2) 事务管理器 -->
        <bean id="transactionManager"
            class="org.springframework.orm.hibernate5.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
    
        <!--3) 定义事务特性 -->
        <tx:advice id="txAdvice"
            transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="add*" propagation="REQUIRED" />
                <tx:method name="save*" propagation="REQUIRED" />
                <tx:method name="insert*" propagation="REQUIRED" />
    
                <tx:method name="edit*" propagation="REQUIRED" />
                <tx:method name="update*" propagation="REQUIRED" />
    
                <tx:method name="del*" propagation="REQUIRED" />
                <tx:method name="remove*" propagation="REQUIRED" />
    
                <tx:method name="load*" propagation="REQUIRED"
                    read-only="true" />
                <tx:method name="list*" propagation="REQUIRED"
                    read-only="true" />
                <tx:method name="select*" propagation="REQUIRED"
                    read-only="true" />
                <tx:method name="query*" propagation="REQUIRED"
                    read-only="true" />
    
                <tx:method name="do*" propagation="REQUIRED" />
            </tx:attributes>
        </tx:advice>
    
        <!--4) 定义切入点 -->
        <!--适配器=通知+切入点 通知:环绕事务管理通知 切入点: -->
        <aop:config>
            <!-- pointcut属性用来定义一个切入点,分成四个部分理解 [* ][*..][*Biz][.*(..)] -->
            <!-- A: 返回类型,*表示返回类型不限 -->
            <!-- B: 包名,*..表示包名不限 -->
            <!-- C: 类或接口名,*Biz表示类或接口必须以Biz结尾 -->
            <!-- D: 方法名和参数,*(..)表示方法名不限,参数类型和个数不限 -->
    
            <aop:advisor advice-ref="txAdvice"
                pointcut="execution(* *..*Biz.*(..))" />
        </aop:config>
    
    
    
        <!--5.注入HibernateTemplate模板 -->
        <bean id="hibernateTemplate"
            class="org.springframework.orm.hibernate5.HibernateTemplate">
            <property name="sessionFactory" ref="sessionFactory"></property>
        </bean>
    
        <!--6.分包分模块开发 -->
        <!--BaseDao -->
        <bean id="baseDao" class="com.hmc.base.dao.BaseDao"
            >
            <property name="hibernateTemplate" ref="hibernateTemplate"></property>
        </bean>
    
        <!--baseBiz -->
        <bean id="baseBiz" class="com.hmc.base.biz.BaseBiz"
            abstract="true">
        </bean>
    
        <!--BaseAction -->
        <bean id="baseAction" class="com.hmc.base.action.BaseAction"
            abstract="true">
    
        </bean>
    
    </beans>

    db.properties

     spring-book.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:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    
      <!--注册bookDao  -->
      <bean id="bookDao" class="com.hmc.book.dao.imp.BookDaoImpl" parent="baseDao">
      <property name="baseDao" ref="baseDao"></property>
      </bean>
      
      <!-- 注册BookBiz -->
      <bean id="bookBiz" class="com.hmc.book.biz.impl.BookBizImpl" parent="baseBiz">
      <property name="bookDao" ref="bookDao"></property>  
      </bean>
      
      <!-- 注册BookAction -->
      <bean id="bookAction" class="com.hmc.book.action.BookAction" scope="prototype" parent="baseAction">
       <property name="bookBiz" ref="bookBiz"></property>
      </bean>
    </beans>

     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:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
        <import resource="spring_xml/spring-hibernate.xml"/>
        <import resource="spring_xml/spring-book.xml"/>
    </beans>

    struts-book.xml

    <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
    <struts>
    <!--
    name:包名
    extends:继承默认struts2的配置,一般叫struts-default
    abstract:是否抽象包
    name:命名空间
      -->
         <package name="struts-book"  extends="struts-base">
          
         <action name="bookAction_*" class="bookAction" method="{1}">
         <result name="list">
         /rs.jsp
         </result>
         
         </action>
          
         
         </package>
          
    
    </struts>

     struts-base.xml

    <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
    <struts>
        <!--开启struts2的开发模式  -->
        <constant name="struts.devMode" value="true"></constant>
        <!-- 启用struts2配置文件自动加载模式 -->
        <constant name="struts.configuration.xml.reload" value="true"></constant>
         
      <!-- 将action创建交由spring容器来管理 -->
      <constant name="struts.objectFactory" value="spring"></constant>
        <package name="struts-base" abstract="true" extends="struts-default">
        <!--开启struts2动态方法调用  -->
        <global-allowed-methods>regex:.*</global-allowed-methods>
        </package>
    </struts>

     struts.xml

    <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
    <struts>
        <include file="struts_xml/struts-base.xml"></include>
        <include file="struts_xml/struts-book.xml"></include>
    </struts>

     BaseAction

    package com.hmc.base.action;
    
    import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    import org.apache.struts2.interceptor.ServletRequestAware;
    import org.apache.struts2.interceptor.ServletResponseAware;
    
    public abstract class BaseAction implements ServletRequestAware,ServletResponseAware{
    
    
        protected HttpServletResponse response;
        protected HttpServletRequest request;
        protected HttpSession session;
        protected ServletContext application;
        
        @Override
        public void setServletRequest(HttpServletRequest request) {
            // TODO Auto-generated method stub
            this.request=request;
            this.session=request.getSession();
            this.application= request.getServletContext();
        }
        
        
        @Override
        public void setServletResponse(HttpServletResponse response) {
            // TODO Auto-generated method stub
            this.response=response;
        }
    }

    Book.java

    package com.hmc.book.entity;
    
    import java.io.Serializable;
    
    public class Book implements Serializable {
        private Integer bid;
        private String bname;
        private Float price;
        private String image;
    
        public Integer geatBid() {
            return bid;
        }
    
        public void setBid(Integer bid) {
            this.bid = bid;
        }
    
    
    
        public String getBname() {
            return bname;
        }
    
        public void setBname(String bname) {
            this.bname = bname;
        }
    
        public Float getPrice() {
            return price;
        }
    
        public void setPrice(Float price) {
            this.price = price;
        }
    
        public String getImage() {
            return image;
        }
    
        public void setImage(String image) {
            this.image = image;
        }
    
        public Book() {
            super();
        }
    
        @Override
        public String toString() {
            return "Book [bid=" + bid + ", bookame=" + bname + ", price=" + price + ", image=" + image + "]";
        }
    
    }

    Book.hbm.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
        
    <hibernate-mapping>
         <class name="com.hmc.book.entity.Book" table="t_mvc_book">
         <id name="bid" type="java.lang.Integer" column="bid">
           <generator class="native"></generator>
         </id>
         <property name="bname" type="java.lang.String" column="bname"/>
         <property name="price" type="java.lang.Float" column="price"/>
         <property name="image" type="java.lang.String" column="image"/>
         </class>
        
        
    </hibernate-mapping>

    IBookDao

    package com.hmc.book.dao;
    
    import java.util.List;
    
    import com.hmc.base.util.PageBean;
    import com.hmc.book.entity.Book;
    
    public interface IBookDao {
        
      public void addBook(Book book);
      public void editBook(Book book);
      public void deleBook(Book book);
      
      public Book getBook(Book book);
      public List<Book> queryBookPager(Book book,PageBean pageBean);
      
      
    }

    BookDaoImpl

    package com.hmc.book.dao.imp;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.Transaction;
    import org.hibernate.query.Query;
    import org.springframework.orm.hibernate5.HibernateCallback;
    
    import com.hmc.base.dao.BaseDao;
    import com.hmc.base.util.PageBean;
    import com.hmc.base.util.StringUtils;
    import com.hmc.book.dao.IBookDao;
    import com.hmc.book.entity.Book;
    
    public class BookDaoImpl  extends BaseDao implements IBookDao{
    
        private BaseDao baseDao=new BaseDao();
        
        public BaseDao getBaseDao() {
            return baseDao;
        }
    
        public void setBaseDao(BaseDao baseDao) {
            this.baseDao = baseDao;
        }
    
        @Override
        public void addBook(Book book) {
            // TODO Auto-generated method stub
            this.getHibernateTemplate().save(book);
        }
    
        @Override
        public void editBook(Book book) {
            // TODO Auto-generated method stub
            Book b = this.getBook(book);
            if(null!=b) {
                
                this.getHibernateTemplate().update(b);
            }
        }
    
        @Override
        public void deleBook(Book book) {
            // TODO Auto-generated method stub
            Book b = this.getBook(book);
            if(null!=b) {
                
            this.getHibernateTemplate().delete(b);
            }
            }
    
        @Override
        public Book getBook(Book book) {
            // TODO Auto-generated method stub
            Book book2 = this.getHibernateTemplate().get(Book.class, book.getBid());
         return book2;
        }
    
        @Override
        public List<Book> queryBookPager(Book book, PageBean pageBean) {
            
        return    this.getHibernateTemplate().execute(new HibernateCallback<List<Book>>() {
    
                public List<Book> doInHibernate(Session session) throws HibernateException {
                    // TODO Auto-generated method stub
                    String hql="from Book";
                    Query query = session.createQuery(hql);
                    //设置分页参数
                    query.setFirstResult(pageBean.getStartIndex());
                    query.setMaxResults(pageBean.getRows());
                    return query.list();
                }
            });
        
        }
    
    }

    IBookBiz

    package com.hmc.book.biz;
    
    import java.util.List;
    
    import com.hmc.base.util.PageBean;
    import com.hmc.book.entity.Book;
    
    public interface IBookBiz {
         public void addBook(Book book);
          public void editBook(Book book);
          public void deleBook(Book book);
          
          public Book getBook(Book book);
          public List<Book> queryBookPager(Book book,PageBean pageBean);
          
    }

    BookBizImpl

    package com.hmc.book.biz.impl;
    
    import java.util.List;
    
    import com.hmc.base.biz.BaseBiz;
    import com.hmc.base.util.PageBean;
    import com.hmc.book.biz.IBookBiz;
    import com.hmc.book.dao.IBookDao;
    import com.hmc.book.entity.Book;
    
    public class BookBizImpl extends BaseBiz implements IBookBiz{
    
        private IBookDao bookDao;
        
        public IBookDao getBookDao() {
            return bookDao;
        }
    
        public void setBookDao(IBookDao bookDao) {
            this.bookDao = bookDao;
        }
    
        @Override
        public void addBook(Book book) {
            // TODO Auto-generated method stub
            bookDao.addBook(book);
        }
    
        @Override
        public void editBook(Book book) {
            // TODO Auto-generated method stub
            bookDao.editBook(book);
        }
    
        @Override
        public void deleBook(Book book) {
            // TODO Auto-generated method stub
            bookDao.deleBook(book);
        }
    
        @Override
        public Book getBook(Book book) {
            // TODO Auto-generated method stub
            return bookDao.getBook(book);
        }
    
        @Override
        public List<Book> queryBookPager(Book book, PageBean pageBean) {
            // TODO Auto-generated method stub
            return bookDao.queryBookPager(book, pageBean);
        }
    
    }

    BookAction

    package com.hmc.book.action;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import com.hmc.base.action.BaseAction;
    import com.hmc.base.util.PageBean;
    import com.hmc.book.biz.IBookBiz;
    import com.hmc.book.entity.Book;
    import com.opensymphony.xwork2.ModelDriven;
    
    public class BookAction extends BaseAction implements ModelDriven<Book> {
    
        private Book book=new Book();
        private IBookBiz bookBiz;
    
        public IBookBiz getBookBiz() {
            return bookBiz;
        }
    
    
        public void setBookBiz(IBookBiz bookBiz) {
            this.bookBiz = bookBiz;
        }
    
    
        @Override
        public Book getModel() {
            // TODO Auto-generated method stub
            return book;
        }
        
        public String addBook() {
            bookBiz.addBook(book);
            return null;
        }
    
        public String queryBookPager() {
            PageBean pageBean=new PageBean();
            pageBean.setRequest(request);
            List<Book> books = bookBiz.queryBookPager(book, pageBean);
            Map map=new HashMap<String, Object>();
            map.put("books", books);
            map.put("pages", pageBean);
            request.setAttribute("list", map);
            return "list";
        }
    }

    rs.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <%@taglib prefix="z" uri="/MyJSP" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="bookAction_queryBookPager.action" method="post">
    <label>书本名称</label>
    <input type="text" name="bname">
    <input type="submit" value="查询">
    </form>
    
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <th>书本编号</th>
    <th>书本名称</th>
    <th>书本价格</th>
    <th>书本图片</th>
    <th>操作</th>
    
    <tbody>
    <c:forEach items="${list.books}" var="book">
      <tr>
      <td>${book.bid}</td>
      <td>${book.bname}</td>
      <td>${book.price}</td>
      <td> ${book.image} </td>
      <td>
      <a href="bookAction_delBook.action?bid=${book.bid}">删除</a>
      <a href="bookAction_book.action?type=edit&bid=${book.bid}">修改</a>
       <a href="bookAction_book.action? type=detail&bid=${book.bid}">详情</a>
       <a href="bookFile.jsp?id=${book.bid}">文件上传</a>
       <a href="fileAction_dowload.action?fileId=${book.image}">文件下载</a>
      </td>
      </tr>
    </c:forEach>
    </tbody>
    
    </table>
     <%-- <z:page bean="${list.pages}"></z:page>  --%>
    </body>
    </html>

  • 相关阅读:
    vue vmodel input type=checkbox的问题
    springboot配置文件优先级
    原生js实现复制功能
    Long.valueOf和Long.parseLong的区别
    程序员学习参考
    国外开源项目
    .NET快速入门教程
    Microsoft Update Catalog 离线安装包下载
    php header示例代码
    CentOS下iptables设置
  • 原文地址:https://www.cnblogs.com/xmf3628/p/11360002.html
Copyright © 2020-2023  润新知