日期:2014-05-16  浏览次数:20378 次

AJAX级联菜单实例,js
AJAX级联菜单实例

说明 ajax级联菜单,例如,一级菜单选择中国,二级菜单列出中国城市;一级菜单选择美国,二级菜单列出美国城市。

数据库脚本 count.sql

DROP TABLE IF EXISTS `country`;

CREATE TABLE `country` (

`id` int(11) NOT NULL auto_increment,

`name` varchar(50) default NULL,

`city` varchar(50) default NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;


insert into country values(1,'中国','沈阳') ;

insert into country values(2,'中国','北京') ;

insert into country values(3,'美国','洛杉矶') ;

insert into country values(4,'美国','纽约') ;


DAO

package edu.syict.www.dao;


import java.util.List;


import org.hibernate.HibernateException;

import org.hibernate.Query;

import org.hibernate.Session;

import org.hibernate.Transaction;


import edu.syict.www.HibernateSessionFactory;


public class DBOperator {

       @SuppressWarnings("unchecked")

       public List queryByName(String name){

              Session session = HibernateSessionFactory.getSession();

              List list=null ;

              String hql="SELECT co.city FROM Country AS co WHERE co.name=?" ;

              System.out.println(hql+name);

              Transaction tx = null;    

              try {

                     tx = session.beginTransaction();

                     Query query=session.createQuery(hql) ;

                     query.setString(0, name) ;

                     list=query.list() ;

                     System.out.println("数据库中记录个数:"+list.size()) ;

                     tx.commit() ;

              } catch (HibernateException e) {

                     if (tx != null)

                            tx.rollback();

                     throw e;

              }finally{

                     session.close();

              }    

              return list ;<