0.0.1-SNAPSHOT
wangbing 5 years ago
parent 3156b6e344
commit fc445a8f33

@ -7,7 +7,6 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="admin" />
<module name="nginx-admin" />
<module name="wsqlite" />
</profile>
</annotationProcessing>

@ -36,11 +36,6 @@
<artifactId>wsqlite</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
@ -51,19 +46,12 @@
<artifactId>commons-io</artifactId>
</dependency>
<!-- mybatis 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<!-- freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
@ -86,12 +74,6 @@
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>

@ -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<Class> 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;
}
}

@ -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;
}
}

@ -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();

@ -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;
}
}

@ -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
spring.servlet.multipart.max-request-size=100MB
dbpath=

@ -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
spring.servlet.multipart.max-request-size=100MB

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<projectName>EXAMPLE-WEB</projectName>
<projectBasePackage>com.example</projectBasePackage>
<projectAuthor>author</projectAuthor>
<modules>
<module>
<moduleComment>用户</moduleComment>
<modulePrefix>SYS</modulePrefix>
<moduleName>usermodel</moduleName>
<hasSysFields>true</hasSysFields>
<tables>
<table create="true" delete="true" find="true" get="true" getAll="false" search="false" tableComment="映射" tableName="MAPPING" update="true">
<fields>
<field IsSystem="true" defaultValue="" fieldComment="主键" fieldLength="0" fieldName="ID" fieldType="Long" isMust="true" isPrimaryKey="true" isQuery="false" isSearch="false"/>
<field IsSystem="false" defaultValue="NULL" fieldComment="用户名" fieldLength="100" fieldName="USERNAME" fieldType="String_var100" isMust="false" isPrimaryKey="false" isQuery="true" isSearch="false"/>
<field IsSystem="false" defaultValue="NULL" fieldComment="用户密码" fieldLength="100" fieldName="PASSWORD" fieldType="String_var100" isMust="false" isPrimaryKey="false" isQuery="true" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="行版本" fieldLength="0" fieldName="ROW_VERSION" fieldType="Long" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="0" fieldComment="是否已删除" fieldLength="0" fieldName="IS_DELETED" fieldType="Boolean" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="创建用户" fieldLength="0" fieldName="CREATE_BY" fieldType="Long" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="NULL" fieldComment="创建时间" fieldLength="0" fieldName="CREATE_TIME" fieldType="Date" isMust="true" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="最后更新用户" fieldLength="0" fieldName="LAST_UPDATE_BY" fieldType="Long" isMust="false" isPrimaryKey="false" isQuery="false" isSearch="false"/>
<field IsSystem="true" defaultValue="" fieldComment="最后更新时间" fieldLength="0" fieldName="LAST_UPDATE_TIME" fieldType="Date" isMust="false" isPrimaryKey="false" isQuery="false" isSearch="false"/>
</fields>
</table>
</tables>
</module>
</modules>
</project>

@ -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='映射';

@ -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='用户';

