Browse Source

支持数据库 order key 等关键词转义 curd 操作

青苗 9 năm trước cách đây
mục cha
commit
cdb71e6560

+ 55 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/entity/AbcUser.java

@@ -0,0 +1,55 @@
+package com.baomidou.entity;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotations.IdType;
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+
+/**
+ *
+ * 
+ *
+ */
+@TableName("abc_user")
+public class AbcUser implements Serializable {
+
+	@TableField(exist = false)
+	protected static final long serialVersionUID = 1L;
+
+	/**  */
+	@TableId(type = IdType.AUTO)
+	protected Integer id;
+
+	/**  */
+	protected String order;
+
+	/**  */
+	protected Integer uid;
+
+	public Integer getId() {
+		return this.id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public String getOrder() {
+		return this.order;
+	}
+
+	public void setOrder(String order) {
+		this.order = order;
+	}
+
+	public Integer getUid() {
+		return this.uid;
+	}
+
+	public void setUid(Integer uid) {
+		this.uid = uid;
+	}
+
+}

+ 65 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/entity/User.java

@@ -0,0 +1,65 @@
+package com.baomidou.entity;
+
+import java.io.Serializable;
+
+import com.baomidou.mybatisplus.annotations.IdType;
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+
+/**
+ *
+ * 用户表
+ *
+ */
+public class User implements Serializable {
+
+	@TableField(exist = false)
+	protected static final long serialVersionUID = 1L;
+
+	/** 主键ID */
+	@TableId(value = "test_id", type = IdType.AUTO)
+	protected Long testId;
+
+	/** 名称 */
+	protected String name;
+
+	/** 年龄 */
+	protected Integer age;
+
+	/** 测试下划线字段命名类型 */
+	@TableField(value = "test_type")
+	protected Integer testType;
+
+	public Long getTestId() {
+		return this.testId;
+	}
+
+	public void setTestId(Long testId) {
+		this.testId = testId;
+	}
+
+	public String getName() {
+		return this.name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Integer getAge() {
+		return this.age;
+	}
+
+	public void setAge(Integer age) {
+		this.age = age;
+	}
+
+	public Integer getTestType() {
+		return this.testType;
+	}
+
+	public void setTestType(Integer testType) {
+		this.testType = testType;
+	}
+
+}

+ 14 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/mapper/AbcUserMapper.java

@@ -0,0 +1,14 @@
+package com.baomidou.mapper;
+
+import com.baomidou.entity.AbcUser;
+import com.baomidou.mybatisplus.mapper.AutoMapper;
+
+/**
+ *
+ * AbcUser 表数据库控制层接口
+ *
+ */
+public interface AbcUserMapper extends AutoMapper<AbcUser> {
+
+
+}

+ 14 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/mapper/UserMapper.java

@@ -0,0 +1,14 @@
+package com.baomidou.mapper;
+
+import com.baomidou.entity.User;
+import com.baomidou.mybatisplus.mapper.AutoMapper;
+
+/**
+ *
+ * User 表数据库控制层接口
+ *
+ */
+public interface UserMapper extends AutoMapper<User> {
+
+
+}

+ 10 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/mapper/xml/AbcUserMapper.xml

@@ -0,0 +1,10 @@
+<?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">
+<mapper namespace="com.baomidou.mapper.AbcUserMapper">
+
+	<!-- 通用查询结果列-->
+	<sql id="Base_Column_List">
+		 id, order, uid
+	</sql>
+
+</mapper>

+ 10 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/mapper/xml/UserMapper.xml

@@ -0,0 +1,10 @@
+<?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">
+<mapper namespace="com.baomidou.mapper.UserMapper">
+
+	<!-- 通用查询结果列-->
+	<sql id="Base_Column_List">
+		 test_id AS testId, name, age, test_type AS testType
+	</sql>
+
+</mapper>

+ 14 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/service/IAbcUserService.java

@@ -0,0 +1,14 @@
+package com.baomidou.service;
+
+import com.baomidou.entity.AbcUser;
+import com.baomidou.framework.service.ISuperService;
+
+/**
+ *
+ * AbcUser 表数据服务层接口
+ *
+ */
+public interface IAbcUserService extends ISuperService<AbcUser> {
+
+
+}

+ 14 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/service/IUserService.java

@@ -0,0 +1,14 @@
+package com.baomidou.service;
+
+import com.baomidou.entity.User;
+import com.baomidou.framework.service.ISuperService;
+
+/**
+ *
+ * User 表数据服务层接口
+ *
+ */
+public interface IUserService extends ISuperService<User> {
+
+
+}

+ 19 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/service/impl/AbcUserServiceImpl.java

@@ -0,0 +1,19 @@
+package com.baomidou.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mapper.AbcUserMapper;
+import com.baomidou.entity.AbcUser;
+import com.baomidou.service.IAbcUserService;
+import com.baomidou.framework.service.impl.SuperServiceImpl;
+
+/**
+ *
+ * AbcUser 表数据服务层接口实现类
+ *
+ */
+@Service
+public class AbcUserServiceImpl extends SuperServiceImpl<AbcUserMapper, AbcUser> implements IAbcUserService {
+
+
+}

+ 19 - 0
mybatis-plus/D:/mybatis-plus/com/baomidou/service/impl/UserServiceImpl.java

@@ -0,0 +1,19 @@
+package com.baomidou.service.impl;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mapper.UserMapper;
+import com.baomidou.entity.User;
+import com.baomidou.service.IUserService;
+import com.baomidou.framework.service.impl.SuperServiceImpl;
+
+/**
+ *
+ * User 表数据服务层接口实现类
+ *
+ */
+@Service
+public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implements IUserService {
+
+
+}

+ 52 - 32
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/DBKeywordsProcessor.java

@@ -1,3 +1,18 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.baomidou.mybatisplus.toolkit;
 
 import java.io.BufferedReader;
@@ -6,45 +21,50 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.logging.Logger;
 
 /**
+ * <p>
  * 数据库关键字替换
+ * </p>
+ * 
+ * @author liupeng
+ * @Date 2016-08-25
  */
 public class DBKeywordsProcessor {
+	protected static final Logger logger = Logger.getLogger("DBKeywordsProcessor");
+	private static final String ESCAPE_CHARACTER = "`";
+	private static final Set<String> KEYWORDS = new HashSet<String>();
 
-    private static final String ESCAPE_CHARACTER = "`";
-
-    private static final Set<String> KEYWORDS = new HashSet<String>();
+	static {
+		BufferedReader br = null;
+		try {
+			InputStream in = DBKeywordsProcessor.class.getClassLoader().getResourceAsStream("database_keywords.dic");
+			br = new BufferedReader(new InputStreamReader(in));
+			String keyword = null;
+			while ((keyword = br.readLine()) != null) {
+				KEYWORDS.add(keyword);
+			}
+		} catch (Exception e) {
+			logger.severe("If you want to support the keyword query, must have database_keywords.dic \n"
+					+ e.getMessage());
+		} finally {
+			if (br != null) {
+				try {
+					br.close();
+				} catch (IOException e) {
+					logger.severe(e.getMessage());
+				}
+			}
+		}
 
-    static {
-        BufferedReader br = null;
-        try {
-            InputStream in = DBKeywordsProcessor.class.getClassLoader().getResourceAsStream("database_keywords.dic");
-            br = new BufferedReader(new InputStreamReader(in));
-            String keyword = null;
-            while ((keyword = br.readLine()) != null) {
-                KEYWORDS.add(keyword);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            if (br != null) {
-                try {
-                    br.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
+	}
 
-    }
-
-    public static String convert(String keyword) {
-        if (KEYWORDS.contains(keyword)) {
-            return new StringBuffer().append(ESCAPE_CHARACTER).append(keyword).append(ESCAPE_CHARACTER).toString();
-        }
-        return keyword;
-    }
+	public static String convert(String keyword) {
+		if (KEYWORDS.contains(keyword)) {
+			return new StringBuffer().append(ESCAPE_CHARACTER).append(keyword).append(ESCAPE_CHARACTER).toString();
+		}
+		return keyword;
+	}
 
 }
-

+ 0 - 0
mybatis-plus/src/main/resources/database_keywords.dic → mybatis-plus/src/test/resources/database_keywords.dic