吴福杰的BLOG 订阅
相关博文
内容读取中…
推荐博文
内容读取中…
谁看过这篇博文
内容读取中…
字体大小: 正文
ssh登陆练习2 (2007-12-20 10:52:08)
 applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
 <bean id="myBean" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName">
   <value>com.mysql.jdbc.Driver</value>
  </property>
  <property name="url">
   <value>jdbc:mysql://localhost:3306/login</value>
  </property>
  <property name="username">
   <value>root</value>
  </property>
 </bean>
 <bean id="mySessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="myBean" />
  </property>
  <property name="mappingResources">
   <list>
    <value>my.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.MySQLDialect
    </prop>
   </props>
  </property>
 </bean>
 <bean name="userDao" class="com.dao.UserDao">
  <property name="sessionFactory" ref="mySessionFactory"></property>
 </bean>
 <bean name="/login" class="com.yourcompany.struts.action.LoginAction">
 </bean>
 </beans>
 
 

package com.dao;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.lovo.UserPo;

public class UserDao extends HibernateDaoSupport
{
 public boolean selectUser(UserPo user)
 {
  System.out.println(user.getName());
  System.out.println(user.getPassword());
  List list=super.getHibernateTemplate().find("from UserPo where name=? and password=?",new String[]{new String(user.getName()),new Integer(user.getPassword()).toString()});
  System.out.println(list);
  if(list.size()!=0)
  {
   System.out.println(list);
   return true;
  }
  else
  {
   System.out.println("1323123"+list);
   return false;
  }
  
 }
 public static void main(String []args)
 {
  ApplicationContext con=new ClassPathXmlApplicationContext("applicationContext.xml");
  UserDao dao=(UserDao)con.getBean("userDao");
  UserPo po=new UserPo();
  po.setName("123");
  po.setPassword("123");
  if(dao.selectUser(po))
  {
   System.out.println("存在");
  }
  else
  {
   System.out.println("不存在");
  }
 }
}

评论(0)| 阅读 (0) | 收藏 (0) | 分享 | 打印 | 举报
前一篇:ssh的登陆练习
后一篇:ssh登陆练习3
评论     发表评论
发表评论  
匿名评论(无需注册)
验证码:看不清楚数字吗?点击这里再试试。
新浪BLOG意见反馈留言板 不良信息反馈 电话:95105670 提示音后按2键(按当地市话标准计费) 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

新浪公司 版权所有