@ -1,217 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<#--baseJs-->
<script src="${Uri.getUrl('/static/dist/lib.min.js')}" type="text/javascript"></script>
<#--移动端ui-->
<script src="${Uri.getUrl('/static/dist/mint-ui.min.js')}" type="text/javascript"></script>
<link href="${Uri.getUrl('/static/dist/mint-ui.min.css')}" rel="stylesheet"/>
<#--ajax接口-->
<script src="${Uri.getUrl('/static/js/ajax.js')}" type="text/javascript"></script>
<style>
* {
padding: 0px;
margin: 0px;
}
html,body,#app{
width: 100%;
height: 100%;
}
.left-in-right-out-enter-active, .left-in-right-out-leave-active {
transition: all 0.3s linear;
position: absolute;
}
.left-in-right-out-enter {
transform: translateX(-100%);
opacity: 0;
}
.left-in-right-out-leave-to {
transform: translateX(100%);
opacity: 0;
}
.right-in-left-out-enter-active, .right-in-left-out-leave-active {
transition: all .3s linear;
position: absolute;
}
.right-in-left-out-enter {
transform: translateX(100%);
}
.right-in-left-out-leave-to {
transform: translateX(-100%);
}
.left-in-right-out-enter-active, .left-in-right-out-leave-active {
transition: all 0.3s linear;
position: absolute;
}
.left-in-right-out-enter {
transform: translateX(-100%);
opacity: 0;
}
.left-in-right-out-leave-to {
transform: translateX(100%);
opacity: 0;
}
.right-in-left-out-enter-active, .right-in-left-out-leave-active {
transition: all .3s linear;
position: absolute;
}
.right-in-left-out-enter {
transform: translateX(100%);
}
.right-in-left-out-leave-to {
transform: translateX(-100%);
}
</style>
</head>
<body>
<#include Layout.setControl("mint-ui-extend")/>
<div id="app">
<transition :name="transitionName">
<router-view></router-view>
</transition>
</div>
<template id="home">
<div class="view">
<mt-header title="Hello world">
<router-link to="/" slot="left">
<mt-button icon="back">返回</mt-button>
</router-link>
<mt-button icon="more" slot="right"></mt-button>
</mt-header>
<div class="content" style="text-align: center;padding-top: 200px">
Hello world <router-link to="demo">demo</router-link>
</div>
</div>
</template>
<template id="demo">
<div class="view">
<mt-header title="表单输入">
<mt-button icon="back" slot="left" @click="back">关闭</mt-button>
</mt-header>
<div class="content" style="text-align: center;">
<mt-header title="Mint-ui自带控件"></mt-header>
<mt-field label="普通文字" placeholder="请输入用户名" v-model="field1"></mt-field>
<mt-field label="邮箱地址" placeholder="请输入邮箱" type="email" v-model="field2"></mt-field>
<mt-field label="用户密码" placeholder="请输入密码" type="password" v-model="field3"></mt-field>
<mt-field label="手机号码" placeholder="请输入手机号" type="tel" v-model="field4"></mt-field>
<mt-field label="网站链接" placeholder="请输入网址" type="url" v-model="field5"></mt-field>
<mt-field label="数字输入" placeholder="请输入数字" type="number" v-model="field6"></mt-field>
<mt-field label="生日日期" placeholder="请输入生日" type="date" v-model="field7"></mt-field>
<mt-field label="多行文字" placeholder="多行文字" type="textarea" rows="2" v-model="field8"></mt-field>
<mt-header title="扩展控件"></mt-header>
<wb-field-select label="文字选择" placeholder="请选择" :items="['男','女']" v-model="field10"></wb-field-select>
<wb-field-dict label="字典选择" placeholder="请选择" :items="[{key:'1',value:'男'},{key:'2',value:'女'}]"
v-model="field11"></wb-field-dict>
<wb-field-date label="日期选择" placeholder="请选择" v-model="field12"></wb-field-date>
<wb-field-time label="时间选择" placeholder="请选择" v-model="field13"></wb-field-time>
<wb-field-datetime label="日期时间" placeholder="请选择" v-model="field14"></wb-field-datetime>
<wb-field-cphm label="车牌号码" placeholder="车牌号" v-model="field15"></wb-field-cphm>
<wb-field-pictures label="选择照片" v-model="field16" @handle-file="handleFile"></wb-field-pictures>
<div style="padding: 10px">
<mt-button type="primary" size="large" @click="doSearch()">打印类容</mt-button>
</div>
</div>
</div>
</template>
<script>
var router = new VueRouter({
routes: [
{
path: '/',
name: 'home',
component: Vue.extend({template: '#home'})
},
{
path: '/demo',
name: 'demo',
component: Vue.extend({
template: '#demo',
mounted: function () {
},
data: function () {
return {
field1: '',
field2: '',
field3: '',
field4: '',
field5: '',
field6: '',
field7: '',
field8: '',
field9: '',
field10: '',
field11: '',
field12: '',
field13: '',
field14: '',
field15: '',
field16: '',
}
},
methods: {
doSearch: function () {
console.log(this.field10);
console.log(this.field11);
console.log(this.field12);
console.log(this.field13);
console.log(this.field14);
console.log(this.field15);
console.log(this.field16);
},
back: function () {
if (window.android) {
android.finish()
} else {
location.href = "${Uri.getUrl('/app/index.htm')}"
}
},
handleFile: function (file, call) {
//do upload
console.log("正在上传文件" + file.name);
if (true) {
call.finish();
} else {
call.cancel();
}
}
}
})
}
]
});
var app = new Vue({
el: '#app',
data: {
transitionName: ''
},
router: router,
watch: {
'$route': function (to, from) {
this.transitionName = to.meta.index < from.meta.index ? 'left-in-right-out' : 'right-in-left-out'
}
}
})
</script>
</html>

