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" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:component-scan base-package="com.hrManager"></context:component-scan><!-- 加载配置文件 --> <context:property-placeholder location="classpath:db_MySQL.properties" /> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>${db.driver}</value> </property> <property name="url"> <value>${db.url}</value> <!--springmybaitis是我的数据库 --> </property> <property name="username"> <value>${db.username}</value> </property> <property name="passWord"> <value>${db.password}</value> </property> </bean><!-- 配置sqlsessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis_config.xml"></property> </bean> <!-- 这里是让sqlSession跟Mapper关联起来 --> <bean id="userDao" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.hrManager.dao.AdminMapper"></property> <property name="sqlSessionFactory" ref="sqlSessionFactory"></property> </bean> <!-- ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <!-- 配置前缀 --> <property name="prefix" value="/WEB-INF/pages/" /> <!-- 配置后缀 --> <property name="suffix" value=".jsp" /> </bean> </beans>
sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration> <!-- 将数据库关联文件引进来 --> <properties resource="db_mysql.properties"></properties> <!-- 给我引用的po起一个别名 --> <typeAliases> <!-- 给某一个包下面的所有po定义,这个时候po类名就相当于是alias --> <package name="com.hrManager.po"/> </typeAliases> <mappers> <package name="com.hrManager.dao"/> </mappers> </configuration>
db.properties
db.driver=org.gjt.mm.mysql.Driverdb.url=jdbc:mysql://localhost:3306/hrmanager?characterEncoding=utf-8db.username=rootdb.password=951207
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>hrManager</display-name> <servlet> <servlet-name>spring_bean</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring_bean.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring_bean</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>/WEB-INF/pages/login.jsp</welcome-file> </welcome-file-list></web-app>
Dao.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.jinhuan.dao.EmployeeDao"> <!-- 通过职位名称和员工姓名查找员工信息 --> <select id="findAllBYEmpName" parameterType="Employee" resultType="Employee"> select * from employee,organ where employee.organ_id = organ.organ_id and emp_name=#{emp_name} and post_type=#{post_type} </select> <!-- 查询员工的所有信息 --> <select id="finaAllEmployee" resultType="Employee"> select * from employee,organ where employee.organ_id = organ.organ_id </select> <!-- 通过职位查找员工信息 --> <select id="findInfoBypost_type" parameterType="int" resultType="Employee"> select * from employee,organ where employee.organ_id = organ.organ_id and post_type=#{post_type} </select></mapper>
jar包的下载地址:http://download.csdn.net/detail/rosener/9755354
新闻热点
疑难解答