一、首先的前提:(共三步,只做一次)
1.在pom.xml文件引入应用对mybatis的依赖:
<!-- 引入starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
<scope>runtime</scope>
</dependency>
<!-- MySQL的JDBC驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- 引入第三方数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
2.编写配置文件application.properties相关信息:
[root@localhost local]$ cd mysql/[root@localhost mysql]$ bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/。
loading class `com.mysql.jdbc.driver'. this is deprecated. the new driver class is `com.mysql.cj.jdbc.driver'. the driver is automatically registered via the spi and manual loading of the driver class is generally unnecessary.。
servertimezone=utc&characterencoding=utf8&useunicode=true&usessl=false。
如果了解jdbc规范(接口),那么它的实现,jdbc driver就一定要开始了解,我的建议是,读读mysql的jdbc驱动,因为它开源、设计优雅。
spring.datasource.username =root
spring.datasource.password =root
#如果不使用默认的数据源 (com.zaxxer.hikari.HikariDataSource)
1.application.properties配置文件spring.datasource.type = com.alibaba.druid.pool.druiddatasource...。 3.在应用的启动类上添加注解@MapperScan("xx.xx.mapper") 让系统可以扫描到mapper; 二、接下来就是具体的操作:(共6步) 1.在domain包编写user的对象类文件: 2.在mapper包编写mapper文件: 3.在controller包编写控制器: 需要自动注入UserService,以自动生成userService bean。mybatis 4.在service包编写UserService接口: 5.在service.impl包编写实现类UserServiceImpl: mybatis将配置文件中的每一个 根据策划的需求,我将游戏数据分析完了之后,就基本理清了表结构,在项目中我使用了hibernate4作为orm框架,相对于前面的版本,hibernate4有一个很爽的功能,就是在javabean中添加一些注解,就能在构建hibernate的session的时候,自动在创建表,这样使得开发效率快了好几倍,hibernate本身就已经够爽了,我认为至今没有什么orm框架能跟它比,以前也用过mybatis,个人感觉mybatis更适合那种需要手动写很复杂的sql才用的,每一个查询都要写sql,在hibernate中,简简单单几行代码,就能完成一个查询,一下贴出hibernate工具类:。 第四步在service的接口实现层添加@service注解并且对注入进来的成员变量进行@resource注入。 首先需要写一个接口,然后在application中添加配置mybatis.mapper-locations=classpath*:mybatis/*mapper.xml。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-89333-1.html
美国佬既然自己送来了
放久了生蛆多正常