解决方案 »

  1.   

    Spring配置如下:
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    <!-- 引入JDBC配置文件 -->
    <bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:oracle.properties"></property>
    </bean>
    <bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="username" value="${jdbc.username}"></property>
    <property name="password" value="${jdbc.password}"></property>
    <property name="url" value="${jdbc.url}"></property>
    <property name="driverClassName" value="${jdbc.driver}"></property>
    </bean>
    <!-- myBatis文件 创建SqlSessionFactory,同时指定数据源 -->
    <bean id="sqlsessionfactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="datasource"></property>
    <property name="mapperLocations" value="classpath*:com/cn/mapper/**/*.xml"></property>
    <property name="typeAliasesPackage" value="com.anwin.model"></property>
    </bean>
    <!--DAO map-->
    <bean id="userdao" class="org.mybatis.spring.mapper.MapperFactoryBean">
    <property name="mapperInterface" value="com.cn.mapper.UserDao" />
    <property name="sqlSessionFactory" ref="sqlsessionfactory" />
    </bean>
      

  2.   

    这是mybatis
    <?xml version="1.0" encoding="UTF-8" ?> 
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <configuration>
    <typeAliases>
    <typeAlias type="com.anwin.model.News_User" alias="user"/>
    </typeAliases><mapper namespace="com.cn.mapper.UserDao">
    <cache></cache>
    <!-- 注册用户 -->
    <insert id="regiest" parameterType="user">
    <selectKey keyProperty="id" order="BEFORE" resultType="int"
    statementType="STATEMENT">
    SELECT NVL(MAX(ID),0)+1 FROM NEWS_USER
    </selectKey>
    INSERT INTO NEWS_USER (id,usercode,name,password,email,address)
    VALUES(#{id},#{usercode},#{name},#{password},#{email},#{address,jdbcType=VARCHAR})
    </insert>
    <!-- 修改用户信息 -->
    <update id="update" parameterType="user">
    UPDATE NEWS_USER
    <trim prefix="set" suffixOverrides=",">
    <if test="usercode!=null and usercode!=0">
    usercode=#{usercode},
    </if>
    <if test="name!=null and name!=''">
    name=#{name},
    </if>
    <if test="password!=null and password!=''">
    password=#{password},
    </if>
    <if test="email!=null and email!=''">
    email=#{email},
    </if>
    <if test="address!=null and address!=''">
    address=#{address},
    </if>
    </trim>
    WHERE id=#{id}
    </update>
    <!-- 两种验证的sql -->
    <sql id="verify_sql">
    SELECT COUNT(*) FROM NEWS_USER
    <trim prefix="where" prefixOverrides="and">
    <if test="id!=null and id!=0">
    and id=#{id}
    </if>
    <if test="email!=null and email!=''">
    and email=#{email}
    </if>
    <if test="password!=null and password!=''">
    and password=#{password}
    </if>
    </trim>
    </sql>
    <!-- 邮箱登陆 -->
    <select id="email_Login" parameterType="user" resultType="int">
    <include refid="verify_sql" />
    </select>
    <!-- id登陆 -->
    <select id="id_Login" parameterType="user" resultType="int">
    <include refid="verify_sql" />
    </select>
    <!-- 查找所有用户 -->
    <resultMap type="user" id="resultmap">
    <id property="id" column="id" />
    <result property="usercode" column="usercode" />
    <result property="name" column="name" />
    <result property="password" column="password" />
    <result property="email" column="email" />
    <result property="address" column="address" />
    </resultMap>
    <select id="select" resultMap="resultmap">
    SELECT * FROM
    NEWS_USER
    </select>
    </mapper>
    </configuration>