diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 4a1bf99..ba9e825 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,7 +7,6 @@
-
diff --git a/admin/pom.xml b/admin/pom.xml
index c5a64c4..346ef14 100644
--- a/admin/pom.xml
+++ b/admin/pom.xml
@@ -36,11 +36,6 @@
wsqlite
-
- org.mybatis.spring.boot
- mybatis-spring-boot-starter
-
-
org.springframework.boot
spring-boot-starter-web
@@ -51,19 +46,12 @@
commons-io
-
-
- com.github.pagehelper
- pagehelper-spring-boot-starter
-
-
org.springframework.boot
spring-boot-starter-freemarker
-
org.springframework.boot
spring-boot-devtools
@@ -86,12 +74,6 @@
net.sf.dozer
dozer
-
-
- mysql
- mysql-connector-java
- runtime
-
diff --git a/admin/src/main/java/com/example/config/SqliteConfig.java b/admin/src/main/java/com/example/config/SqliteConfig.java
new file mode 100644
index 0000000..d16755b
--- /dev/null
+++ b/admin/src/main/java/com/example/config/SqliteConfig.java
@@ -0,0 +1,42 @@
+package com.example.config;
+
+import com.example.module.admin.ent.Mapping;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.system.ApplicationHome;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.util.StringUtils;
+import xyz.wbsite.wsqlite.ObjectClient;
+
+import java.io.File;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+
+@Configuration
+public class SqliteConfig {
+ @Value("${dbpath}")
+ public String dbpath;
+
+ @Bean
+ public ObjectClient registry() {
+ try {
+ if (StringUtils.isEmpty(dbpath)) {
+ ApplicationHome home = new ApplicationHome(getClass());
+ // 当前运行jar文件
+ File jarFile = home.getSource() != null ? home.getSource() : home.getDir();
+ //jar同目录
+ dbpath = jarFile.getParent();
+ }
+
+ ArrayList objects = new ArrayList<>();
+ objects.add(Mapping.class);
+ return new ObjectClient(new File(dbpath,"data.db"), objects);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/admin/src/main/java/com/example/module/admin/ent/Mapping.java b/admin/src/main/java/com/example/module/admin/ent/Mapping.java
index 27b0643..e9a355d 100644
--- a/admin/src/main/java/com/example/module/admin/ent/Mapping.java
+++ b/admin/src/main/java/com/example/module/admin/ent/Mapping.java
@@ -1,6 +1,9 @@
package com.example.module.admin.ent;
import com.example.frame.base.BaseEntity;
+import xyz.wbsite.wsqlite.anonation.TableField;
+
+import java.util.Date;
/**
* MAPPING - 映射
@@ -9,42 +12,78 @@ import com.example.frame.base.BaseEntity;
* @version 0.0.1
* @since 2019-09-28
*/
-public class Mapping extends BaseEntity {
+public class Mapping {
/**
* ID - 主键
*/
+ @TableField
private Long id;
/**
- * USERNAME - 用户名
+ * NAME - 映射名称
+ */
+ @TableField
+ private String name;
+ /**
+ * VALUE - 映射值
*/
- private String username;
+ @TableField
+ private String value;
/**
- * PASSWORD - 用户密码
+ * BZ - 备注
*/
- private String password;
+ @TableField
+ private String bz;
+ @TableField
+ private Date createTime;
+ @TableField
+ private boolean isDeleted;
- public Long getId() {
- return this.id;
+ public String getName() {
+ return name;
}
- public void setId(Long id) {
- this.id = id;
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
}
- public String getUsername() {
- return this.username;
+ public void setValue(String value) {
+ this.value = value;
}
- public void setUsername(String username) {
- this.username = username;
+ public String getBz() {
+ return bz;
}
- public String getPassword() {
- return this.password;
+ public void setBz(String bz) {
+ this.bz = bz;
}
- public void setPassword(String password) {
- this.password = password;
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public boolean isDeleted() {
+ return isDeleted;
+ }
+
+ public void setDeleted(boolean deleted) {
+ isDeleted = deleted;
+ }
+
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
}
}
\ No newline at end of file
diff --git a/admin/src/main/java/com/example/module/admin/mgr/MappingManagerImpl.java b/admin/src/main/java/com/example/module/admin/mgr/MappingManagerImpl.java
index 58c95e4..cd584f4 100644
--- a/admin/src/main/java/com/example/module/admin/mgr/MappingManagerImpl.java
+++ b/admin/src/main/java/com/example/module/admin/mgr/MappingManagerImpl.java
@@ -15,11 +15,9 @@ import com.example.module.admin.rsp.MappingCreateResponse;
import com.example.module.admin.rsp.MappingDeleteResponse;
import com.example.module.admin.rsp.MappingFindResponse;
import com.example.module.admin.rsp.MappingUpdateResponse;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import com.github.pagehelper.util.StringUtil;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
+import xyz.wbsite.wsqlite.ObjectClient;
/**
* MAPPING - 映射
@@ -31,6 +29,9 @@ import org.springframework.transaction.annotation.Transactional;
@Service
public class MappingManagerImpl implements MappingManager {
+ @Autowired
+ private ObjectClient objectClient;
+
/**
* 插入
*
@@ -49,8 +50,9 @@ public class MappingManagerImpl implements MappingManager {
long id = IDgenerator.nextId();
Mapping entity = MapperUtil.map(request, Mapping.class);
entity.setId(id);
+ objectClient.insert(Mapping.class, entity);
-
+ response.setId(id);
return response;
}
@@ -99,7 +101,6 @@ public class MappingManagerImpl implements MappingManager {
* @param token 令牌
* @return 响应
*/
- @Transactional(readOnly = true)
public MappingFindResponse find(MappingFindRequest request, Token token) {
MappingFindResponse response = new MappingFindResponse();
diff --git a/admin/src/main/java/com/example/module/admin/req/MappingCreateRequest.java b/admin/src/main/java/com/example/module/admin/req/MappingCreateRequest.java
index 41b9148..0b0c3c8 100644
--- a/admin/src/main/java/com/example/module/admin/req/MappingCreateRequest.java
+++ b/admin/src/main/java/com/example/module/admin/req/MappingCreateRequest.java
@@ -1,8 +1,11 @@
package com.example.module.admin.req;
import com.example.frame.base.BaseRequest;
+
import javax.validation.constraints.NotNull;
import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.Pattern;
+
import org.hibernate.validator.constraints.Length;
/**
@@ -15,30 +18,45 @@ import org.hibernate.validator.constraints.Length;
public class MappingCreateRequest extends BaseRequest {
/**
- * 用户名
+ * NAME - 映射名称
+ */
+ @NotNull(message = "映射名称不能为空")
+ private String name;
+
+ /**
+ * VALUE - 映射值
*/
- @Length(min = 0, max = 100, message = "用户名长度不合法(0-100)")
- private String username;
+ @NotNull(message = "映射值不能为空")
+ @Pattern(regexp = "[^/]*", message = "映射值不能存在/")
+ @Pattern(regexp = "\\w*", message = "映射值需为英文")
+ private String value;
/**
- * 用户密码
+ * BZ - 备注
*/
- @Length(min = 0, max = 100, message = "用户密码长度不合法(0-100)")
- private String password;
+ private String bz;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
- public String getUsername() {
- return this.username;
+ public String getValue() {
+ return value;
}
- public void setUsername(String username) {
- this.username = username;
+ public void setValue(String value) {
+ this.value = value;
}
- public String getPassword() {
- return this.password;
+ public String getBz() {
+ return bz;
}
- public void setPassword(String password) {
- this.password = password;
+ public void setBz(String bz) {
+ this.bz = bz;
}
}
diff --git a/admin/src/main/resources/application-dev.properties b/admin/src/main/resources/application-dev.properties
index d66df1f..3ba9337 100644
--- a/admin/src/main/resources/application-dev.properties
+++ b/admin/src/main/resources/application-dev.properties
@@ -16,23 +16,11 @@ web.welcome.page=/index.htm
# 需要验证授权, 既访问时组装Token
web.url.auth.included=/**
# 不需要验证授权, 或该请求有自己的验证机制
-web.url.auth.excluded=/favicon.ico,/static/**,/api,/login.htm
+web.url.auth.excluded=/favicon.ico,/static/**,/api,/login.htm,/app
# 日志配置
logging.path=D://
logging.levels=DEBUG
logging.config=classpath:logback-config.xml
-# mysql
-spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
-spring.datasource.username=test
-spring.datasource.password=123456
-# mybatis
-mybatis.mapper-locations=classpath:**/mpr/*.xml
-# pagehelper
-pagehelper.autoRuntimeDialect=true
-pagehelper.reasonable=false
-pagehelper.supportMethodsArguments=true
-pagehelper.params=count=countSql
# jackson 相关配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
@@ -60,4 +48,5 @@ spring.freemarker.settings.url_escaping_charset=utf-8
# 文件上传配置
spring.servlet.multipart.resolveLazily=false
spring.servlet.multipart.max-file-size=100MB
-spring.servlet.multipart.max-request-size=100MB
\ No newline at end of file
+spring.servlet.multipart.max-request-size=100MB
+dbpath=
\ No newline at end of file
diff --git a/admin/src/main/resources/application-prod.properties b/admin/src/main/resources/application-prod.properties
index 7d37eb4..30ba5e8 100644
--- a/admin/src/main/resources/application-prod.properties
+++ b/admin/src/main/resources/application-prod.properties
@@ -21,18 +21,6 @@ web.url.auth.excluded=/favicon.ico,/static/**,/api,/login.htm
logging.path=/root/
logging.levels=INFO
logging.config=classpath:logback-config.xml
-# mysql
-spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
-spring.datasource.username=test
-spring.datasource.password=123456
-# mybatis
-mybatis.mapper-locations=classpath:**/mpr/*.xml
-# pagehelper
-pagehelper.autoRuntimeDialect=true
-pagehelper.reasonable=false
-pagehelper.supportMethodsArguments=true
-pagehelper.params=count=countSql
# jackson 相关配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
@@ -60,4 +48,4 @@ spring.freemarker.settings.url_escaping_charset=utf-8
# 文件上传配置
spring.servlet.multipart.resolveLazily=false
spring.servlet.multipart.max-file-size=100MB
-spring.servlet.multipart.max-request-size=100MB
\ No newline at end of file
+spring.servlet.multipart.max-request-size=100MB
diff --git a/admin/src/main/resources/dbtool/EXAMPLE-WEB.xml b/admin/src/main/resources/dbtool/EXAMPLE-WEB.xml
deleted file mode 100644
index 9f24040..0000000
--- a/admin/src/main/resources/dbtool/EXAMPLE-WEB.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-EXAMPLE-WEB
-com.example
-author
-
-
-用户
-SYS
-usermodel
-true
-
-
-
-
-
-
diff --git a/admin/src/main/resources/dbtool/usermodel_table/ALL_TABLE.sql b/admin/src/main/resources/dbtool/usermodel_table/ALL_TABLE.sql
deleted file mode 100644
index 98204c2..0000000
--- a/admin/src/main/resources/dbtool/usermodel_table/ALL_TABLE.sql
+++ /dev/null
@@ -1,17 +0,0 @@
-
--- ----------------------------
--- Table structure for MAPPING - 映射
--- ----------------------------
-CREATE TABLE `SYSMAPPING` (
- `ID` BIGINT(20) NOT NULL COMMENT '主键',
- `USERNAME` VARCHAR(100) COMMENT '用户名',
- `PASSWORD` VARCHAR(100) COMMENT '用户密码',
- `ROW_VERSION` BIGINT(20) NOT NULL DEFAULT 0 COMMENT '行版本',
- `IS_DELETED` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否已删除',
- `CREATE_BY` BIGINT(20) NOT NULL COMMENT '创建用户',
- `CREATE_TIME` DATETIME NOT NULL COMMENT '创建时间',
- `LAST_UPDATE_BY` BIGINT(20) DEFAULT NULL COMMENT '最后更新用户',
- `LAST_UPDATE_TIME` DATETIME DEFAULT NULL COMMENT '最后更新时间',
-PRIMARY KEY (`ID`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='映射';
-
diff --git a/admin/src/main/resources/dbtool/usermodel_table/USER.sql b/admin/src/main/resources/dbtool/usermodel_table/USER.sql
deleted file mode 100644
index 0b9ab82..0000000
--- a/admin/src/main/resources/dbtool/usermodel_table/USER.sql
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-Target : MYSQL
-Author
-Date: 2019-08-14
-*/
-
--- ----------------------------
--- Table structure for USER - 用户
--- ----------------------------
-
-CREATE TABLE `SYSUSER` (
- `ID` BIGINT(20) NOT NULL COMMENT '主键',
- `USERNAME` VARCHAR(100) COMMENT '用户名',
- `PASSWORD` VARCHAR(100) COMMENT '用户密码',
- `ROW_VERSION` BIGINT(20) NOT NULL DEFAULT 0 COMMENT '行版本',
- `IS_DELETED` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否已删除',
- `CREATE_BY` BIGINT(20) NOT NULL COMMENT '创建用户',
- `CREATE_TIME` DATETIME NOT NULL COMMENT '创建时间',
- `LAST_UPDATE_BY` BIGINT(20) DEFAULT NULL COMMENT '最后更新用户',
- `LAST_UPDATE_TIME` DATETIME DEFAULT NULL COMMENT '最后更新时间',
-PRIMARY KEY (`ID`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户';
diff --git a/admin/src/main/resources/lib/ojdbc7-12.1.0.2.jar b/admin/src/main/resources/lib/ojdbc7-12.1.0.2.jar
deleted file mode 100644
index d72b9eb..0000000
Binary files a/admin/src/main/resources/lib/ojdbc7-12.1.0.2.jar and /dev/null differ
diff --git a/admin/src/main/resources/templates/layout/app.ftl b/admin/src/main/resources/templates/layout/app.ftl
deleted file mode 100644
index ee9c6be..0000000
--- a/admin/src/main/resources/templates/layout/app.ftl
+++ /dev/null
@@ -1,217 +0,0 @@
-
-
-
-
-
-
- <#--baseJs-->
-
- <#--移动端ui-->
-
-
- <#--ajax接口-->
-
-
-
-
-<#include Layout.setControl("mint-ui-extend")/>
-
-
-
-
-
-
-
-
-
-
- 返回
-
-
-
-
- Hello world demo
-
-
-
-
-
-
- 关闭
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 打印类容
-
-
-
-
-
-
-
diff --git a/admin/src/main/resources/templates/screen/index.ftl b/admin/src/main/resources/templates/screen/index.ftl
index d893aeb..6509626 100644
--- a/admin/src/main/resources/templates/screen/index.ftl
+++ b/admin/src/main/resources/templates/screen/index.ftl
@@ -17,16 +17,7 @@
系统设置
- 用户管理
- 机构管理
- 角色管理
-
-
-
-
- 日志管理
-
- 登录日志
+ 映射管理
@@ -47,7 +38,7 @@
- 我的
+ 我的
修改信息
@@ -266,8 +257,8 @@
properties: {
uniqueOpened: true,//是否保持一个子菜单展开
isCollapse: false,//左侧菜单是否收缩
- transition:false,
- defaultActive:"1-1",
+ transition: false,
+ defaultActive: "1-1",
}
},
methods: {
@@ -290,13 +281,7 @@
handleSelect: function (index) {
switch (index) {
case "1-1":
- this.addTab({title: "用户管理", name: "usersManager", url: "about:blank"});
- break;
- case "1-2":
- this.addTab({title: "机构管理", name: "departmentsManager", url: "about:blank"});
- break;
- case "1-3":
- this.addTab({title: "角色管理", name: "rolesManager", url: "about:blank"});
+ this.addTab({title: "映射管理", name: "usersManager", url: "about:blank"});
break;
}
return false;
diff --git a/admin/src/main/resources/templates/screen/login.ftl b/admin/src/main/resources/templates/screen/login.ftl
index 4f04ae0..69d58ca 100644
--- a/admin/src/main/resources/templates/screen/login.ftl
+++ b/admin/src/main/resources/templates/screen/login.ftl
@@ -6,7 +6,7 @@
-
+
diff --git a/admin/src/test/java/com/example/UtilTest.java b/admin/src/test/java/com/example/UtilTest.java
index 7a425e0..4990885 100644
--- a/admin/src/test/java/com/example/UtilTest.java
+++ b/admin/src/test/java/com/example/UtilTest.java
@@ -5,7 +5,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.transaction.annotation.Transactional;
/**
* UtilTest - - 测试用例
@@ -16,7 +15,6 @@ import org.springframework.transaction.annotation.Transactional;
*/
@RunWith(SpringRunner.class)
@SpringBootTest
-@Transactional
public class UtilTest {
@Test
diff --git a/admin/src/test/java/com/example/mapping/MappingTest.java b/admin/src/test/java/com/example/mapping/MappingTest.java
new file mode 100644
index 0000000..7388757
--- /dev/null
+++ b/admin/src/test/java/com/example/mapping/MappingTest.java
@@ -0,0 +1,38 @@
+package com.example.mapping;
+
+import com.example.frame.base.Token;
+import com.example.frame.utils.IDgenerator;
+import com.example.frame.utils.LocalData;
+import com.example.module.admin.mgr.MappingManager;
+import com.example.module.admin.req.MappingCreateRequest;
+import com.example.module.admin.rsp.MappingCreateResponse;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static junit.framework.TestCase.assertTrue;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class MappingTest {
+
+ @Autowired
+ private MappingManager mappingManager;
+
+ @Autowired
+ private Token token;
+
+ @Test
+ public void createMapping() {
+ MappingCreateRequest createRequest = new MappingCreateRequest();
+ createRequest.setName("测试");
+ createRequest.setValue("test");
+ MappingCreateResponse mappingCreateResponse = mappingManager.create(createRequest, token);
+
+
+ assertTrue(!mappingCreateResponse.hasError());
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index b561422..e777e54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,6 +4,11 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
+
+ admin
+ wsqlite
+
+
org.springframework.boot
spring-boot-starter-parent
@@ -14,6 +19,7 @@
xyz.wbsite
nginx-admin
1.0-SNAPSHOT
+ pom
UTF-8
@@ -39,24 +45,6 @@
pom
import
-
-
- com.github.pagehelper
- pagehelper-spring-boot-starter
- ${pagehelper-version}
-
-
-
- org.mybatis.spring.boot
- mybatis-spring-boot-starter
- ${mybatis-version}
-
-
-
- org.mybatis.caches
- mybatis-ehcache
- ${ehcache-version}
-
net.sf.dozer
diff --git a/wsqlite/pom.xml b/wsqlite/pom.xml
index 559ebae..cc71de7 100644
--- a/wsqlite/pom.xml
+++ b/wsqlite/pom.xml
@@ -13,6 +13,7 @@
xyz.wbsite
wsqlite
1.0-SNAPSHOT
+ jar
diff --git a/wsqlite/src/main/java/xyz/wbsite/wsqlite/ObjectClient.java b/wsqlite/src/main/java/xyz/wbsite/wsqlite/ObjectClient.java
index eb3e7f0..8c7da51 100644
--- a/wsqlite/src/main/java/xyz/wbsite/wsqlite/ObjectClient.java
+++ b/wsqlite/src/main/java/xyz/wbsite/wsqlite/ObjectClient.java
@@ -17,7 +17,7 @@ import java.util.Map;
*/
public class ObjectClient extends Client {
- private Map classMap = new HashMap();
+ private Map classMap = new HashMap<>();
/**
* 构造函数
@@ -53,6 +53,20 @@ public class ObjectClient extends Client {
} else if (f.getType() == Boolean.class || f.getType() == boolean.class) {
sql.append(f.getName().toUpperCase());
sql.append(" BOOLEAN,");
+ } else if (f.getType() == Byte.class || f.getType() == byte.class ||
+ f.getType() == Short.class || f.getType() == short.class ||
+ f.getType() == Character.class || f.getType() == char.class ||
+ f.getType() == Integer.class || f.getType() == int.class ||
+ f.getType() == Long.class || f.getType() == long.class) {
+ sql.append(f.getName().toUpperCase());
+ sql.append(" INTEGER,");
+ } else if (f.getType() == Float.class || f.getType() == float.class ||
+ f.getType() == Double.class || f.getType() == double.class) {
+ sql.append(f.getName().toUpperCase());
+ sql.append(" REAL,");
+ } else if (f.getType() == Byte[].class || f.getType() == byte[].class) {
+ sql.append(f.getName().toUpperCase());
+ sql.append(" BLOB,");
}
}
}
@@ -64,7 +78,7 @@ public class ObjectClient extends Client {
}
}
- public void insert(Class poClass, T po) throws SQLException, ClassNotFoundException {
+ public int insert(Class poClass, T po) {
try {
Class aClass = classMap.get(poClass.getName());
if (aClass == null) {
@@ -95,8 +109,23 @@ public class ObjectClient extends Client {
valueSql.append("'");
valueSql.append(String.valueOf(value));
valueSql.append("'");
- } else {
+ } else if (f.getType() == Byte.class || f.getType() == byte.class ||
+ f.getType() == Short.class || f.getType() == short.class ||
+ f.getType() == Character.class || f.getType() == char.class ||
+ f.getType() == Integer.class || f.getType() == int.class ||
+ f.getType() == Long.class || f.getType() == long.class) {
+ valueSql.append("'");
+ valueSql.append(value);
+ valueSql.append("'");
+ } else if (f.getType() == Float.class || f.getType() == float.class ||
+ f.getType() == Double.class || f.getType() == double.class) {
+ valueSql.append("'");
valueSql.append(value);
+ valueSql.append("'");
+ } else if (f.getType() == Byte[].class || f.getType() == byte[].class) {
+ valueSql.append("'");
+ valueSql.append(value);
+ valueSql.append("'");
}
if (i != fs.size() - 1) {
fieldsSql.append(",");
@@ -109,13 +138,18 @@ public class ObjectClient extends Client {
sql.append(valueSql);
sql.append(")");
System.out.println("SQL ==> " + sql.toString());
- executeUpdate(sql.toString());
+ return executeUpdate(sql.toString());
}
} catch (IllegalAccessException e) {
e.printStackTrace();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
} finally {
destroyed();
}
+ return 0;
}
public int delete(Class poClass, String... wheres) throws SQLException, ClassNotFoundException {
@@ -173,8 +207,23 @@ public class ObjectClient extends Client {
sql.append("'");
sql.append(String.valueOf(value));
sql.append("'");
- } else {
+ } else if (f.getType() == Byte.class || f.getType() == byte.class ||
+ f.getType() == Short.class || f.getType() == short.class ||
+ f.getType() == Character.class || f.getType() == char.class ||
+ f.getType() == Integer.class || f.getType() == int.class ||
+ f.getType() == Long.class || f.getType() == long.class) {
+ sql.append("'");
+ sql.append(value);
+ sql.append("'");
+ } else if (f.getType() == Float.class || f.getType() == float.class ||
+ f.getType() == Double.class || f.getType() == double.class) {
+ sql.append("'");
sql.append(value);
+ sql.append("'");
+ } else if (f.getType() == Byte[].class || f.getType() == byte[].class) {
+ sql.append("'");
+ sql.append(value);
+ sql.append("'");
}
if (i != fs.size() - 1) {
sql.append(",");
@@ -202,7 +251,7 @@ public class ObjectClient extends Client {
}
public List select(Class poClass, int pageNumber, int pageSize, String... wheres) throws SQLException, ClassNotFoundException {
- ArrayList list = new ArrayList();
+ ArrayList list = new ArrayList<>();
try {
Class aClass = classMap.get(poClass.getName());
if (aClass == null) {
@@ -272,11 +321,35 @@ public class ObjectClient extends Client {
f.setAccessible(true);
if (f.getType() == String.class) {
- String string = resultSet.getString(f.getName());
- f.set(o, string);
+ String v = resultSet.getString(f.getName());
+ f.set(o, v);
} else if (f.getType() == Boolean.class || f.getType() == boolean.class) {
- boolean b = resultSet.getBoolean(f.getName());
- f.set(o, b);
+ boolean v = resultSet.getBoolean(f.getName());
+ f.set(o, v);
+ } else if (f.getType() == Byte.class || f.getType() == byte.class) {
+ byte v = resultSet.getByte(f.getName());
+ f.set(o, v);
+ } else if (f.getType() == Short.class || f.getType() == short.class) {
+ short v = resultSet.getShort(f.getName());
+ f.set(o, v);
+ } else if (f.getType() == Character.class || f.getType() == char.class) {
+ short v = resultSet.getShort(f.getName());
+ f.set(o, (char) v);
+ } else if (f.getType() == Integer.class || f.getType() == int.class) {
+ int v = resultSet.getInt(f.getName());
+ f.set(o, v);
+ } else if (f.getType() == Long.class || f.getType() == long.class) {
+ long v = resultSet.getLong(f.getName());
+ f.set(o, v);
+ } else if (f.getType() == Float.class || f.getType() == float.class) {
+ float v = resultSet.getFloat(f.getName());
+ f.set(o, v);
+ } else if (f.getType() == Double.class || f.getType() == double.class) {
+ double v = resultSet.getDouble(f.getName());
+ f.set(o, v);
+ } else if (f.getType() == Byte[].class || f.getType() == byte[].class) {
+ byte[] v = resultSet.getBytes(f.getName());
+ f.set(o, v);
} else {
String string = resultSet.getString(f.getName());
f.set(o, string);
@@ -296,7 +369,7 @@ public class ObjectClient extends Client {
}
private List getFields(Class aClass) {
- List fs = new ArrayList();
+ List fs = new ArrayList<>();
for (Field f : aClass.getDeclaredFields()) {
if (f.isAnnotationPresent(TableField.class)) {
fs.add(f);
diff --git a/wsqlite/src/main/java/xyz/wbsite/wsqlite/entity/Example.java b/wsqlite/src/main/java/xyz/wbsite/wsqlite/entity/Example.java
new file mode 100644
index 0000000..f6ceec8
--- /dev/null
+++ b/wsqlite/src/main/java/xyz/wbsite/wsqlite/entity/Example.java
@@ -0,0 +1,107 @@
+package xyz.wbsite.wsqlite.entity;
+
+import xyz.wbsite.wsqlite.anonation.TableField;
+
+public class Example {
+
+ @TableField(40)
+ private String s;
+ @TableField
+ private boolean b;
+ @TableField
+ private byte[] bs;
+ @TableField
+ private byte b1;
+ @TableField
+ private short s1;
+ @TableField
+ private char c1;
+ @TableField
+ private int age;
+ @TableField
+ private long id;
+ @TableField
+ private float f1;
+ @TableField
+ private double d1;
+
+ public String getS() {
+ return s;
+ }
+
+ public void setS(String s) {
+ this.s = s;
+ }
+
+ public boolean isB() {
+ return b;
+ }
+
+ public void setB(boolean b) {
+ this.b = b;
+ }
+
+ public byte[] getBs() {
+ return bs;
+ }
+
+ public void setBs(byte[] bs) {
+ this.bs = bs;
+ }
+
+ public byte getB1() {
+ return b1;
+ }
+
+ public void setB1(byte b1) {
+ this.b1 = b1;
+ }
+
+ public short getS1() {
+ return s1;
+ }
+
+ public void setS1(short s1) {
+ this.s1 = s1;
+ }
+
+ public char getC1() {
+ return c1;
+ }
+
+ public void setC1(char c1) {
+ this.c1 = c1;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public float getF1() {
+ return f1;
+ }
+
+ public void setF1(float f1) {
+ this.f1 = f1;
+ }
+
+ public double getD1() {
+ return d1;
+ }
+
+ public void setD1(double d1) {
+ this.d1 = d1;
+ }
+}
diff --git a/wsqlite/src/main/java/xyz/wbsite/wsqlite/entity/User.java b/wsqlite/src/main/java/xyz/wbsite/wsqlite/entity/User.java
deleted file mode 100644
index 97d27ce..0000000
--- a/wsqlite/src/main/java/xyz/wbsite/wsqlite/entity/User.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package xyz.wbsite.wsqlite.entity;
-
-import xyz.wbsite.wsqlite.anonation.TableField;
-
-public class User {
-
- @TableField(40)
- private String name;
- @TableField(40)
- private String password;
- @TableField
- private boolean valid;
-
- public boolean isValid() {
- return valid;
- }
-
- public void setValid(boolean valid) {
- this.valid = valid;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-}
diff --git a/wsqlite/src/test/java/SqliteTest.java b/wsqlite/src/test/java/SqliteTest.java
deleted file mode 100644
index 16d2368..0000000
--- a/wsqlite/src/test/java/SqliteTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-import xyz.wbsite.wsqlite.ObjectClient;
-import xyz.wbsite.wsqlite.entity.User;
-
-import java.io.File;
-import java.sql.*;
-import java.util.ArrayList;
-import java.util.List;
-
-public class SqliteTest {
- public static void main(String[] args) {
- try {
- List arrayList = new ArrayList();
- arrayList.add(User.class);
- ObjectClient h = new ObjectClient(new File("D:\\test.db"),arrayList);
-
- System.out.println("测试 insert");
- User user = new User();
- user.setName("wangbing");
- user.setPassword("test");
- h.insert(User.class, user);
-
- System.out.println("测试 select");
- List select = h.select(User.class,1,10);
- System.out.println(select.size());
-
- System.out.println("测试 update");
- user.setName("==");
- user.setPassword("==");
- int update = h.update(User.class, user);
- System.out.println(update);
-
- System.out.println("测试 delete");
- int delete = h.delete(User.class,"NAME = '=='");
- System.out.println(delete);
-
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-}
\ No newline at end of file