Merge pull request #158 from threefish/add-nutzboot-starter-sqlxmltpl

添加nutzboot-starter-sqlxmltpl
This commit is contained in:
Wendal Chen 2019-04-04 16:16:30 +08:00 committed by GitHub
commit 717dc37a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 490 additions and 3 deletions

View File

@ -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的重要一支

View File

@ -0,0 +1,7 @@
FROM azul/zulu-openjdk:8
MAINTAINER wendal <wendal1985@gmail.com>
ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/share/nb.jar"]
# Add the service itself
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/nb.jar

View File

@ -0,0 +1,66 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-demo-simple</artifactId>
<version>2.3.4-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-demo-simple-sqlxmltpl</artifactId>
<properties>
<docker.image.prefix>nutzboot</docker.image.prefix>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-nutz-mvc</artifactId>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-nutz-dao</artifactId>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-swagger</artifactId>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-sqlxmltpl</artifactId>
<version>${nutzboot.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
</dependencies>
</project>

View File

@ -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<User> userList = userService.queryLikeNameByCnd(Cnd.where("name", "like", "a%"), new Pager(0, 5));
List<NutMap> 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()));
}
}

View File

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

View File

@ -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<User> query(@Param("..")Pager pager) {
return dao.query(User.class, Cnd.orderBy().asc("age"), pager);
}
}

View File

@ -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<User> queryLikeNameByCnd(Cnd cnd, Pager pager);
List<NutMap> queryMapslikeName(NutMap param);
}

View File

@ -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<User> 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<User> queryLikeNameByCnd(Cnd cnd, Pager pager) {
return queryEntityBySql("queryLikeNameByCnd", NutMap.NEW(), cnd);
}
@Override
public List<NutMap> queryMapslikeName(NutMap param) {
return queryMapBySql("queryMapslikeName", param);
}
@Override
public SqlsTplHolder getSqlsTplHolder() {
return this.sqlsTplHolder;
}
@Override
public Dao getDao() {
return super.dao();
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Sqls PUBLIC "nutz-sqltpl" "https://threefish.gitee.io/nutz-sqltpl/nutz-sqltpl.dtd">
<Sqls class="io.nutz.demo.simple.service.impl.UserServiceImpl">
<!--var是当前文件的共享变量var中不能有表达式-->
<var name="tableName">t_user</var>
<!--wrap=true 表示将会清除换行符\n 默认不清除-->
<sql id="queryLikeName" wrap="true">
SELECT * from ${tableName}
<exp>if(isNotEmpty(name)){</exp>
where name like @name
<exp>}</exp>
</sql>
<sql id="queryLikeNameByCnd" wrap="true">
SELECT * from ${tableName} $condition
</sql>
<sql id="queryMapslikeName" wrap="true">
SELECT * from ${tableName}
<exp>if(isNotEmpty(name)){</exp>
where name like @name
<exp>}</exp>
</sql>
</Sqls>

View File

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

View File

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

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello, So NB!</title>
</head>
<body>
<div>
<h2>Hello, So NB!</h2>
</div>
<div>
<h2>
<a href="swagger/index.html">查看api文档(由Swagger生成)</a>
</h2>
</div>
<div>
<h2><a href="druid/">Druid监控页面,用户名密码在日志搜索 "druid stat view"</a></h2>
</div>
</body>
</html>

View File

@ -30,7 +30,7 @@
<module>nutzboot-demo-simple-zkclient</module>
<module>nutzboot-demo-simple-velocity</module>
<module>nutzboot-demo-simple-jetty</module>
<module>nutzboot-demo-simple-caffeine</module>
<module>nutzboot-demo-simple-hystrix</module>
<module>nutzboot-demo-simple-eureka-client</module>
@ -57,6 +57,8 @@
<module>nutzboot-demo-simple-dao-with-many</module>
<module>nutzboot-demo-simple-ftp</module>
<module>nutzboot-demo-simple-fastdfs</module>
<module>nutzboot-demo-simple-sqlxmltpl</module>
</modules>
<dependencies>

View File

@ -0,0 +1,68 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter</artifactId>
<version>2.3.4-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<name>nutzboot-starter-sqlxmltpl</name>
<artifactId>nutzboot-starter-sqlxmltpl</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>NutzBoot, nutzboot-starter-sqlxmltpl</description>
<url>http://nutzam.com</url>
<issueManagement>
<system>Github Issue</system>
<url>http://github.com/nutzam/nutzboot/issues</url>
</issueManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<id>threefish</id>
<name>threefish</name>
<email>huchuc@vip.qq.com</email>
<url>http://github.com/threefish/</url>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/nutzam/nutzboot.git</connection>
<developerConnection>scm:git:git://github.com/nutzam/nutzboot.git</developerConnection>
<url>git://github.com/nutzam/nutzboot.git</url>
</scm>
<distributionManagement>
<snapshotRepository>
<id>nutzcn-snapshots</id>
<name>NutzCN snapshot repository</name>
<url>https://jfrog.nutz.cn/artifactory/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-release-staging</id>
<name>Sonatype Nexus release repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.github.threefish/nutz-sqltpl -->
<dependency>
<groupId>com.github.threefish</groupId>
<artifactId>nutz-sqltpl</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.ibeetl</groupId>
<artifactId>beetl</artifactId>
<version>${beetl.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -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 = "<exp>")
public static final String statementStart = PRE + "statementStart";
@PropDoc(group = "sqlXmlTpl", value = "sqlXmlTpl模版语言语句结束", defaultValue = "</exp>")
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");
}
}

View File

@ -0,0 +1 @@
org.nutz.boot.starter.sqlxmltpl.SqlXmlTplIocLoaderStarter

View File

@ -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','<exp>')"},
statementEnd: {java: "$conf.get('sqlXmlTpl.statementEnd','</exp>')"}
}
}
}

View File

@ -43,7 +43,7 @@
<module>nutzboot-starter-feign</module>
<module>nutzboot-starter-caffeine</module>
<module>nutzboot-starter-hystrix</module>
<module>nutzboot-starter-nutz-mvc</module>
<module>nutzboot-starter-shiro</module>
<module>nutzboot-starter-dubbo</module>
@ -76,7 +76,9 @@
<module>nutzboot-starter-ftp</module>
<module>nutzboot-starter-fastdfs</module>
<module>nutzboot-starter-fescar</module>
</modules>
<module>nutzboot-starter-sqlxmltpl</module>
</modules>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>

View File

@ -78,6 +78,7 @@
<module>nutzboot-core</module>
<module>nutzboot-starter</module>
<module>nutzboot-contrib</module>
<!--<module>nutzboot-demo</module>-->
</modules>