当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
3 Star 0 Fork 0

poyexinghun / frame
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

JVSFrame

标签(空格分隔): 架构

Required: Java 1.6+

Dbs组件

详细介绍

Dbs是一个开源、基于XML的分布式的Web服务架构。每一种架构都是对普遍问题或特别问题的一种解决方案。Dbs可能要解决的是这样的一种特殊问题。

网站、客户端、接口 ---》 业务层服务 ---》 数据层服务

主要解决业务层及数据层的痛点,可能存在多种技术框架;业务层如何便捷的使用数据层服务,业务层之间的模块之间如何实现服务共享,

现有的解决方案提供服务注册中心,业务层服务、数据层服务都注册上去;业务层与数据层之间通过RPC的方式进行数据交换。

如果业务层与数据层之间通信要穿越网段、机房、防火墙,那注册中心就是个问题?

Dbs的解决方案则是数据层向业务层模块进行注册、业务层如果存在多个模块,各位模块相互注册,则彼此之间可以相互使用服务,就像使用本地服务一样。

Dbs底层的通信协议支持多种:HTTP、RPC等

架构

系统架构

快速入门

maven依赖配置

<dependency>
	<groupId>com.jarveis</groupId>
	<artifactId>frame</artifactId>
	<version>2.5.8</version>
</dependency>

frame配置文件(config.xml)

<?xml version="1.0" encoding="utf-8"?>
<config>
    
    <module>
        <parser clazz="com.jarveis.frame.dbs.DbsParser" />
    </module>
    
</config>

编写服务类

@Function(code="10001")
@Before(filters="logger,param")
@After(filters="param,logger")
public class EchoHello implements Service {

    public Param callService(Param in) {
        Param out = null;
        try {
            out = new Param(Param.RESP);
            String name = in.getBody().getString("@name");
    
            out.getBody().setProperty("@message", "Hello " + name);
            out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);
        } catch (Exception ex) {
            if ( out != null ) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
        }
        return out;
    }
}

服务启动:

  • 部署到tomcat,修改web.xml
<web-app>
	......
	<listener>
		<listener-class>com.jarveis.frame.dbs.server.DbsContextListenter</listener-class>
	</listener>

	<servlet>
		<servlet-name>dbs</servlet-name>
		<servlet-class>com.jarveis.frame.dbs.server.DbsServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dbs</servlet-name>
		<url-pattern>*.service</url-pattern>
	</servlet-mapping>
	......
</web-app>

服务请求: http://127.0.0.1:8080/dbs.service

核心部件

流程图

系统流程图

Filter

Filter是拦截业务的规则性组件,负责拦截业务请求。 Filter分为前置拦截组件和后置拦截组件。 创建Filter,需要实现Filter接口。

@Interceptor(code="logger" )
public class LoggerFilter implements Filter {

    public int init() {}
    public int destory() {}
    
    public int filter(Param param) {
        try {
            logger.info(param.toString());
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
        return 0;
    }
}

系统提供的默认Filter

  • 打印日志 LoggerFilter( code=“logger” )
  • 参数校验 ParamFilter( code=“param” )
  • 数据库连接与关闭 JdbsFilter( code=“jdbc” )
  • redis缓存连接与关闭 Redis( code=“redis” )

Service

Service是业务服务组件,负责处理单个特定的业务请求。 创建Service,需要实现Service接口。

  • 返回json,xml格式的数据
@Function(code="10001")
@Before(filters="logger,param")
@After(filters="param,logger")
public class EchoHello implements Service {

	public Param callService(Param in) {
		Param out = null;
		
		try {
			out = new Param(Param.RESP);
			String name = in.getBody().getString("@name");

			out.getBody().setProperty("@message", "Hello " + name);
			out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);

		} catch (Exception ex) {
            if ( out != null ) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
		}
		
		return out;
	}

}
  • 返回html格式的数据
@Function(code="10002")
@Before(filters="logger,param")
@After(filters="param,logger")
public class EchoHtml implements Service {

	public Param callService(Param in) {
		Param out = null;
		
		try {
			out = new Param(Param.RESP);
			String name = in.getBody().getString("@name");

			out.getBody().addCDATA("Hello " + name);
			out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);

		} catch (Exception ex) {
            if ( out != null ) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
		}
		
