# MyBatis3
**Repository Path**: zhtt/mybatits3
## Basic Information
- **Project Name**: MyBatis3
- **Description**: No description available
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2017-04-22
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# MyBatits3
## 建表语句
``` sql
CREATE DATABASE test3 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE IF NOT EXISTS zdshbzryexcel(
id INT UNSIGNED AUTO_INCREMENT,
xm VARCHAR(100) ,
xb VARCHAR(40) ,
jtgx VARCHAR(40),
PRIMARY KEY ( id )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
create database test4 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
CREATE TABLE IF NOT EXISTS zdshbzryexcel(
id INT UNSIGNED AUTO_INCREMENT,
xm VARCHAR(100) ,
xb VARCHAR(40) ,
jtgx VARCHAR(40),
PRIMARY KEY ( id )
)ENGINE=InnoDB DEFAULT CHARSET=gbk;
```
## mysql乱码解决方法
* 1、停止mysql服务
services.msc
* 2、打开配置文件
C:\Program Files\MySQL\MySQL Server 5.0\my.ini
* 3、修改配置文件
在[client]、[mysql]、[mysqld]
无则增加、有则修改
default-character-set=utf8
## mybatis sql相关
### 批量执行SQL
``` sql
begin
delete from t_user where id=#{id};
delete from r_user_role where user_id=#{id};
end;
```
### 指定全局表名
``` sql
table_space_name.t_user
```
### 批量更新
1. java代码如下:
```
public void addEmps(@Param("emps")List emps);
```
2. sql语句如下:
```
INSERT INTO tb1_emplyee(last_name,email,gender,d_id)
VALUES
(#{emp.lastName},#{emp.email},#{emp.gender},#{emp.dept.id})
```
### 逻辑比较
First Header | Second Header| Second Header
------------- | -------------| -------------
& | `&`|
' | `'`
" | `"`
< | `<`|``
<= | `<=`|``
`>` | `>`|` ]]>`
`>=` | `>=`|`= ]]>`
## 查询时的特殊符号
``` java
public static String decode(String str, String defaultValue) {
if (str == null) {
return defaultValue;
}
try {
return URLDecoder.decode(str, "UTF-8");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return defaultValue;
}
}
import org.springframework.util.StringUtils;
public class SpecialCharacherUtils {
public static String toMyString(String oldString) {
String symbol = "";
if(oldString.contains("%")){
symbol = "%";
}else if(oldString.contains("_")){
symbol = "_";
}else if(oldString.contains("[")){
symbol = "[";
}else if(oldString.contains("]")){
symbol = "]";
}else{
return oldString;
}
if (!StringUtils.isEmpty(oldString)) {
int length = oldString.length();
String repString = "*";
int flag = oldString.indexOf(symbol);
String newString1 = oldString.substring(0, flag);
String newString2 = oldString.substring(flag, length);
String newString = newString1 + repString + newString2;
return newString;
} else {
return oldString;
}
}
}
'%' || #{_like_name} || '%' ESCAPE '*'
```
* 多条件逻辑判断
``` sql
```