mybatis
mapper
- <?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">
- <mapper namespace="com.dao.mapper.UserMapper">
- <select id="findAll" resultType="User">
- select * from user
- </select>
- <select id="findAllByUser" resultType="User">
- select * from user
- <where>
- <if test="id!=null">
- and id=#{id}
- </if>
- <if test="name!=null">
- and name=#{name}
- </if>
- <if test="password!=null">
- and password=#{password}
- </if>
- </where>
- </select>
- <select id="findById" parameterType="int" resultType="User">
- select * from user where id=#{parameter}
- </select>
- <select id="userLogin" parameterType="User" resultType="map">
- select * from user where name=#{username} and password=#{userpwd}
- </select>
- <select id="insert" parameterType="User">
- insert into user(name,password) value(#{name},#{password})
- </select>
- <select id="update" parameterType="User">
- update user
- <set>
- <if test="name!=null">
- name=#{name},
- </if>
- <if test="password!=null">
- password=#{password}
- </if>
- </set>
- where id=#{id}
- </select>
- <select id="deleteUser" parameterType="int">
- delete * from user where id=#{parameter}
- </select>
- </mapper>
mybatis
config
- <?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 type="com.entity"/>
- <!-- <package name="com.entity"/> -->
- </typeAliases>
- <!-- <environments default="development">
- <environment id="development">
- <transactionManager type="JDBC" />
- <dataSource type="POOLED">
- <property name="driver" value="com.mysql.jdbc.Driver" />
- <property name="url" value="jdbc:mysql://localhost:3306/test" />
- <property name="username" value="root" />
- <property name="password" value="karen" />
- </dataSource>
- </environment>
- </environments>
- <mappers>
- <mapper resource="com/dao/mapper/UserMapper.xml"/>
- </mappers> -->
- </configuration>