The SSH framework reads data from the database and displays the process

 

  1. Create a table of primary categories :

    CREATE TABLE `category` (

      `cid` int(11) NOT NULL AUTO_INCREMENT,

      `cname` varchar(255) DEFAULT NULL,

      PRIMARY KEY (`cid`)

    ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

     

  2. Build packages and corresponding classes :

    * cn.itcast.shop.category

    * action

    * service

    * CategoryService: business layer object

    *dao

    * CategoryDao: Persistence layer object

    * vo

    * Category: entity object

    * Category.hbm.xml: Mapping file

     

  3. Configure the Service and DAO :

    * Inject sessionFactory in DAO

    * Inject DAO in Service

     

  4. Need to inject first-class service in IndexAction .

    * Action-----Service------Dao

    * Display the data of the first-level classification to the page :

    * Store the data of the first-level classification into the session scope .

    ActionContext.getContext().getSession().put("cList",cList);

    Then read it iteratively in jsp and display

    <s:iterator var="c" value="#session.cList">

         <li><a href="xxx/xxx.html"><s:property value="#c.cname"></a></li>

    </s:iterator>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326112607&siteId=291194637