第一步:log4j.properties的配置

原因:Mybatis的日志输出是依赖与log4j的,所以必须要配置

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# Mybatis logging configuration...
log4j.logger.com.xu.itheima=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

第二步:db.properties的配置

原因:在配置SqlSessionFactory全局配置文件的时候需要连接数据库的操作,这时配置一个db,properties文件,

在修改数据库的配置信息是更加灵活。

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis
jdbc.username=root
jdbc.password=admin

第三步:SqlSessionFactory.xml全局配置文件的配置

原因:Mybatis框架的加载过程以及数据库的连接过程

<?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>
<properties resource="db.properties"></properties>
<environments default="development">
<environment id="development">
<transactionManager type="jdbc"/>
<dataSource type="pooled">
<property name="driver" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</dataSource>
</environment>
</environments> <mappers>
<!-- 类路径的引入 -->
<mapper resource="sqlmapper/User.xml"/>
</mappers>
</configuration>

第四步:UserMapper.xml的配置

原因:Mybatis框架是一个典型的ORM框架(对象关系映射),X谢谢Mapper.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">
<!-- User的映射xml -->
<mapper namespace="test">
<!-- 根据id查询一条数据 -->
<select id="findUserById" parameterType="int" resultType="com.xu.pojo.User">
select * from user where id=#{id}
</select>
<!-- 根据模糊查询多条数据 -->
<select id="findUserByName" parameterType="String" resultType="com.xu.pojo.User">
select * from user where username like '%${value}%'
</select>
<!-- 添加用户信息 -->
<insert id="addUser" parameterType="com.xu.pojo.User">
insert into user(username,sex,birthday) values(#{username},#{sex},#{birthday})
</insert>
<!-- 修改用户信息 -->
<update id="updateUserById" parameterType="com.xu.pojo.User">
update user set username=#{username},sex=#{sex} where id=#{id}
</update>
<!-- 删除用户信息 -->
<delete id="deleteUser" parameterType="int">
delete from user where id=#{id}
</delete>
</mapper>

总结:通过以上的配置再结合该链接的初始化代码 http://www.cnblogs.com/x-ll123/p/8507048.html 就初步运行实现代码功能。


MyBatis框架的文件配置的更多相关文章

  1. mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置

    mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置 ============================== 蕃薯耀 2018年3月14 ...

  2. mybatis mapper xml文件配置resultmap时,id行和result行有什么区别?

    mybatis mapper xml文件配置resultmap时,id行和result行有什么区别? <resultMap id = "CashInvoiceMap" typ ...

  3. [Django框架 - 静态文件配置、request对象方法初识、 pycharm链接数据库、ORM实操增删改查、django请求生命周期]

    [Django框架 - 静态文件配置.request对象方法初识. pycharm链接数据库.ORM实操增删改查.django请求生命周期] 我们将html文件默认都放在templates文件夹下 将 ...

  4. 深入理解MyBatis框架的的配置信息

    面对一个框架,最重要的不是说回用其代码就可以了,我们需要了解其思想,这样才能更快更好的掌握这个框架.而对于一个框架,最重要的就是其配置文件的作用及功能了.下面,我就来谈一谈我今天遇到的这个MyBati ...

  5. SSM Spring SpringMVC Mybatis框架整合Java配置完整版

    以前用着SSH都是老师给配好的,自己直接改就可以.但是公司主流还是SSM,就自己研究了一下Java版本的配置.网上大多是基于xnl的配置,但是越往后越新的项目都开始基于JavaConfig配置了,这也 ...

  6. mybatis 自动生成文件配置

    maven 依赖配置: <!-- sql server --><dependency> <groupId>com.microsoft.sqlserver</g ...

  7. yaf框架学习文件配置

    文件配置: 在配置php支持yaf的时候,可以设置一个参数yaf.environ:把本地开发设置成develop.测试环境配置成test.生产环境配置成product. [yaf] extension ...

  8. mybatis的Mapper文件配置

    一.resultMap resultMap 元素是 MyBatis 中最重要最强大的元素. 该配置节点下如下子节点配置 id – 一个 ID 结果;标记结果作为 ID 可以帮助提高整体效能 const ...

  9. MyBatis - 2.全局文件配置

    1.properties 属性 <!--properties 引入外部配置文件 properties 的内容 resource: 引入类路径资源 url: 引入网络资源 --> <p ...

随机推荐

  1. iconfont 在vue项目中的应用(icon-component组件)

    前言:上一篇记录了iconfont的三种基本使用方法. 在Vue中应该如何使用呐?Vue中的组件化思想很明确,要提高组件的复用率,增强项目的可维护性,扩展性.以下是采用icontfont的使用方式之s ...

  2. 结合sessionStorage解决vuex页面刷新数据丢失的问题

    将需要保存在vuex中的数据同时保存在sessionStorage中即可: import Vue from 'vue'; import Vuex from 'vuex'; Vue.use(Vuex); ...

  3. Web-动态页面

    <!doctype html>01 - JavaEE- JSP - EL&JSTL figure:first-child { margin-top: -20px; } #write ...

  4. 侧滑关闭Activity的解决方案——SwipeBackLayout

    项目地址:ikew0ng/SwipeBackLayout: An Android library that help you to build app with swipe back gesture. ...

  5. 2019-9-2-贡献自己的服务器搭建tor中转

    title author date CreateTime categories 贡献自己的服务器搭建tor中转 lindexi 2019-09-02 12:57:38 +0800 2018-2-13 ...

  6. RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more infor

    在virtualenv环境下使用matplotlib绘图时遇到了这样的问题: >>> import matplotlib.pyplot as pltTraceback (most r ...

  7. vue中 给router-view 组件的 绑定 key 的原因

    不设置 router-view 的 key 属性 由于 Vue 会复用相同组件, 即 /page/1 => /page/2 或者 /page?id=1 => /page?id=2 这类链接 ...

  8. crontab[计划任务],tar[压缩],grep[查找]

    计划任务:1.新建一个计划任务:crontab -e -----> 3*/1 * * * * date >> /tmp/data.txt查看计划任务:crontab -l.如果超过6 ...

  9. index方法用于数据集的强制索引操作

    index方法为3.2.3版本新增,用于数据集的强制索引操作,例如: $Model->index('user')->select(); 对查询强制使用user索引,user必须是数据表实际 ...

  10. sqlite3加密

    最近因为工作原因,需要使用sqlite数据库.sqlite数据库小并且使用方便,感觉挺不错的.但有一个不足就是没有对数据库进行加密,不过好的是sqlite预留有加密的接口,我们可以直接调用即可.我也是 ...