		return out;
	}

}
  • 内部服务的相互调用

在业务处理的过程中,会遇到多个服务之间的调用.对于服务来说有可能是本地的服务,也有可能是远程的服务(稍后的分布中会有说明).对于业务来说并不关心这些,希望两者是统一的.

Dbs会将所有的服务注册到本地的注册中心,用户只用关心本地注册中心有没有这些服务即可.关于调用的是本地的还是远程的交给代理服务来解决.

@Function(code="10002")
@Before(filters="logger,param")
@After(filters="param,logger")
public class EchoHtml implements Service {

	public Param callService(Param in) {
		Param out = null;
		
		try {
			out = new Param(Param.RESP);
			String name = in.getBody().getString("@name");
			
			Param subOut = ServiceProxy.callService("10003", in);
            if (Param.ERROR_SUCCESS.equals(subOut.getHead().getString(Param.LABEL_ERROR))) {
                out.getBody().addCDATA("Hello " + name);
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);
			} else {
			    out.getHead().setProperty(Param.LABEL_ERROR, "3001");
			}

		} catch (Exception ex) {
            if ( out != null ) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
		}
		
		return out;
	}

}

@Function(code="10003")
@Before(filters="logger,param")
@After(filters="param,logger")
public class CheckName implements Service {

	public Param callService(Param in) {
		Param out = null;
		
		try {
			out = new Param(Param.RESP);
			String name = in.getBody().getString("@name");
			
			if ("Tom".equals(name)){
			    out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);
			} else {
			    out.getHead().setProperty(Param.LABEL_ERROR, "3001");
			}
		} catch (Exception ex) {
            if ( out != null ) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
		}
		
		return out;
	}

}
  • 服务的作用域

服务功能的相互调用,会导致服务的相应抽象,比如有一个服务可以适配多个服务.同时也面临着另一个问题的产生,抽象的服务不想对外提供服务,仅限于本地内部服务的调用,此时我们引用了作用域的概念;Dbs支持服务的作用域分为,public和private;

public作用域,定义了服务可以对外提供服务;内部的服务可以调用,外部的服务也可以调用.Dbs默认服务是public作用域. private作用域,定义了服务可以对内提供服务;内部的服务可以调用,外部的服务不可以调用.

@Function(code="10003", scope = Scope.PRIVATE)
@Before(filters="logger,param")
@After(filters="param,logger")
public class CheckName implements Service {

	public Param callService(Param in) {
		Param out = null;
		
		try {
			out = new Param(Param.RESP);
			String name = in.getBody().getString("@name");
			
			if ("Tom".equals(name)){
			    out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);
			} else {
			    out.getHead().setProperty(Param.LABEL_ERROR, "3001");
			}
		} catch (Exception ex) {
            if ( out != null ) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
		}
		
		return out;
	}

}
  • 支持文件上传
@Function(code="10004")
@Before(filters="logger,param")
@After(filters="param,logger")
public class UploadService implements Service {

    public Param callService(Param in) {
        Param out = null;

        try {
            out = new Param(Param.RESP);

            String uploadPath = DbsCache.getConst("upload_folder");
            List<FileItem> formItems = DbsCache.getUploads();

            if (formItems != null && formItems.size() > 0) {
                // 迭代表单数据
                for (FileItem item : formItems) {
                    // 处理不在表单中的字段
                    if (!item.isFormField()) {
                        String fileName = new File(item.getName()).getName();
                        String filePath = uploadPath + File.separator + fileName;
                        File storeFile = new File(filePath);
                        // 保存文件到硬盘
                        item.write(storeFile);
                    }
                }
            }
            out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);
        } catch (Exception ex) {
            if (out != null) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
        }

        return out;
    }

}
  • 支持输入流
@Function(code="10005")
@Before(filters="logger,param")
@After(filters="param,logger")
public class UploadService implements Service {

    public Param callService(Param in) {
        Param out = null;

        try {
            out = new Param(Param.RESP);

            byte[] bytes = DbsCache.getStream();

            String str = new String(bytes);
            out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);
        } catch (Exception ex) {
            if (out != null) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
        }

        return out;
    }

}

如果使用上传组件,dbs.xml需要增加如下配置:

