Browse Source

druid+mybatis plus---

mgr-gxzc 7 years ago
parent
commit
345e2acc43

+ 41 - 41
build.gradle

@@ -63,21 +63,21 @@ subprojects {
         testCompile('org.springframework.boot:spring-boot-starter-test')
         testCompile("junit:junit:4.12")
 
-//        compile ("commons-io:commons-io:$commons_io_version")
-//        compile ("commons-logging:commons-logging:$commons_logging_version")
-//        compile ("org.apache.commons:commons-lang3:$commons_lang3_version")
-//        compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
-//        compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.2'
-//        compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3'
-//        compile group: 'log4j', name: 'log4j', version: '1.2.17'
-//        compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
-//        // compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
-//
-//        // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
-//        compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
-//        compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
-////        compile group: 'javax.servlet', name: 'jstl', version: '1.2'
-////        compile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1'
+        compile ("commons-io:commons-io:$commons_io_version")
+        compile ("commons-logging:commons-logging:$commons_logging_version")
+        compile ("org.apache.commons:commons-lang3:$commons_lang3_version")
+        compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
+        compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.2'
+        compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3'
+        compile group: 'log4j', name: 'log4j', version: '1.2.17'
+        compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
+        // compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
+
+        // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
+        compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
+        compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
+//        compile group: 'javax.servlet', name: 'jstl', version: '1.2'
+//        compile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.1'
 //
 //        compile ("org.springframework.amqp:spring-rabbit:$spring_rabbitmq_version")
 //        compile ("org.springframework.data:spring-data-commons-core:1.4.1.RELEASE")
@@ -86,31 +86,31 @@ subprojects {
 //        compile ("org.springframework.data:spring-data-jpa:$spring_data_version")
 //        compile ("org.springframework.data:spring-data-elasticsearch:$spring_data_elasticsearch_version")
 //
-//        compile ("com.alibaba:druid:$alidruid_version")
-//        compile ("org.ehcache:ehcache:$ehcache_version")
-//        compile ("org.activiti:activiti-engine:$activiti_version")
-//        compile ("org.activiti:activiti-spring:$activiti_version")
-//        compile ("net.sf.ehcache:ehcache-core:$ehcache_core_version")
-//        compile ("mysql:mysql-connector-java:$mysql_connector_version")
-////        compile ("org.mybatis:mybatis:$mybatis_version")
-////        compile ("org.mybatis:mybatis-spring:$mybatiss_version")
-//        compile ("com.baomidou:mybatis-plus:$mybatis_plus_version")
-//        compile ("com.baomidou:mybatisplus-spring-boot-starter:$mybatis_plus_boot_version")
-//        compile ("com.rabbitmq:amqp-client:$rabbitmq_version")
-//        compile ("com.xuxueli:xxl-job-core:$xxljob_version")
-//        compile ("io.springfox:springfox-swagger2:$swagger_version")
-//        compile ("io.springfox:springfox-swagger-ui:$swagger_version")
-//
-//        compile ("com.google.guava:guava:23.6-jre")
-//        compile ("com.github.penggle:kaptcha:2.3.2")
-//        compile ("com.alibaba:fastjson:$fastjson_version")
-//        compile ("com.fasterxml.jackson.core:jackson-core:2.9.3")
-//        compile ("com.fasterxml.jackson.core:jackson-databind:2.9.3")
-//        compile ("com.fasterxml.jackson.core:jackson-annotations:2.9.3")
-//
-//
-//        compile ("com.baomidou:kisso:3.6.11")
-//        compile ("io.jsonwebtoken:jjwt:0.7.0")
-//        compile ("org.projectlombok:lombok:1.16.18")
+        compile ("com.alibaba:druid:$alidruid_version")
+        compile ("org.ehcache:ehcache:$ehcache_version")
+        compile ("org.activiti:activiti-engine:$activiti_version")
+        compile ("org.activiti:activiti-spring:$activiti_version")
+        compile ("net.sf.ehcache:ehcache-core:$ehcache_core_version")
+        compile ("mysql:mysql-connector-java:$mysql_connector_version")
+//        compile ("org.mybatis:mybatis:$mybatis_version")
+//        compile ("org.mybatis:mybatis-spring:$mybatiss_version")
+        compile ("com.baomidou:mybatis-plus:$mybatis_plus_version")
+        compile ("com.baomidou:mybatisplus-spring-boot-starter:$mybatis_plus_boot_version")
+        compile ("com.rabbitmq:amqp-client:$rabbitmq_version")
+        compile ("com.xuxueli:xxl-job-core:$xxljob_version")
+        compile ("io.springfox:springfox-swagger2:$swagger_version")
+        compile ("io.springfox:springfox-swagger-ui:$swagger_version")
+
+        compile ("com.google.guava:guava:23.6-jre")
+        compile ("com.github.penggle:kaptcha:2.3.2")
+        compile ("com.alibaba:fastjson:$fastjson_version")
+        compile ("com.fasterxml.jackson.core:jackson-core:2.9.3")
+        compile ("com.fasterxml.jackson.core:jackson-databind:2.9.3")
+        compile ("com.fasterxml.jackson.core:jackson-annotations:2.9.3")
+
+
+        compile ("com.baomidou:kisso:3.6.11")
+        compile ("io.jsonwebtoken:jjwt:0.7.0")
+        compile ("org.projectlombok:lombok:1.16.18")
     }
 }