@ -17,16 +17,7 @@
<i class="el-icon-setting"></i>
<span>系统设置</span>
</template>
<el-menu-item index="1-1">用户管理</el-menu-item>
<el-menu-item index="1-2">机构管理</el-menu-item>
<el-menu-item index="1-3">角色管理</el-menu-item>
</el-submenu>
<el-submenu index="2">
<template slot="title">
<i class="el-icon-time"></i>
<span slot="title">日志管理</span>
</template>
<el-menu-item index="2-1">登录日志</el-menu-item>
<el-menu-item index="1-1">映射管理</el-menu-item>
</el-submenu>
</el-menu>
</div>
@ -47,7 +38,7 @@
</li>
<li>
<el-dropdown>
<el-link :underline="false" @click="onHome" icon="el-icon-user-solid">我的</el-link>
<el-link :underline="false" @click="onHome" icon="el-icon-example-solid">我的</el-link>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>修改信息</el-dropdown-item>
@ -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;

@ -6,7 +6,7 @@
<el-form :model="form" :rules="rules" ref="form" class="form">
<el-form-item prop="name">
<el-input placeholder="用户名" v-model="form.name">
<template slot="prepend"><i class="icon iconfont el-icon-user"></i></template>
<template slot="prepend"><i class="icon iconfont el-icon-example"></i></template>
</el-input>
</el-form-item>

@ -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

@ -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());
}
}

@ -4,6 +4,11 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modules>
<module>admin</module>
<module>wsqlite</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
@ -14,6 +19,7 @@
<groupId>xyz.wbsite</groupId>
<artifactId>nginx-admin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -39,24 +45,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- sql分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper-version}</version>
</dependency>
<!-- spring-boot -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-version}</version>
</dependency>
<!-- mybatis 缓存框架 -->
<dependency>
<groupId>org.mybatis.caches</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>${ehcache-version}</version>
</dependency>
<!-- 映射工具 -->
<dependency>
<groupId>net.sf.dozer</groupId>

@ -13,6 +13,7 @@
<groupId>xyz.wbsite</groupId>
<artifactId>wsqlite</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

@ -17,7 +17,7 @@ import java.util.Map;
*/
public class ObjectClient extends Client {
private Map<String, Class> classMap = new HashMap();
private Map<String, Class> 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 <T> void insert(Class<T> poClass, T po) throws SQLException, ClassNotFoundException {
public <T> int insert(Class<T> 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 <T> int delete(Class<T> 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 <T> List<T> select(Class<T> poClass, int pageNumber, int pageSize, String... wheres) throws SQLException, ClassNotFoundException {
ArrayList<T> list = new ArrayList();
ArrayList<T> 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<Field> getFields(Class aClass) {
List<Field> fs = new ArrayList();
List<Field> fs = new ArrayList<>();
for (Field f : aClass.getDeclaredFields()) {
if (f.isAnnotationPresent(TableField.class)) {
fs.add(f);

@ -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;
}
}

@ -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;
}
}

@ -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<Class> 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<User> 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();
}
}
}
Loading…
Cancel
Save

Powered by TurnKey Linux.