<dbs>
    ...
    
    <constants>
        ...
        <constant name="upload_memory_size" value="3145728" />
        <constant name="upload_file_size" value="41943040" />
        <constant name="upload_request_size" value="52428800" />
        <constant name="upload_folder" value="D:\\tmp" />
        ...
    </constants>
    
    ...
</dbs>

Param

Param是输入和输出数据的标准对象,Dbs将接收到的输入参数封装成Param对象方便Dbs框架内的数据交换及处理,Dbs最终会将返回的Param对象,转换成用户需要的数据格式;

对于数据的输入与输出并没有作相同格式的限定,也就是说json的输入可得到(json|xml|html)格式的输出.同样对于xml的输入也可以得到(json|xml|html)格式的输出.输出的格式是按照在传入的返回数据格式来生成的.

输入支持

  • 支持json数据格式;
  • 支持xml数据格式;
  • 支持参数形式传递;

输出支持

  • 支持json数据格式;
  • 支持xml数据格式;
  • 支持html数据格式;

json数据格式

输入和输出

{
    "head": {
        "dataType": "返回数据格式",
        "device": "设备标识",
        "token": "会话标识",
        "funcId": "服务编号"
    },
    "body": {
        propKey: propValue,
        ...
    }
}
/* 实例-输入 */
{
    "head": {
        "dataType": "json",
        "device": "a7bf1feda8124fd7a15b302691ba164f",
        "token": "dbded8a69c9a41d4908a24f5c58ae419",
        "funcId": "10001"
    },
    "body": {
        name: "jvsframe"
    }
}
/* 实例-输出 */
{
    "head": {
        "dataType": "json",
        "device": "a7bf1feda8124fd7a15b302691ba164f",
        "token": "dbded8a69c9a41d4908a24f5c58ae419",
        "funcId": "10001"
    },
    "body": {
        message: "Hello jvsframe"
    }
}

xml数据格式

输入

<Req>
<head device="设备标识" token="会话标识" funcId="服务编号" dataType="返回数据格式" />
<body propKey="propValue" />
</Req>

<!-- 实例 -->
<Req>
<head device="a7bf1feda8124fd7a15b302691ba164f" token=“dbded8a69c9a41d4908a24f5c58ae419” funcId="10001" dataType="xml"/>
<body name="jvsframe" />
</Req>

输出

<?xml version="1.0" encoding="UTF-8"?>
<Resp>
<head device="设备标识" token=“会话标识” funcId="服务编号" dataType="返回数据格式"/>
<body propKey=propValue ...>
    (<extensibleNode proKey=propValue ... />) 
</body>
</Resp>

/* 实例 */
<Resp>
<head device="a7bf1feda8124fd7a15b302691ba164f" token=“dbded8a69c9a41d4908a24f5c58ae419” funcId="10001" dataType="xml"/>
<body message="Hello jvsframe" />
</Resp>

html数据格式

输入:使用json,xml的输入数据格式,定义dataType="html"

/* 实例-输入 */
{
    "head": {
        "dataType": "html",
        "device": "a7bf1feda8124fd7a15b302691ba164f",
        "token": "dbded8a69c9a41d4908a24f5c58ae419",
        "funcId": "10001"
    },
    "body": {
        name: "jvsframe"
    }
}

<Req>
<head device="a7bf1feda8124fd7a15b302691ba164f" token=“dbded8a69c9a41d4908a24f5c58ae419” funcId="10001" dataType="html"/>
<body name="jvsframe" />
</Req>

输出

<?xml version="1.0" encoding="UTF-8"?>
<Resp>
<head device="设备标识" token=“会话标识” funcId="服务编号" dataType="返回数据格式"/>
<body>
    <![CDATA[
    (html code|javascript code)
    ]]> 
</body>
</Resp>

/* 实例-输出 */
<?xml version="1.0" encoding="UTF-8"?>
<Resp>
<head device="设备标识" token=“会话标识” funcId="服务编号" dataType="返回数据格式"/>
<body>
    <![CDATA[
    <h1>Hello jvsframe</h1>
    ]]> 
</body>
</Resp>

<?xml version="1.0" encoding="UTF-8"?>
<Resp>
<head device="设备标识" token=“会话标识” funcId="服务编号" dataType="返回数据格式"/>
<body>
    <![CDATA[
    <script>alert('Hello jvsframe')</script>
    ]]> 
