Struts2 mybatis spring 实现用户登录
来源:互联网 发布:js基本数据类型 编辑:程序博客网 时间:2024/06/01 08:06
前两天了解了一下Ibatis的简单配置和使用,今天主要是将ibatis和spring 、struts2整合在一起,实现用户登录的简单功能。以下是项目结构图,以及项目的部分代码。
创建ApplicationContext.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <!--配置数据源属性文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>/WEB-INF/configs/mySql.properties</value> </property> </bean> <!--配置数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>${jdbc.driver}</value> </property> <property name="url"> <value>${jdbc.url}</value> </property> <property name="username"> <value>${jdbc.user}</value> </property> <property name="password"> <value>${jdbc.pwd}</value> </property> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:com/test/sqlMapper/mybatis_config.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="loginDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.test.dao.ILoginDao"/> <property name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean> <bean id="loginAction" class="com.test.action.LoginAction"> <property name="loginDao" ref="loginDao"></property> </bean> </beans>
mybatis的配置文件mybatis_config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <typeAlias alias="user" type="com.test.entity.User"/> </typeAliases> <mappers> <mapper resource="com/test/sqlMapper/loginMapper.xml"/> </mappers> </configuration>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
Action中的execute方法,对用户进行验证。
public String execute(){ String userName = getUsername(); String password = getPassword(); System.out.println("userName:"+userName+"\n"+"password:"+password); List list = loginDao.getUser(userName); if(list.size()>0){ return "success"; }else{ return "error"; } }
花费了几天时间去了解了ibatis以及spring的简单功能。明天打算开始学习jquery easyui的知识。
0 0
- Struts2 mybatis spring 实现用户登录
- struts2 简单实现用户登录
- mybatis学习笔记二mybatis结合spring mvc实现(用户登录,数据查询)
- Struts2+Mybatis整合实现注册登录功能
- SpringMVC + Mybatis 实现用户登录功能
- struts2+spring防止用户重复登录(单点登录)
- java之Struts2实现用户登录过滤
- struts2+ajax+json实现用户登录
- struts2连接数据库实现用户登录
- 使用Struts2实现简单用户登录
- spring mvc +mybatis登录首页功能 实现
- Spring MVC + mybatis实现的注册登录
- SpringMVC Spring Mybatis Maven 实现登录功能
- Struts2,Spring,jquery实现的登录例子
- Struts2与Spring整合,实现登录效果
- Spring MVC实现用户登录页面
- Struts与Spring整合实现用户登录
- 新手教你学Spring MVC4.0+MyBatis+MySQL5.0实现简单用户注册登录程序(一)
- jquery textarea文本域字数限制发布框
- spatialite-gui加载txt文件
- IPv4 icmp4
- leetcode 29 Divide Two Integers
- 关于display:none使用
- Struts2 mybatis spring 实现用户登录
- 让PanelTabbed组件在页面刷新时保持当前打开的项
- BroadleafCommerce简介
- OpenCV统计应用-直方图反向投影
- IPv4 rawip4
- OpenCV成长之路(7):图像滤波
- Pack URIs in WPF
- 军报应用开发小组在2015年终于成立了
- IPv4 routing fib4: Forwarding Information Base