+ 1 - 0
zen-admin/build.gradle

@@ -2,4 +2,5 @@ apply plugin: 'war'
 
 dependencies {
     compile project(":zen-api")
+    compile project(":zen-ui")
 }

+ 12 - 2
zen-admin/src/main/kotlin/com/gxzc/zen/ExampleController.kt

@@ -1,5 +1,9 @@
 package com.gxzc.zen
 
+import com.gxzc.zen.sys.dao.TestDao
+import com.gxzc.zen.sys.service.TestService
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.ui.Model
 import org.springframework.web.bind.annotation.PathVariable
 import org.springframework.web.bind.annotation.RequestMapping
 import org.springframework.web.bind.annotation.RestController
@@ -8,9 +12,15 @@ import org.springframework.web.bind.annotation.RestController
 @RestController
 class ExampleController {
 
+    @Autowired
+    private val service: TestService?=null
+
     @RequestMapping("/")
-    fun home(): String {
-        return "Hello World!"
+    fun home(model:Model): String {
+        val one=service?.findOne(1)
+        val list=service?.findList(mapOf())
+        val html=""
+        return "Hello World!"+html
     }
 
     @RequestMapping("/hello/{myName}")

+ 1 - 1
zen-admin/src/main/kotlin/com/gxzc/zen/MainApplication.kt

@@ -4,7 +4,7 @@ import org.springframework.boot.SpringApplication
 import org.springframework.boot.autoconfigure.SpringBootApplication
 
 
-@SpringBootApplication
+@SpringBootApplication(scanBasePackages = ["com.gxzc.zen"])
 class MainApplication
 
 fun main(args:Array<String>){

+ 30 - 84
zen-admin/src/main/resources/application.yml

@@ -1,61 +1,53 @@
-##########################################################
-##################  所有profile共有的配置  #################
-##########################################################
 
-###################  guns配置  ###################
-guns:
-  swagger-open: true #是否开启swagger (true/false)
-  kaptcha-open: false #是否开启登录时验证码 (true/false)
-  session-open: false #是否开启session超时验证(受影响的类SessionTimeoutInterceptor) (true/false)
-  #file-upload-path: d:/tmp  #文件上传目录(不配置的话为java.io.tmpdir目录)
-  muti-datasource-open: false #是否开启多数据源(true/false)
-  spring-session-open: false #是否开启spring session,如果是多机环境需要开启(true/false)
-  session-invalidate-time: 1800 #session失效时间(只在单机环境下生效,多机环境在SpringSessionConfig类中配置) 单位:秒
-  session-validation-interval: 900 #多久检测一次失效的session(只在单机环境下生效) 单位:秒
-
-###################  项目启动端口  ###################
 server:
-  port: 8080
-
-###################  beetl配置  ###################
-beetl:
-  delimiter-statement-start: \@   #开始结束标签(yaml不允许@开头)
-  delimiter-statement-end: null
-  resource-tagroot: common/tags   #自定义标签文件Root目录和后缀
-  resource-tagsuffix: tag
-  resource-auto-check: true #是否检测文件变化,开发用true合适,但线上要改为false
-
+  port: 8081
 
 ###################  spring配置  ###################
 spring:
+  profiles:
+    active: dev
   redis:
     host: localhost
     port: 6379
     password:
-  profiles:
-    active: dev
-  mvc:
-    static-path-pattern: /static/**
-    view:
-      prefix: /WEB-INF/view
   http:
     converters:
       preferred-json-mapper: fastjson
     multipart:
       max-request-size: 100MB #最大请求大小
       max-file-size: 100MB #最大文件大小
-  devtools:
-    restart:
-      enabled: false #是否开启开发者工具(true/false)
-      additional-paths: src/main/java
-      exclude: static/**,WEB-INF/view/**
   aop:
     proxy-target-class: true #false为启用jdk默认动态代理,true为cglib动态代理
 
+
+
+###################  druid配置  ###################
+druid:
+  view:
+#    enable: false无效
+    username: root
+    password: 123456
+    slowsql: true
+  datasource-sys:
+    url: jdbc:mysql://127.0.0.1:3306/zen-sys?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
+    username: root
+    password: 123456
+    filters: log4j,wall,mergeStat
+    driver-class-name: com.mysql.jdbc.Driver
+    initialSize: 5
+    minIdle: 5
+    maxActive: 20
+    timeBetweenEvictionRunsMillis: 60000
+    minEvictableIdleTimeMillis: 30000
+    validationQuery: SELECT 1 FROM DUAL
+    testWhileIdle: true
+    testOnBorrow: false
+    testOnReturn: false
+
 ###################  mybatis-plus配置  ###################
 mybatis-plus:
-  mapper-locations: classpath*:com/northlan/netplat/**/mapping/*.xml
-  typeAliasesPackage: com.northlan.netplat.common.persistence.model
+  mapper-locations: classpath*:com/gxzc/zen/*/mapping/*.xml
+  typeAliasesPackage: com.gxzc.zen.persistence.model
   global-config:
     id-type: 0  #0:数据库ID自增   1:用户输入id  2:全局唯一id(IdWorker)  3:全局唯一ID(uuid)
     db-column-underline: false
@@ -66,49 +58,3 @@ mybatis-plus:
     lazyLoadingEnabled: true #延时加载的开关
     multipleResultSetsEnabled: true #开启的话,延时加载一个属性时会加载该对象全部属性,否则按需加载属性
 #    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
-
----
-
-##########################################################
-###################  开发环境的profile  ###################
-##########################################################
-spring:
-  profiles: dev
-  datasource:
-      url: jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
-      username: root
-      password: root
-      filters: log4j,wall,mergeStat
-
-#多数据源
-guns:
-  muti-datasource:
-    default-dataSource-name: dataSourceGuns #默认的数据源名称
-    url: jdbc:mysql://127.0.0.1:3306/biz?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
-    username: root
-    password: root
-
-logging:
-  level.root: info
-  level.com.northlan: debug
-  path: logs/
-  file: guns.log
-
----
-
-##########################################################
-###################  正式环境的profile  ###################
-##########################################################
-spring:
-  profiles: produce
-  datasource:
-      url: jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
-      username: root
-      password: root
-      filters: log4j,wall,mergeStat
-
-logging:
-  level.root: warn
-  path: logs/
-  file: guns.log
-

+ 1 - 1
zen-admin/src/main/webapp/index.jsp

@@ -11,6 +11,6 @@
     <title>$Title$</title>
   </head>
   <body>
-  $END$
+  $END$s
   </body>
 </html>

+ 11 - 0
zen-api/src/main/kotlin/com/gxzc/zen/sys/dao/TestDao.kt

@@ -0,0 +1,11 @@
+package com.gxzc.zen.sys.dao
+
+import com.baomidou.mybatisplus.mapper.BaseMapper
+import com.gxzc.zen.sys.model.Test
+import org.apache.ibatis.annotations.Param
+import org.springframework.stereotype.Repository
+
+@Repository
+interface TestDao: BaseMapper<Test> {
+    fun findList(@Param("cm") params:Map<String, Any?>): List<Test>
+}

+ 8 - 0
zen-api/src/main/kotlin/com/gxzc/zen/sys/model/Test.kt

@@ -0,0 +1,8 @@
+package com.gxzc.zen.sys.model
+
+import java.util.*
+
+class Test{
+    val name:String?=null
+    val times: Date?=null
+}

+ 19 - 0
zen-api/src/main/kotlin/com/gxzc/zen/sys/service/TestService.kt

@@ -0,0 +1,19 @@
+package com.gxzc.zen.sys.service
+
+import com.gxzc.zen.sys.dao.TestDao
+import com.gxzc.zen.sys.model.Test
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.stereotype.Service
+
+@Service
+class TestService {
+    @Autowired
+    private val dao:TestDao?=null
+
+    fun findList(params:Map<String, Any?>):List<Test>?{
+        return dao?.findList(params)
+    }
+    fun findOne(id:Long):Test?{
+        return dao?.selectById(id)
+    }
+}

+ 10 - 0
zen-api/src/main/resources/com.gxzc.zen/sys/mapping/TestMapper.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.gxzc.zen.sys.dao.TestDao">
+
+    <select id="findList" resultType="com.gxzc.zen.sys.model.Test">
+        SELECT *
+        FROM test
+    </select>
+
+</mapper>

+ 92 - 0
zen-config/src/main/kotlin/com/gxzc/zen/config/DruidConfig.kt

@@ -0,0 +1,92 @@
+package com.gxzc.zen.config
+
+import com.alibaba.druid.pool.DruidDataSource
+import com.alibaba.druid.support.http.StatViewServlet
+import com.alibaba.druid.support.http.WebStatFilter
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.web.servlet.FilterRegistrationBean
+import org.springframework.boot.web.servlet.ServletRegistrationBean
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+import java.sql.SQLException
+import javax.sql.DataSource
+
+
+@Configuration
+class SysDruidConfig:DruidConfig<SysDruidProperties>()
+
+
+
+
+
+
+/*-----------------druid数据源bean注册 */
+open class DruidConfig<T:DruidProperties> {
+    private val logger= LoggerFactory.getLogger(javaClass)
+
+    @Autowired
+    private val config:T?=null
+
+//    private val name=nm
+
+    @Bean
+    open fun druidDataSource(): DataSource {
+        val datasource = DruidDataSource()
+        datasource.url = config?.url
+        datasource.username = config?.username
+        datasource.password = config?.password
+        datasource.driverClassName = config?.driverClassName
+        datasource.initialSize = config?.initialSize!!
+        datasource.minIdle = config?.minIdle!!
+        datasource.maxActive = config?.maxActive!!
+        datasource.maxWait = config?.maxWait!!
+        datasource.timeBetweenEvictionRunsMillis = config?.timeBetweenEvictionRunsMillis!!
+        datasource.minEvictableIdleTimeMillis = config?.minEvictableIdleTimeMillis!!
+        datasource.validationQuery = config?.validationQuery!!
+        datasource.isTestWhileIdle = config?.testWhileIdle!!
+        datasource.isTestOnBorrow = config?.testOnBorrow!!
+        datasource.isTestOnReturn = config?.testOnReturn!!
+        try {
+            datasource.setFilters(config?.filters)
+        } catch (e: SQLException) {
+            logger.error("druid configuration initialization filter", e)
+        }
+
+        return datasource
+    }
+}
+
+
+
+
+/*-----------------配置druid显示界面 */
+@Configuration
+class DruidViewConfig{
+
+    @Autowired
+    private val config:DruidViewProperties?=null
+
+    @Bean
+    fun druidServlet(): ServletRegistrationBean {
+//        if(!config?.enable!!)return throw Exception()
+        val reg = ServletRegistrationBean()
+        reg.setServlet(StatViewServlet())
+        reg.addUrlMappings("/druid/*")
+        reg.addInitParameter("loginUsername", config?.username)
+        reg.addInitParameter("loginPassword", config?.password)
+        reg.addInitParameter("logSlowSql", config?.slowsql)
+        return reg
+    }
+
+    @Bean
+    fun filterRegistrationBean(): FilterRegistrationBean {
+//        if(!config?.enable!!)return throw Exception()
+        val filterRegistrationBean = FilterRegistrationBean()
+        filterRegistrationBean.filter = WebStatFilter()
+        filterRegistrationBean.addUrlPatterns("/*")
+        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*")
+        filterRegistrationBean.addInitParameter("profileEnable", "true")
+        return filterRegistrationBean
+    }
+}

+ 23 - 0
zen-config/src/main/kotlin/com/gxzc/zen/config/MybatisPlusConfig.java

@@ -0,0 +1,23 @@
+package com.gxzc.zen.config;
+
+import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * MybatisPlus配置
+ *
+ * @author NorthLan
+ */
+@Configuration
+@MapperScan(basePackages = {"com.gxzc.zen.persistence.*.dao", "com.gxzc.zen.*.dao"})
+public class MybatisPlusConfig {
+    /**
+     * mybatis-plus分页插件
+     */
+    @Bean
+    public PaginationInterceptor paginationInterceptor() {
+        return new PaginationInterceptor();
+    }
+}

+ 38 - 0
zen-config/src/main/kotlin/com/gxzc/zen/config/ZenBeanProperties.kt

@@ -0,0 +1,38 @@
+package com.gxzc.zen.config
+
+import org.springframework.boot.context.properties.ConfigurationProperties
+import org.springframework.stereotype.Component
+
+
+open class DruidProperties{
+    var url:String?=null
+    var username:String?=null
+    var password:String?=null
+    var filters:String?=null
+
+    var driverClassName:String?="com.mysql.jdbc.Driver"
+    var initialSize:Int?=5
+    var minIdle:Int?=5
+    var maxActive:Int?=20
+    var maxWait:Long?=60000
+
+    var timeBetweenEvictionRunsMillis:Long?=null
+    var minEvictableIdleTimeMillis:Long?=null
+    var validationQuery:String?=null
+    var testWhileIdle:Boolean?=null
+    var testOnBorrow:Boolean?=null
+    var testOnReturn:Boolean?=null
+}
+
+@Component
+@ConfigurationProperties(prefix = "druid.view")
+class DruidViewProperties{
+//    var enable:Boolean?=false
+    var username:String?=null
+    var password:String?=null
+    var slowsql:String?=null
+}
+
+@Component
+@ConfigurationProperties(prefix = "druid.datasource-sys")
+class SysDruidProperties:DruidProperties()

+ 10 - 0
zen-ui/src/main/resources/static/index.html

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>index</title>
+</head>
+<body>
+hello world!index
+</body>
+</html>