</body>
</Resp>

请求方式

为发方便前端多原化的请求方式,dbs支持提供了两种类型的请求方式.

http://127.0.0.1:8080/dbs.service?message={"head":{"device":"a7bf1feda8124fd7a15b302691ba164f","token":"dbded8a69c9a41d4908a24f5c58ae419","funcId":"10001","dataType":"json"},"body":{"name":"jvsframe"}}

http://127.0.0.1:8080/dbs.service?_message=xml格式

http://127.0.0.1:8080/dbs.service?message=<Req><head device="a7bf1feda8124fd7a15b302691ba164f" token="dbded8a69c9a41d4908a24f5c58ae419" funcId="10001" dataType="xml"/><body name="jvsframe"/>
http://127.0.0.1:8080/10001.service?_device=a7bf1feda8124fd7a15b302691ba164f&_token=dbded8a69c9a41d4908a24f5c58ae419&name=jvsframe

http://127.0.0.1:8080/{返回数据格式}/10001.service?参数集

http://127.0.0.1:8080/json/10001.service?_device=a7bf1feda8124fd7a15b302691ba164f&_token=dbded8a69c9a41d4908a24f5c58ae419&name=jvsframe

http://127.0.0.1:8080(/{访问标识}/{设备编号}/{渠道}/{版本号})/{返回数据格式}/10001.service?参数集

http://127.0.0.1:8080/dbded8a69c9a41d4908a24f5c58ae419/a7bf1feda8124fd7a15b302691ba164f/json/10001.service?name=jvsframe

常量

业务开发的过程中会使用到一些配置信息,Dbs提供了基于dbs.xml的配置处理.

/* dbs.xml */
<dbs>
    ...
    <constants>
        <constant name="配置名" value="配置值" />
    </constants>
    ...
</dbs>

如何获取配置数据,可以通过DbsCache.getConst("配置名"),方法来获取配置值.

    public Param callService(Param in) {
		Param out = null;
		
		try {
			out = new Param(Param.RESP);
			String name = in.getBody().getString("@name");
			String whiteNames = DbsCache.getConst("white.list");
			if (whiteNames.indexOf(name)){
			    out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_SUCCESS);
			} else {
			    out.getHead().setProperty(Param.LABEL_ERROR, "3001");
			}
		} catch (Exception ex) {
            if ( out != null ) {
                out.getHead().setProperty(Param.LABEL_ERROR, Param.ERROR_EXCEPTION);
            }
		}
		
		return out;
	}

扩展组件

微服务

启动入口

com.jarveis.frame.dbs.jetty.Dbs4Jetty

配置参数

dbs.contextPath = / 应用程序的上下文路径,默认的值("/")

dbs.httpPort = 8080 应用程序的端口号,默认值(8080)

dbs.poolSize = 500 应用程序的处理线程池大小,默认值(500)

完整配置

java -Ddbs.contextPath=/test -Ddbs.httpPort=8080 -Ddbs.poolSize=200 com.jarveis.frame.dbs.jetty.Dbs4Jetty

分布式

在大型应用中,服务都是模块化的,对于模块与模块之间的调用.Dbs给出了自己的解决方案.

分布式1

模块与模块之间通信,需要知道调用模块的通信地址.如果A模块与B模块建立了联系,那A模块与B模块之间的服务则可相互调用;如果再有C模块接入A模块或B模块,那A模块,B模块,C模块之间的服务则可相互调用.

分布式2

分布式配置 A模块(dbs.xml),端口号:8001

<constants>
    <!-- 本地主机,服务使用方 -->
	<constant name="dbs_local" value="" />
	<!-- 远程主机,服务提供方 -->
	<constant name="dbs_remote" value="http://127.0.0.1:8001" />
</constants>

B模块(dbs.xml),端口号:8002

<constants>
    <!-- 本地主机,服务使用方 -->
	<constant name="dbs_local" value="http://127.0.0.1:8002" />
	<!-- 远程主机,服务提供方 -->
	<constant name="dbs_remote" value="http://127.0.0.1:8001" />
</constants>

C模块(dbs.xml),端口号:8003

