struts2+spring3+hibernate3+mysql简单登录实现

1.导入相关的jar包

2.建立数据库

复制代码
1 create table account(
2 id int(10), 3 user varchar(50), 4 paw varchar(50) 5 ); 6 insert into account values(1,'admin','admin');
复制代码

 

3.建立包结构

 

4.配置文件的配置及代码

4.1 数据库配置文件:db.properties

1 #jdbc
2 jdbc.driver=com.mysql.jdbc.Driver
3 jdbc.url=jdbc:mysql://127.0.0.1:3306/test 4 jdbc.username=root 5 jdbc.password=

4.2 spring配置文件:applicationContext.xml

复制代码
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"  3  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  4  xmlns:util="http://www.springframework.org/schema/util" xmlns:jee="http://www.springframework.org/schema/jee"  5  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"  6  xmlns:mvc="http://www.springframework.org/schema/mvc"  7  xsi:schemaLocation="  8  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  9  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd 10  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd 11  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd 12  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 13  http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd 14  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 15 <context:component-scan base-package="ssh.ft"></context:component-scan> 16 17 <context:property-placeholder location="classpath:configs/db.properties" /> 18 <!-- datasource --> 19 <bean id="dataSource" 20  class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 21 <property name="driverClassName" value="${jdbc.driver}" /> 22 <property name="url" value="${jdbc.url}" /> 23 <property name="username" value="${jdbc.username}" /> 24 <property name="password" value="${jdbc.password}" /> 25 </bean> 26 <!-- spring与hibernate整合 spring来管理session的创建、打开和关闭 --> 27 <bean id="sessionFactory" 28  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 29 <!-- 通过配置文件的方式获取数据源,出现异常,未解决 --> 30 <property name="hibernateProperties"> 31 <props> 32 <prop key="connection.useUnicode">true</prop> 33 <prop key="connection.characterEncoding">utf-8</prop> 34 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 35 <prop key="hibernate.show_sql">true</prop> 36 <prop key="hibernate.hbm2ddl.auto">update</prop> 37 </props> 38 </property> 39 <property name="dataSource" ref="dataSource" /> 40 <property name="mappingResources"> 41 <list> 42 <!-- 以下用来列出所有的PO映射文件 --> 43 <value>configs/account.hbm.xml</value> 44 </list> 45 </property> 46 </bean> 47 <!-- 定义事物管理器,并位事物管理器配置上述所定义的session --> 48 <!-- <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 49  <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> 50  </bean> <tx:annotation-driven transaction-manager="transactionManager"/> --> 51 52 

转载于:https://www.cnblogs.com/Jansens520/p/6504686.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值