# 查询语句

查询语句是建立在数据表基数上的查询语句配置。配置查询语句后，在应用中可调用执行。

## 入口 <a href="#ru-kou" id="ru-kou"></a>

点系统的左上角导航->设计中心->数据中心->具体应用->查询配置打开

## 查询语句的后台服务 <a href="#shi-tu-de-hou-tai-fu-wu" id="shi-tu-de-hou-tai-fu-wu"></a>

​<http://applicationServer:20020/x\\_query\\_assemble\\_surface/jest/index.html​>

![](https://3148786149-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmN_rNQCcekD6lUTyjN%2F-LmgqGIfWmYdK5Od_X3n%2F-Lmgt1C1ZsKAU95ZBjFy%2FQQ%E5%9B%BE%E7%89%8720190820103821.png?alt=media\&token=212725e7-eae2-4002-875a-a813a5e29381)

## 创建查询配置

1、创建查询配置；

2、选择语句类型和数据表；

3、编写查询语句，保存

## 查询语句

### 语法

查询语句用的是JPA JPQL语句，如 `select o from tableName o where o.name='zhangsan'`。

了解JPQL语句可以点击链接查看：<https://www.objectdb.com/java/jpa/query/jpql/structure>​

### 动态传参

查询语句中的where语句的值可以使用json传入

如：

查询语句的设计为 `select o from tableName o where o.name=:n`

在调用查询语句的时候传入 json

```
{
    "n" : "zhangsan"
}
```

则 最终在后台拼接成的语句为

`select o from tableName o where o.name='zhangsan'`

![](https://3148786149-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmN_rNQCcekD6lUTyjN%2F-Lmhys6Yo5MzbQaYVwbS%2F-Lmi-hBf0EpR6jsHHt98%2FQQ%E5%9B%BE%E7%89%8720190820155112.png?alt=media\&token=3d2b1d5d-4846-44fe-8826-736ede414ad1)

了解JPQL语句动态传参可以点击链接查看：<https://www.objectdb.com/java/jpa/query/parameter>

## 使用 <a href="#shu-ju-biao-jiao-ben" id="shu-ju-biao-jiao-ben"></a>

需要编写脚本去使用查询语句

### 方法一

```
o2.Actions.get( "x_query_assemble_surface" ).executeStatement(
    statementFlag, //语句id、语句名称或语句别名
    page, //页码，数字
    size,  //每页条数
    data, //请求的json
    function(json){
        //json为执行結果
    },
    function(xhr){ 
        //如果返回错误，在这里处理
    },
    async //同步还是异步
)
```

例如：现在已有一个查询语句配置`select o from student o where o.class=:class`，存储的别名是 selectStudent，取第一页的10条，那么方法如下：

```
o2.Actions.get( "x_query_assemble_surface" ).executeStatement(
    "selectStudent",1,10,{
        class : "01计算机一班"
    },function(json){
        //json 为返回的结果
    }
)
```

### 方法二

```
var action = new this.Action( "x_query_assemble_surface", {
    executeStatement:{ //服务命名1，自定义
        "uri": "/jaxrs/statement/{flag}/execute/page/{page}/size/{size}", //服务地址1，形如 /jaxrs/...
        "method": "POST" //请求方法，包括 GET POST PUT DELETE
    }
);
action.invoke({
    "name": "executeStatement", //自定义的服务名
    "parameter": {
        "flag": statementFlag, //语句id、语句名称或语句别名
        "page" : page, //页码，数字
        "size" : size //每页条数
    },  //uri参数
    "data": {  }, //请求的正文
    "success": function(json){ //服务调用成功时的回调方法，json 是服务返回的数据
        //这里进行具体的处理
    }.bind(this),
    "failure" : function(xhr){ //服务调用失败时的回调方法，xhr 为 XMLHttpRequest 对象
        //这里进行具体的处理
    },
    "async" : true, //同步还是异步，默认为true
});
```

例如：现在已有一个查询语句配置`select o from student o where o.class=:class`，存储的别名是 selectStudent，取第一页的10条，那么方法如下：

```
var action = new this.Action( "x_query_assemble_surface", {
    executeStatement:{ //服务命名1，自定义
        "uri": "/jaxrs/statement/{flag}/execute/page/{page}/size/{size}", //服务地址1，形如 /jaxrs/...
        "method": "POST" //请求方法，包括 GET POST PUT DELETE
    }
);
action.executeStatement({
    "name": "executeStatement", //自定义的服务名
    "parameter": { //uri参数
        "flag": selectStudent, //语句id、语句名称或语句别名
        "page" : 1, //页码，数字
        "size" : 10 //每页条数
    },  
    "data": { //请求的正文
        class : "01计算机一班"
     }, 
     "success" : function(json){
         //json 为返回的结果
     }
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://o2oa.gitbook.io/course/liu-cheng-guan-li/untitled-3/cha-xun-yu-ju.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