<constants>
    <!-- 本地主机,服务使用方 -->
	<constant name="dbs_local" value="http://127.0.0.1:8003" />
	<!-- 远程主机,服务提供方 -->
	<constant name="dbs_remote" value="http://127.0.0.1:8001" />
</constants>

Puddle组件

详细介绍

Puddle是一个开源、基于Ehcache,Redis搭建的二级缓存框架。一级缓存使用Ehcache,二级缓存使用Redis。Puddle参考并借用了J2Cache的思想及相关代码,并跟据自身项目需要开发的一套缓存组件。

流程图

流程图

快速入门

maven依赖配置

<dependency>
    <groupId>com.jarveis</groupId>
    <artifactId>frame</artifactId>
    <version>2.3.3</version>
</dependency>

frame配置文件(config.xml)

<?xml version="1.0" encoding="utf-8"?>
<config>
    
    ...
    
    <module>
        ...
        <parser clazz="com.jarveis.frame.cache.Puddle" />
        ...
    </module>
    
    <redisConfig>
        <datasource id="db56" default="true">
            <property name="ip" value="192.168.1.175" />
            <property name="host" value="192.168.1.175" />
            <property name="port" value="6379" />
            <property name="password" value="1qaz2wsx" />
            <property name="database" value="0" />
            <property name="timeout" value="20000" />
            <property name="maxTotal" value="100" />
            <property name="maxIdle" value="20" />
            <property name="maxWait" value="10000" />
            <property name="testOnBorrow" value="true" />
            <property name="testOnReturn" value="true" />
            <!-- 通知 -->
            <property name="channel" value="j2cache_channel" />
        </datasource>
    </redisConfig>
    
    <puddleConfig>
        <puddle>
            <!-- broadcast: (jgroups | redis) -->
            <property name="broadcast" value="jgroups" />
            <!-- l1_provider: (echache) -->
            <property name="l1_provider" value="ehcache" />
            <!-- l2_provider: (redis) -->
            <property name="l2_provider" value="redis" />
            <!-- serialization: (fst | fst-snappy | fastjson | java) -->
            <property name="serialization" value="fst" />
        </puddle>
    </puddleConfig>
    
    ...
</config>

新增配置文件,ehcache.xml, network.xml; ehcache.xml提供了一级缓存(ehcache)组件所需要的配置。

<ehcache updateCheck="false" dynamicConfig="false">

    <diskStore path="java.io.tmpdir" />

    <cacheManagerEventListenerFactory
        class="" properties="" />

    <defaultCache maxElementsInMemory="1000" eternal="false"
        timeToIdleSeconds="1800" timeToLiveSeconds="1800"
        overflowToDisk="true">
    </defaultCache>

    <cache name="session" maxElementsInMemory="5000" eternal="false"
        timeToIdleSeconds="1800" timeToLiveSeconds="1800"
        overflowToDisk="false" />

</ehcache>

network.xml提供了缓存节点间通信组件(jgroups)所需的配置。如果缓存节点的通信使用redis,可以忽略此配置文件。

<config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.4.xsd">

    <UDP
         mcast_addr="${jgroups.udp.mcast_addr:235.5.5.5}"
         mcast_port="${jgroups.udp.mcast_port:45588}"
         tos="8"
         ucast_recv_buf_size="20M"
         ucast_send_buf_size="640K"
         mcast_recv_buf_size="25M"
         mcast_send_buf_size="640K"
         loopback="true"
         max_bundle_size="64K"
         max_bundle_timeout="30"
         ip_ttl="${jgroups.udp.ip_ttl:2}"
         enable_diagnostics="true"
         thread_naming_pattern="cl"

         timer_type="new"
         timer.min_threads="4"
         timer.max_threads="10"
         timer.keep_alive_time="3000"
         timer.queue_max_size="500"

         thread_pool.enabled="true"
         thread_pool.min_threads="2"
         thread_pool.max_threads="8"
         thread_pool.keep_alive_time="5000"
         thread_pool.queue_enabled="true"
         thread_pool.queue_max_size="10000"
         thread_pool.rejection_policy="discard"

         oob_thread_pool.enabled="true"
         oob_thread_pool.min_threads="1"
         oob_thread_pool.max_threads="8"
         oob_thread_pool.keep_alive_time="5000"
         oob_thread_pool.queue_enabled="false"
         oob_thread_pool.queue_max_size="100"
         oob_thread_pool.rejection_policy="Run"/>

    <PING timeout="2000" num_initial_members="3"/>
    <MERGE2 max_interval="30000" min_interval="10000"/>
    <FD_SOCK/>
    <FD_ALL/>
    <VERIFY_SUSPECT timeout="1500"  />
    <BARRIER />
    <pbcast.NAKACK use_mcast_xmit="true"
                   retransmit_timeout="300,600,1200"
                   discard_delivered_msgs="true"/>

    <pbcast.STABLE stability_delay="1000" 
                   desired_avg_gossip="50000"
                   max_bytes="4M"/>
    <pbcast.GMS print_local_addr="true"
                print_physical_addrs="true"
                join_timeout="3000"
                view_bundling="true"
                max_join_attempts="3"/>
                
    <UFC max_credits="2M" min_threshold="0.4"/>
    <MFC max_credits="2M" min_threshold="0.4"/>
    <FRAG2 frag_size="60K"  />
    <pbcast.STATE_TRANSFER />

