mybatis generator 使用手册.docx_第1页
mybatis generator 使用手册.docx_第2页
mybatis generator 使用手册.docx_第3页
mybatis generator 使用手册.docx_第4页
mybatis generator 使用手册.docx_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Mybatis generator使用手册目录Mybatis generator使用手册1一、引言11.编写目的12.术语定义13.概述1二、安装2安装:在pom.xml中设置mybatis-generator插件为2三、使用-demo实例21.配置generatorConfig.xml22.配置一个外部工具33.生成配置文件54.创建接口UserService和其实现类UserServiceImpl如下55.配置web.xml76.配置jdbc. properties87.配置mybatis-config.xml88.配置applicationContext.xml99.创建jsp文件1110.测试11附加说明11一、 引言1. 编写目的本文档是mybatisgenerator使用说明,编写目的是:为即将使用mybatis的开发人员提供帮助。2. 术语定义暂无。3. 概述Mybatis-generator是一个mybatis相关代码的自动生成工具。二、 安装安装:在pom.xml中设置mybatis-generator插件为 org.mybatis.generator mybatis-generator-maven-plugin 1.3.1 执行mvn eclipse:eclipse,这时在maven中会加入此插件三、 使用-demo实例1. 配置generatorConfig.xmlMybatis-generator的配置文件名称默认为generatorConfig.xml。也可能更改,更改时要在pom.xml中加入如下代码(注意properties可能已存在)generatorConfig.xmlgeneratorConfig.xml的内容为 !- - 2. 配置一个外部工具在program下新建一个工具 输入name为mybatis_generator,location选择mvn.bat(maven的执行文件),work directory设置为项目路径。Arguments中为要运行的命令: mybatis-generator:generate点击“apply“。在common中得display in favorites menu中勾选上external tools选项(以后在external tools的下拉列表里就有此名称的命令了)3. 生成配置文件在外部工具中点击”mybatis_generator”,之后刷新项目,即可见到mybatis自动生成的文件。生成之后的项目录为 UserMapper.java为接口文件,内含对user表增删改查等抽象方法。User.java为model类,UserExample为查询是where条件类,UserMapper.xml为mybatis的xml配置文件。4. 创建接口UserService和其实现类UserServiceImpl如下UserService.javapackage abren.user.service;import abren.user.mybatis.model.User;public interface UserService public User getUser(Integer id);UserServiceImpl.javapackage abren.user.service.impl;import org.springframework.beans.factory.annotation.Autowired;import abren.user.mybatis.dao.UserMapper;import abren.user.mybatis.model.User;import abren.user.service.UserService;public class UserServiceImpl implements UserService AutowiredUserMapper userMapper;Overridepublic User getUser(Integer id) / TODO Auto-generated method stubUser user = userMapper.selectByPrimaryKey(id);return user;创建完成之后的目录结构为5. 配置web.xml在web.xml中配置applicationContext.xml contextConfigLocationclasspath*:applicationContext*.xmlorg.springframework.web.context.ContextLoaderListener index.jsp 6. 配置jdbc. properties在main/resources中添加perties,内容如下#MySql#jdbc.url=jdbc:mysql:/localhost:3306/testjdbc.driverClassName=com.mysql.jdbc.Driverjdbc.username=rootjdbc.password=123456# Time to wait for an open connection before timing out# (in milliseconds)cpool.checkoutTimeout=5000# Connection pool sizecpool.minPoolSize=5cpool.maxPoolSize=20# How long to keep unused connections around(in seconds)# Note: MySQL times out idle connections after 8 hours(28,800 seconds)# so ensure this value is below MySQL idle timeoutcpool.maxIdleTime=3600# How long to hang on to excess unused connections after traffic spike# (in seconds)cpool.maxIdleTimeExcessConnections=1800# Acquiring new connections is slow, so eagerly retrieve extra connections# when current pool size is reachedcpool.acquireIncrement=57. 配置mybatis-config.xml在main/resources下加入mybatis-config.xml,内容如下 !- - 8. 配置applicationContext.xml在applicationContext.xml中配置如下 9. 创建jsp文件 10. 测试用maven打成war包,浏览index.jsp。Demo完成附加说明生成的mybatis的xml文件的namespace一定是mapper完整的路径+类名一下方式为简化注入方式。(mybatis的xml的配置文件和mapper文件路径和名称必须相同)的Mapper 此种方式只适合mybatis的xml和Mapper文件在同一路径下并名称相同的情况下。如有路径或不同名称不同请参照附件说明 -完整的注入方式为(mybatis的xml的配置文件和mapper文件路径和名称必须相同) mybatis的xml的配置文件和mapper文件路径和名称如果不相同的话有两种配置方法方式一1.在MyBatis配置文件中添加mappers:my

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论