diff --git a/README.md b/README.md index 082c11b1..b5acd62d 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ public class MainLauncher { * [tasdingoo](https://github.com/tasdingoo)(issue@github 122) * [csl_slchia](https://gitee.com/csl_slchia)(issue@gitee II92L) * [大鲨鱼](https://github.com/Wizzercn)(提交starter-wkcache/elasticsearch/sentinel等,扩展NB功能) +* [threefish](https://github.com/threefish)(Nutz Intellij idea插件,提交starter-email/sqlXmlTpl) * 还有您的名字哦,告知我们吧 ## 采用NutzBoot的公司 @@ -192,6 +193,7 @@ public class MainLauncher { - ORM - [x] **starter-[nutz-dao](https://github.com/nutzam/nutz) Nutz官方Dao** - [x] starter-[beetlsql](http://ibeetl.com/guide/#beetlsql) 基于Beetl的SQL框架 + - [x] starter-[sqlXmlTpl](http://github.com/threefish) 解决Java拼接SQL(采用xml管理sql) - 非关系型数据库 - [x] **starter-[redis](https://redis.io) 特点就是快,吃内存!** - [x] starter-mongodb NoSQL的重要一支 diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/Dockerfile b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/Dockerfile new file mode 100644 index 00000000..48bb6f23 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/Dockerfile @@ -0,0 +1,7 @@ +FROM azul/zulu-openjdk:8 +MAINTAINER wendal + +ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/share/nb.jar"] +# Add the service itself +ARG JAR_FILE +ADD target/${JAR_FILE} /usr/share/nb.jar \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/pom.xml b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/pom.xml new file mode 100644 index 00000000..e8321756 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/pom.xml @@ -0,0 +1,66 @@ + + 4.0.0 + + org.nutz + nutzboot-demo-simple + 2.3.4-SNAPSHOT + + nutzboot-demo-simple-sqlxmltpl + + nutzboot + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + + + + src/main/java + + **/*.xml + + + + + + + org.nutz + nutzboot-starter-nutz-mvc + + + org.nutz + nutzboot-starter-nutz-dao + + + org.nutz + nutzboot-starter-jdbc + + + org.nutz + nutzboot-starter-jetty + + + org.nutz + nutzboot-starter-swagger + + + org.nutz + nutzboot-starter-sqlxmltpl + ${nutzboot.version} + + + org.slf4j + slf4j-log4j12 + + + com.h2database + h2 + 1.4.196 + + + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/MainLauncher.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/MainLauncher.java new file mode 100644 index 00000000..c5e6b667 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/MainLauncher.java @@ -0,0 +1,50 @@ +package io.nutz.demo.simple; + +import com.github.threefish.nutz.dto.PageDataDTO; +import io.nutz.demo.simple.bean.User; +import io.nutz.demo.simple.service.IUserService; +import org.nutz.boot.NbApp; +import org.nutz.dao.Cnd; +import org.nutz.dao.Dao; +import org.nutz.dao.pager.Pager; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.json.Json; +import org.nutz.json.JsonFormat; +import org.nutz.lang.util.NutMap; + +import java.util.List; + +/** + * @author 黄川 huchuc@vip.qq.com + * @date 2019-04-03 + */ +@IocBean(create = "init") +public class MainLauncher { + + @Inject + protected Dao dao; + @Inject + protected IUserService userService; + + public static void main(String[] args) throws Exception { + new NbApp().setPrintProcDoc(true).run(); + } + + public void init() { + dao.create(User.class, true); + dao.insert(new User("apple", 40, "北京")); + dao.insert(new User("ball", 30, "未知")); + dao.insert(new User("cat", 50, "温哥华")); + dao.insert(new User("fox", 51, "纽约")); + dao.insert(new User("bra", 25, "济南")); + dao.insert(new User("alina", 50, "深圳")); + PageDataDTO dataDTO = userService.queryLikeName(NutMap.NEW().setv("name", "a%"), new Pager(0, 5)); + List userList = userService.queryLikeNameByCnd(Cnd.where("name", "like", "a%"), new Pager(0, 5)); + List userMaps = userService.queryMapslikeName(NutMap.NEW()); + System.out.printf("queryLikeName --> %s %s \n", dataDTO.getCount(), Json.toJson(dataDTO.getData(), JsonFormat.compact())); + System.out.printf("queryLikeNameByCnd --> %s \n", Json.toJson(userList, JsonFormat.compact())); + System.out.printf("queryMapslikeName --> %s \n", Json.toJson(userMaps, JsonFormat.compact())); + } + +} diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/bean/User.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/bean/User.java new file mode 100644 index 00000000..658c927e --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/bean/User.java @@ -0,0 +1,58 @@ +package io.nutz.demo.simple.bean; + +import org.nutz.dao.entity.annotation.Id; +import org.nutz.dao.entity.annotation.Name; +import org.nutz.dao.entity.annotation.Table; + +@Table("t_user") +public class User { + + @Id + private long id; + @Name + private String name; + private int age; + private String location; + + public User() { + } + + public User(String name, int age, String location) { + super(); + this.name = name; + this.age = age; + this.location = location; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } +} diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/module/UserModule.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/module/UserModule.java new file mode 100644 index 00000000..49f99177 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/module/UserModule.java @@ -0,0 +1,45 @@ +package io.nutz.demo.simple.module; + +import java.util.List; + +import org.nutz.dao.Cnd; +import org.nutz.dao.Dao; +import org.nutz.dao.pager.Pager; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.mvc.annotation.At; +import org.nutz.mvc.annotation.Ok; +import org.nutz.mvc.annotation.Param; + +import io.nutz.demo.simple.bean.User; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; + +@Api("user") +@At("/user") +@IocBean +public class UserModule { + + @Inject + Dao dao; + + @ApiOperation(value = "获取用户总数", notes = "获取用户总数", httpMethod="GET", response=Long.class) + @Ok("raw") + @At + public long count() { + return dao.count(User.class); + } + + @ApiOperation(value = "查询用户列表", notes = "可分页", httpMethod="GET") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNumber", paramType="query", value = "起始页是1", dataType="int", required = false, defaultValue="1"), + @ApiImplicitParam(name = "pageSize", paramType="query", value = "每页数量", dataType="int", required = false, defaultValue="20"), + }) + @Ok("json:full") + @At + public List query(@Param("..")Pager pager) { + return dao.query(User.class, Cnd.orderBy().asc("age"), pager); + } +} diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/IUserService.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/IUserService.java new file mode 100644 index 00000000..e8bbd5da --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/IUserService.java @@ -0,0 +1,22 @@ +package io.nutz.demo.simple.service; + +import com.github.threefish.nutz.dto.PageDataDTO; +import io.nutz.demo.simple.bean.User; +import org.nutz.dao.Cnd; +import org.nutz.dao.pager.Pager; +import org.nutz.lang.util.NutMap; + +import java.util.List; + +/** + * @author 黄川 huchuc@vip.qq.com + * @date: 2019/4/3 + */ +public interface IUserService { + + PageDataDTO queryLikeName(NutMap param, Pager pager); + + List queryLikeNameByCnd(Cnd cnd, Pager pager); + + List queryMapslikeName(NutMap param); +} diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/impl/UserServiceImpl.java b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..5833bd3b --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/impl/UserServiceImpl.java @@ -0,0 +1,59 @@ +package io.nutz.demo.simple.service.impl; + +import com.github.threefish.nutz.dto.PageDataDTO; +import com.github.threefish.nutz.sqltpl.ISqlDaoExecuteService; +import com.github.threefish.nutz.sqltpl.SqlsTplHolder; +import com.github.threefish.nutz.sqltpl.SqlsXml; +import io.nutz.demo.simple.bean.User; +import io.nutz.demo.simple.service.IUserService; +import org.nutz.dao.Cnd; +import org.nutz.dao.Dao; +import org.nutz.dao.pager.Pager; +import org.nutz.ioc.loader.annotation.IocBean; +import org.nutz.lang.util.NutMap; +import org.nutz.service.EntityService; + +import java.util.List; + +/** + * @author 黄川 huchuc@vip.qq.com + * @date: 2019/4/3 + */ +@IocBean(args = {"refer:dao"}) +@SqlsXml +public class UserServiceImpl extends EntityService implements IUserService, ISqlDaoExecuteService { + + /** + * 1、我是必须要有的 + * 2、可以不实现 ISqlDaoExecuteService 接口,用 SqlsTplHolder 直接渲染sql自己再进行操作 + */ + private SqlsTplHolder sqlsTplHolder; + + public UserServiceImpl(Dao dao) { + super(dao); + } + + @Override + public PageDataDTO queryLikeName(NutMap param, Pager pager) { + return queryEntityBySql("queryLikeName", param, pager); + } + + @Override + public List queryLikeNameByCnd(Cnd cnd, Pager pager) { + return queryEntityBySql("queryLikeNameByCnd", NutMap.NEW(), cnd); + } + @Override + public List queryMapslikeName(NutMap param) { + return queryMapBySql("queryMapslikeName", param); + } + + @Override + public SqlsTplHolder getSqlsTplHolder() { + return this.sqlsTplHolder; + } + + @Override + public Dao getDao() { + return super.dao(); + } +} diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/impl/UserServiceImpl.xml b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/impl/UserServiceImpl.xml new file mode 100644 index 00000000..67e75836 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/java/io/nutz/demo/simple/service/impl/UserServiceImpl.xml @@ -0,0 +1,22 @@ + + + + + t_user + + + SELECT * from ${tableName} + if(isNotEmpty(name)){ + where name like @name + } + + + SELECT * from ${tableName} $condition + + + SELECT * from ${tableName} + if(isNotEmpty(name)){ + where name like @name + } + + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/application.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/application.properties new file mode 100644 index 00000000..f083b65e --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/application.properties @@ -0,0 +1,7 @@ +server.port=8080 +server.host=0.0.0.0 + +jdbc.url=jdbc:h2:mem:~ + +nutz.dao.interceptor.time.enable=true +nutz.dao.interceptor.cache.enable=true \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/log4j.properties b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/log4j.properties new file mode 100644 index 00000000..0a141dd0 --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/log4j.properties @@ -0,0 +1,8 @@ +log4j.rootLogger=info,Console + +log4j.logger.org.nutz=debug +log4j.logger.org.eclipse.jetty=info + +log4j.appender.Console=org.apache.log4j.ConsoleAppender +log4j.appender.Console.layout=org.apache.log4j.PatternLayout +log4j.appender.Console.layout.ConversionPattern=[%d{yyyy-MM-dd HH:mm:ss.SSS}] %5p [%t] --- %c{1}: %m%n diff --git a/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/static/index.html b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/static/index.html new file mode 100644 index 00000000..61f6ae4a --- /dev/null +++ b/nutzboot-demo/nutzboot-demo-simple/nutzboot-demo-simple-sqlxmltpl/src/main/resources/static/index.html @@ -0,0 +1,20 @@ + + + + +Hello, So NB! + + +
+

Hello, So NB!

+
+ + + + \ No newline at end of file diff --git a/nutzboot-demo/nutzboot-demo-simple/pom.xml b/nutzboot-demo/nutzboot-demo-simple/pom.xml index c0f37265..af0d0dac 100644 --- a/nutzboot-demo/nutzboot-demo-simple/pom.xml +++ b/nutzboot-demo/nutzboot-demo-simple/pom.xml @@ -30,7 +30,7 @@ nutzboot-demo-simple-zkclient nutzboot-demo-simple-velocity nutzboot-demo-simple-jetty - + nutzboot-demo-simple-caffeine nutzboot-demo-simple-hystrix nutzboot-demo-simple-eureka-client @@ -57,6 +57,8 @@ nutzboot-demo-simple-dao-with-many nutzboot-demo-simple-ftp nutzboot-demo-simple-fastdfs + nutzboot-demo-simple-sqlxmltpl + diff --git a/nutzboot-starter/nutzboot-starter-sqlxmltpl/pom.xml b/nutzboot-starter/nutzboot-starter-sqlxmltpl/pom.xml new file mode 100644 index 00000000..32b3f4c5 --- /dev/null +++ b/nutzboot-starter/nutzboot-starter-sqlxmltpl/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + + org.nutz + nutzboot-starter + 2.3.4-SNAPSHOT + + jar + nutzboot-starter-sqlxmltpl + nutzboot-starter-sqlxmltpl + + UTF-8 + + + NutzBoot, nutzboot-starter-sqlxmltpl + + http://nutzam.com + + Github Issue + http://github.com/nutzam/nutzboot/issues + + + + The Apache Software License, Version 2.0 + http://apache.org/licenses/LICENSE-2.0.txt + + + + + threefish + threefish + huchuc@vip.qq.com + http://github.com/threefish/ + + + + scm:git:git://github.com/nutzam/nutzboot.git + scm:git:git://github.com/nutzam/nutzboot.git + git://github.com/nutzam/nutzboot.git + + + + nutzcn-snapshots + NutzCN snapshot repository + https://jfrog.nutz.cn/artifactory/snapshots + + + + sonatype-release-staging + Sonatype Nexus release repository + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + + + + com.github.threefish + nutz-sqltpl + 1.3.4.RELEASE + + + com.ibeetl + beetl + ${beetl.version} + + + \ No newline at end of file diff --git a/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/java/org/nutz/boot/starter/sqlxmltpl/SqlXmlTplIocLoaderStarter.java b/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/java/org/nutz/boot/starter/sqlxmltpl/SqlXmlTplIocLoaderStarter.java new file mode 100644 index 00000000..0aee7f18 --- /dev/null +++ b/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/java/org/nutz/boot/starter/sqlxmltpl/SqlXmlTplIocLoaderStarter.java @@ -0,0 +1,31 @@ +package org.nutz.boot.starter.sqlxmltpl; + +import org.nutz.boot.annotation.PropDoc; +import org.nutz.boot.ioc.IocLoaderProvider; +import org.nutz.ioc.IocLoader; +import org.nutz.ioc.impl.PropertiesProxy; +import org.nutz.ioc.loader.annotation.Inject; +import org.nutz.ioc.loader.json.JsonLoader; + +/** + * @author 黄川 huchuc@vip.qq.com + * @date 2019-04-03 + */ +public class SqlXmlTplIocLoaderStarter implements IocLoaderProvider { + + protected static final String PRE = "sqlXmlTpl."; + + @PropDoc(group = "sqlXmlTpl", value = "sqlXmlTpl模版语言语句开始", defaultValue = "") + public static final String statementStart = PRE + "statementStart"; + + @PropDoc(group = "sqlXmlTpl", value = "sqlXmlTpl模版语言语句结束", defaultValue = "") + public static final String statementEnd = PRE + "statementEnd"; + + @Inject + protected PropertiesProxy conf; + + @Override + public IocLoader getIocLoader() { + return new JsonLoader("org/nutz/boot/starter/sqlxmltpl/sqlxmltpl.js"); + } +} \ No newline at end of file diff --git a/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/resources/META-INF/nutz/org.nutz.boot.starter.NbStarter b/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/resources/META-INF/nutz/org.nutz.boot.starter.NbStarter new file mode 100644 index 00000000..9a4d31f3 --- /dev/null +++ b/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/resources/META-INF/nutz/org.nutz.boot.starter.NbStarter @@ -0,0 +1 @@ +org.nutz.boot.starter.sqlxmltpl.SqlXmlTplIocLoaderStarter \ No newline at end of file diff --git a/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/resources/org/nutz/boot/starter/sqlxmltpl/sqlxmltpl.js b/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/resources/org/nutz/boot/starter/sqlxmltpl/sqlxmltpl.js new file mode 100644 index 00000000..63729ed0 --- /dev/null +++ b/nutzboot-starter/nutzboot-starter-sqlxmltpl/src/main/resources/org/nutz/boot/starter/sqlxmltpl/sqlxmltpl.js @@ -0,0 +1,16 @@ +var ioc = { + sqlTplIocEventListener: { + type: "com.github.threefish.nutz.sqltpl.SqlTplIocEventListener", + args: [{refer: '$ioc'}] + }, + beetlSqlTemplteEngineImpl: { + type: "com.github.threefish.nutz.sqltpl.BeetlSqlTemplteEngineImpl", + events: { + create: "init" + }, + fields: { + statementStart: {java: "$conf.get('sqlXmlTpl.statementStart','')"}, + statementEnd: {java: "$conf.get('sqlXmlTpl.statementEnd','')"} + } + } +} diff --git a/nutzboot-starter/pom.xml b/nutzboot-starter/pom.xml index b8c3a06f..ba238225 100644 --- a/nutzboot-starter/pom.xml +++ b/nutzboot-starter/pom.xml @@ -43,7 +43,7 @@ nutzboot-starter-feign nutzboot-starter-caffeine nutzboot-starter-hystrix - + nutzboot-starter-nutz-mvc nutzboot-starter-shiro nutzboot-starter-dubbo @@ -76,7 +76,9 @@ nutzboot-starter-ftp nutzboot-starter-fastdfs nutzboot-starter-fescar - + nutzboot-starter-sqlxmltpl + + org.nutz diff --git a/pom.xml b/pom.xml index 1b3b0597..cec19fa1 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,7 @@ nutzboot-core nutzboot-starter nutzboot-contrib +