我有一个使用 lambda 实现的函数调用,它使用 jooq 库在 postgres 数据库中插入一行。
下面是代码:
dslContext.transaction(
c -> {
this.postgresService.insertData(c, table, map);
});
Run Code Online (Sandbox Code Playgroud)
其中 c 类型为 org.jooq.Configuration。
该代码工作正常并在表中插入一条记录并返回插入的记录。如何访问 lambda 函数返回的主键。
这是 insertData 的函数:
public Record insertData(
Configuration configuration, Table<? extends Record> table, Map<TableField<? extends Record, ?>, Object> map
)
{
return DSL.using(configuration)
.insertInto(table)
.set(map)
.returning()
.fetchOne();
}
Run Code Online (Sandbox Code Playgroud) 我正在编写一个 spring boot api,它从数据库获取一些数据,存储在模型对象中并返回它。但我只想返回模型的几个字段作为 api 响应。
List<MyModel> myModelList = new ArrayList<>();
mongoUserCollection.find().into(myModelList);
class MyModel{
public int id;
public String name;
public String lastname;
public int age;
// getter & setter of all properties
}
Run Code Online (Sandbox Code Playgroud)
我正在显示 myModelList 作为响应。作为回应,它显示了所有字段。如何仅显示特定字段,例如仅显示 ID 和年龄。仅从数据库中选择 ID 和年龄仍将显示响应中模型的所有字段(姓名和姓氏将显示为空)。除了创建新的 ModelView 类或将 JsonIgnore 设置为该模型之外,还有什么方法吗?
a = [
{
"id" : 15,
"name" : "abc"
},
{
"id" : 16,
"name" : "xyz"
},
{
"id" : 17,
"name" : "pqr"
}
]
b = [15,17]
Run Code Online (Sandbox Code Playgroud)
我上面有两个列表,如果列表b中没有id,我想从列表a中删除该对象.任何帮助,怎么做?
输出清单:
[
{
"id" : 15,
"name" : "abc"
},
{
"id" : 17,
"name" : "pqr"
}
]
Run Code Online (Sandbox Code Playgroud)