使用 Angular 2+,我如何在 HTML 中执行类似波纹管的操作?
{{ object.array.map( (o)=> o.property ) }}
Run Code Online (Sandbox Code Playgroud)
此代码会使 Angular 应用程序崩溃。我必须使用管道或类似的东西?
null我有一个可为空的对象,如果该对象不满足且不满足条件,我将尝试抛出异常。
我尝试用以下方法Optional:
Optional.ofNullable(nullableObject)
.filter(object -> "A".equals(object.getStatus()))
.orElseThrow(() -> new BusinessUncheckedException("exception message"));
Run Code Online (Sandbox Code Playgroud)
当对象不是 时null,它会按我想要的方式工作,但否则,它也会引发异常(我不希望这样)。
有一种方法可以做到这一点,Optional或者有其他方法不使用if object != null?
我从用户表中制作了两个外键。
db.Subscription.belongsTo(db.User, {foreignKey: 'creatorId'});
db.Subscription.belongsTo(db.User, {foreignKey: 'subscriberId'});
Run Code Online (Sandbox Code Playgroud)
在搜索查询期间,我得到的subscriberId列包含而不是creatorId
Subscription.findAll({
where: {
subscriberId: req.decoded._id
},
include: [
{
model: User,
foreignKey: 'creatorId',
attributes: ['name', 'role', 'uid', 'imageUrl']
}
]
})
Run Code Online (Sandbox Code Playgroud)
有人可以找出我在这里做错了什么。
我正在尝试过滤实现接口的对象列表。我正在尝试为所有类创建一个通用方法。
就像是:
interface SomeInterface {
String getFlag();
}
class SomeObject implements SomeInterface {
public String getFlag() {
return "X";
}
}
List<SomeObject> someObjectList = new ArrayList<>();
// Compilation error here
List<SomeObject> filterList = filterGenericList(someObjectList, "X");
private List<?> filterGenericList(List<? extends SomeInterface> objects, String flag) {
return objects.stream()
.filter(it -> it.getFlag().equals(flag))
.collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)
如何避免编译错误?
Incompatible types.
Found: 'java.util.List<capture<?>>',
Required: 'java.util.List<SomeObject>'
Run Code Online (Sandbox Code Playgroud) java ×2
angular ×1
generics ×1
java-8 ×1
java-stream ×1
javascript ×1
list ×1
mysql ×1
node.js ×1
option-type ×1
sequelize.js ×1
typescript ×1