Mybatis基于XML配置SQL映射器(一)

 Durid和Mybatis开发环境搭建

SpringBoot搭建基于Spring+SpringMvc+Mybatis的REST服务(http://www.cnblogs.com/nbfujx/p/7694768.html)

Mybatis之代码生成器

Maven Plugin管理

 1  <build>
 2         <plugins>
 3             <plugin>
 4                 <groupId>org.mybatis.generator</groupId>
 5                 <artifactId>mybatis-generator-maven-plugin</artifactId>
 6                 <version>1.3.5</version>
 7                 <executions>
 8                     <execution>
 9                         <id>Generate MyBatis Artifacts</id>
10                         <goals>
11                             <goal>generate</goal>
12                         </goals>
13                     </execution>
14                 </executions>
15             </plugin>
16             <plugin>
17                 <groupId>org.apache.maven.plugins</groupId>
18                 <artifactId>maven-compiler-plugin</artifactId>
19                 <configuration>
20                     <source>1.6</source>
21                     <target>1.6</target>
22                 </configuration>
23             </plugin>
24         </plugins>
25     </build>
View Code

generatorConfig.xml

配置相关内容

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE generatorConfiguration PUBLIC
 3         "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
 5 <generatorConfiguration>
 6 
 7     <!-- !!!! Driver Class Path !!!! -->
 8     <classPathEntry location="C:\Users\Han\.m2\repository\mysql\mysql-connector-java\5.1.35\mysql-connector-java-5.1.35.jar"/>
 9 
10     <context id="context" targetRuntime="MyBatis3">
11         <commentGenerator>
12             <property name="suppressAllComments" value="false"/>
13             <property name="suppressDate" value="true"/>
14         </commentGenerator>
15 
16         <!-- !!!! Database Configurations !!!! -->
17         <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://10.1.51.235:3306/jawavesys" userId="root" password="jawave88"/>
18 
19         <javaTypeResolver>
20             <property name="forceBigDecimals" value="false"/>
21         </javaTypeResolver>
22 
23         <!-- !!!! Model Configurations !!!! -->
24         <javaModelGenerator targetPackage="com.goku.druid.demo.model" targetProject="src/main/java">
25             <property name="enableSubPackages" value="false"/>
26             <property name="trimStrings" value="true"/>
27         </javaModelGenerator>
28 
29         <!-- !!!! Mapper XML Configurations !!!! -->
30         <sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
31             <property name="enableSubPackages" value="false"/>
32         </sqlMapGenerator>
33 
34         <!-- !!!! Mapper Interface Configurations !!!! -->
35         <javaClientGenerator targetPackage="com.goku.druid.demo.mapper" targetProject="src/main/java" type="XMLMAPPER">
36             <property name="enableSubPackages" value="false"/>
37         </javaClientGenerator>
38 
39         <!-- !!!! Table Configurations !!!! -->
40         <table tableName="user_" domainObjectName="User" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
41                enableUpdateByExample="false"/>
42     </context>
43 </generatorConfiguration>
View Code

Maven生成语句配置(mybatis-generator:generate

Maven生成语句启动

修改 generatorConfig.xml 里 Table Configurations 的相关配置,然后启动生成

Mybatis之SpringBoot配置

mybatis-spring-boot-starter方式

1 <dependency>
2     <groupId>org.mybatis.spring.boot</groupId>
3     <artifactId>mybatis-spring-boot-starter</artifactId>
4     <version>1.0.0</version>
5 </dependency>
View Code

application.properties配置

1 # mybatis
2 mybatis.type-aliases-package=com.goku.mybatis.model
3 mybatis.mapper-locations=classpath:mapping/**/*.xml
4         
5 #pagehelper
6 pagehelper.helperDialect=mysql
7 pagehelper.reasonable=true
8 pagehelper.supportMethodsArguments=true
9 pagehelper.params=count=countSql
View Code

GITHUB

github :  https://github.com/nbfujx/learn-java-demo/tree/master/Goku.MybatisDemo.XML

转载于:https://www.cnblogs.com/nbfujx/p/7702571.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/428650.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1282B1. K for the Price of One (Easy Version)

B1. K for the Price of One (Easy Version)&#xff1a;题目 两种情况&#xff0c;前面取一或者前面不取#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const int …

GIT的Push和Pull,强制Pull覆盖本地命令

连接命令&#xff1a; git remote add origin 你Git库的地址 其中&#xff0c;origin是你对这个Git库地址的标识。 一. 把文件从本地上传到库中 第一步&#xff1a;使用命令 git add命令把文件添加到暂存区里面去。git add * 命令是将当前文件夹内所有文件均添加到暂存区。 举…

1284B. New Year and Ascent Sequence

B. New Year and Ascent Sequence&#xff1a;题目 小小思维题#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const int mod 1e9 7; signed main() {int t;cin>…

linux运维、架构之路-Zabbix监控

一、监控常用命令 1、物理服务器监控命令 ①添加yum源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo ②安装 yum -y install OpenIPMI ipmitoo…

505B. Mr. Kitayuta‘s Colorful Graph

B. Mr. Kitayuta’s Colorful Graph&#xff1a;题目 一开始就像到了DFS&#xff0c;并查集也不难想到。 弗洛伊德算法倒是不容易想到&#xff0c;平时不这么用。。。。。#include <bits/stdc.h> using namespace std; #define int long long // vector<int> a((i…

vi命令

vi命令是UNIX操作系统和类UNIX操作系统中最通用的全屏幕纯文本编辑器。 Linux中的vi编辑器叫vim&#xff0c;它是vi的增强版&#xff08;vi Improved&#xff09;&#xff0c;与vi编辑器完全兼容&#xff0c;而且实现了很多增强功能。 vi编辑器支持编辑模式和命令模式&#xff…

1189C. Candies

C. Candies&#xff1a;题目 思维题&#xff0c;我是笨蛋。我看了半天也没想明白怎么dp&#xff0c;可恶啊。#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c((int)6e5); const i…

SQL基本语法

SQL 基本语法 表库操作 创建表create table 表名(字段名 类型(长度) 约束,字段名 类型(长度) 约束); 创建主键约束id int primary key, primary key(id) // 在创建表最后创建主键约束 删除主键alter table 表名 drop primary key; 主键自动增长主键字段后加auto_increment(只适…

136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one. 题目含义&#xff1a;给定的数组中&#xff0c;每个数字出现两次&#xff0c;只有一个数字出现了一次&#xff0c;找出这个数字 1 public int singleNumber(int[] nums) {…

797B. Odd sum

B. Odd sum&#xff1a;题目 一道小小的贪心#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c[(int)6e5]; const int mod 1e9 7; string s; multiset<int> se; signed mai…

602B. Approximating a Constant Range

B. Approximating a Constant Range&#xff1a;题目 可恶啊&#xff0c;不知道为什么我双指针的代码不过&#xff0c;重新写了个。。。。。#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((i…

1415C. Bouncing Ball

C. Bouncing Ball&#xff1a;题目 很好的dp&#xff0c;1400分难见的题#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c[(int)6e5]; const int mod 1e9 7; string s; signed m…

几种直播流媒体协议

题外话&#xff1a; HTTP渐进下载流媒体播放: 基于TCP。 yy、乐视、爱奇艺、优酷土豆、搜狐视频、花椒直播&#xff0c;主要还是通过rtmp&hls来实现的&#xff0c; 但他们也意识到rtmp的天生缺陷&#xff0c;所以不管是技术预研也好&#xff0c;还是测试版也好&#xff0c…

253B. Physics Practical

B. Physics Practical&#xff1a;题目 太简单的题目了&#xff0c;和dp没啥关系#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c[(int)6e5]; const int mod 1e9 7; signed mai…

程序常识

闰年判定&#xff08;三种情况&#xff1a;或&#xff09;&#xff1a; 非整百年&#xff1a;能够被4整除&#xff0c;且不能被100整除&#xff08;year % 4 0 && year % 100 ! 0&#xff09;。整百年&#xff1a;能够被400整除&#xff08;year % 400 0&#xff09;…

940B. Our Tanya is Crying Out Loud

B. Our Tanya is Crying Out Loud&#xff1b;题目 1特判&#xff0c;因为除1还是本身&#xff0c;这点就很淦#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c[(int)6e5]; const …

548B. Mike and Fun

B. Mike and Fun&#xff1a;题目 太离谱了呀&#xff0c;这啥遍历题啊。。。#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c[(int)6e5]; const int mod 1e9 7; int g[1001][1…

EntityFramwork常见问题

1.常用的语句有哪些 添加migration dotnet ef migrations add [MIgrationName] 删除刚添加的migration dotnet ef migrations remove 更新数据库 dotnet ef database update、 2.在代码中用 attribute (code first) 限制表中字段的类型及主外键 主键 [Key]自…

359B. Permutation

B. Permutation&#xff1a;题目 很容易就发现&#xff0c;按顺序正好等于0。把i和i2换一次可以加2&#xff0c;所以k是多少就换几次#include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5)…

180C. Letter

C. Letter&#xff1a;题目 #include <bits/stdc.h> using namespace std; #define int long long vector<int> a((int)6e5); vector<int> b((int)6e5), c[(int)6e5]; const int mod 1e9 7; string s; signed main() {cin>>s;int n s.length();s …