</config>

如何在程序中使用缓存组件,请参考如下代码:

CacheChannel cache = Puddle.getChannel();
String region = "const";
String key = "message";
cache.put(region, key, "hello world");
// 设置缓存有效期,时间单位:秒
// cache.put(region, key, "hello world", 300); //当前缓存的有效期为5分种

JDBC组件

详细介绍

主要包括

  • 支持O/R Mapping
  • 支持SQL操作

O/R Mapping

@Table(name = "user")
public class User {
	
	@Column(primaryKey = true)
	private Long suid;
	@Column
	private String uname;
	@Column
	private String uphone;

	
	public User(){}

	public Long getSuid() {
		return suid;
	}

	public void setSuid(Long suid) {
		this.suid = suid;
	}

	public String getUname() {
		return this.uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public String getUphone() {
		return this.uphone;
	}

	public void setUphone(String uphone) {
		this.uphone = uphone;
	}
}

public class CreateUserService implements Service {
	
	public Param callService(Param in) {
		
		String uname = in.getProperty("@uname"); // 用户名
		String uphone = in.getProperty("@uphone"); // 手机号
		
		User user = new User();
		long suid = generateCode();
		user.setSuid(suid);
		user.setUphone(uphone);
		user.setUname(uname);
		JdbcUtil.save(s);
		
	}
	
}

SQL

public class LoadUserService implements Service {
	
	public Param callService(Param in) {
		
		String uphone = in.getProperty("@uphone"); // 手机号
		
		HashMap<String, String> params = new HashMap<String, String>(1);
		params.put("uphone", uphone);
		
		Map mapResult = new HashMap();
		try {
			mapResult = (Map) JdbcUtil.query("select * from user where uphone = :uphone limit 1", new MapHandler(), params);
		} catch (SQLException e) {
			logger.error(e.getMessage(), e);
		}

		Param item = out.getBody().addParam("user");
		item.setProperty("@suid", (Long) mapResult.get("suid"));
		item.setProperty("@uname", (String) mapResult.get("uname"));
		item.setProperty("@uphone", (String) mapResult.get("uphone"));
		
	}
	
}


public class LoadUserService implements Service {
	
	public Param callService(Param in) {
		
		String uphone = in.getProperty("@uphone"); // 手机号
		
		HashMap<String, String> params = new HashMap<String, String>(1);
		params.put("uphone", uphone);
		
		User user = new User();
		try {
			user = (Map) JdbcUtil.query("select * from user where uphone = :uphone limit 1", new BeanHandler(User.class), params);
		} catch (SQLException e) {
			logger.error(e.getMessage(), e);
		}

		Param item = out.getBody().addParam("user");
		item.setProperty("@suid", user.getSuid("suid"));
		item.setProperty("@uname", user.getUname("uname"));
		item.setProperty("@uphone", user.getUphone("uphone"));
		
	}
	
}

Sliuce组件

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2018 poyexinghun Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/poyexinghun/frame.git
git@gitee.com:poyexinghun/frame.git
poyexinghun
frame
frame
master

搜索帮助