mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
<!-- <settings> <setting name="cacheEnabled" value="true"/> </settings> -->
<!-- 数据库环境设置 ,可以配置多个环境设置 属性 default:指定当前使用的数据库环境 -->
<settings>
<setting name="cacheEnabled" value="true"/>
</settings>
<typeAliases>
<!-- 自动扫描实体类,起别名 短类名 User -->
<package name="com.baizhi.entity"/>
<!-- plugins必须在 typeAliases标签和 environments标签之间 -->
</typeAliases>
<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- 使用下面的方式配置参数,后面会有所有的参数介绍 -->
<property name="helperDialect" value="Mysql"/> <!--配置数据库种类 -->
<!--开启对dao参数的支持 -->
<property name="supportMethodsArguments" value="true"/>
</plugin>
</plugins>
<environments default="db1">
<!-- 一个数据库环境的设置 id 当前环境的唯一标识 -->
<environment id="db1">
<!-- 事务控制机制 type: JDBC MANAGER 交给第三方软件处理事务 -->
<transactionManager type="JDBC"></transactionManager>
<!-- 连接池设置 type : POOLED 使用数据库连接池 UNPOOLED 不使用数据库连接池 -->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://localhost:3306/wxz?useUnicode=true&characterEncoding=utf-8"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
<!--<environment id="Oracle">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
<property name="username" value="hr"/>
<property name="password" value="hr"/>
</dataSource>
</environment>-->
</environments>
<mappers>
<package name="com.baizhi.dao"/>
</mappers>
</configuration>
XxxMapper.xml
<?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.baizhi.dao.PersonDao">
<!-- <cache/> -->
<resultMap type="com.baizhi.entity.Person" id="PersonMap">
<id column="person_id" property="id"/>
<result column="person_name" property="name"/>
<result column="age" property="age"/>
<result column="sex" property="sex"/>
<result column="mobile" property="mobile"/>
<result column="birthday" property="birthday"/>
</resultMap>
<insert id="insert">
insert into person values(null,#{name},#{age},#{sex},#{mobile},#{birthday})
</insert>
<select id="selectByName" resultMap="PersonMap">
select * from person where person_name=#{name}
</select>
<select id="selectById" resultMap="PersonMap">
select * from person where person_id=#{id}
</select>
<select id="selectAll" resultMap="PersonMap">
select * from person limit #{offset},#{rows}
</select>
<update id="updateById">
update person set person_name=#{name},age=#{age},sex=#{sex},mobile=#{mobile},birthday=#{birthday} where person_id=#{id}
</update>
<delete id="deleteById">
delete from person where person_id=#{id}
</delete>
<select id="totalcount" resultType="int">
select COUNT(*) from person
</select>
<select id="selectAllshow" resultMap="PersonMap">
select * from person
where person_id like concat('%',#{search},'%')
or person_name like concat('%',#{search},'%')
or age like concat('%',#{search},'%')
or mobile like concat('%',#{search},'%')
order by ${sort} ${order}
limit #{offset},#{limit}
</select>
<delete id="deleteMany">
delete from person
where person_id in
<foreach collection="ids" item="id" open="(" close=")" separator="," >
#{id}
</foreach>
</delete>
</mapper>