我正在使用@NamedEntityGraph注释从数据库加载图表.
@NamedEntityGraph(
name = "Firma.uredjivanje",
attributeNodes = {
@NamedAttributeNode(value="prevodi", subgraph = "prevodi")
},
subgraphs = {
@NamedSubgraph(
name = "prevodi",
attributeNodes = {
@NamedAttributeNode(value = "jezik", subgraph = "jezik")
}
)
}
)
Run Code Online (Sandbox Code Playgroud)
在Spring Data JPA存储库中,我使用的是注释:
@EntityGraph(value="Firma.uredjivanje", type = EntityGraph.EntityGraphType.LOAD)
List<Firma> getByAktivna(boolean aktivna);
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作,期望所有关系都加入,我得到重复的Firma实体(因为JOIN).我得到{1,1,1,2,2,3}而不是实体ID为{1,2,3}的List.
获取不同实体的最佳方法是什么(如果这不是一个错误的话).
为什么以下代码:
StringBuilder sb22 = IntStream
.range(1, 101)
.filter(x -> x > 50)
.boxed()
.parallel()
.collect(// object that is used in accumulator to do accumulating on
StringBuilder::new,
// use object from above and call append on it with each stream element as argument
(sb, a) -> sb.append(":" + a),
// (executes only when using parallel!)
(sb1, sb2) -> {
System.out.println(Thread.currentThread().getId() + " " + "sb1=" + sb1 + " AND " + "sb2=" + sb2);
sb1.append("-"+sb2);
});
Run Code Online (Sandbox Code Playgroud)
产生这个结果:
------------------:51:52:53-:54:55:56-:57:58:59-:60:61:62-:63:64:65-:66:67:68-:69:70:71-:72:73-:74:75-:76:77:78-:79:80:81-:82:83:84-:85:86:87-:88:89:90-:91:92:93-:94:95:96-:97:98-:99:100
Run Code Online (Sandbox Code Playgroud)
不应该首先将part(------------------ …
我有java接口和类实现,在调用类似的行为时需要不同的参数.以下哪项最适合?
在第一个选项中,我有不同的类从基接口继承公共行为,所有差异只在类中直接实现,而不是在接口中实现.这个似乎最合适,但我必须在代码中进行手动类型转换.
public class VaryParam1 {
static Map<VehicleType, Vehicle> list = new HashMap<>();
static List<Car> carsList = new ArrayList<>();
static List<TruckWithTrailer> trucksList = new ArrayList<>();
public static void main(String[] args) {
list.put(VehicleType.WITHOUT_TRAILER, new Car());
list.put(VehicleType.WITH_TRAILER, new TruckWithTrailer());
//violates LSP?
((Car)list.get(VehicleType.WITHOUT_TRAILER)).paint(1); //ok - but needed manual cast
((TruckWithTrailer)list.get(VehicleType.WITH_TRAILER)).paint(1, "1"); //ok - but needed manual cast
carsList.add(new Car());
trucksList.add(new TruckWithTrailer());
//Does not violate LSP
carsList.get(0).paint(1);
trucksList.get(0).paint(1, "1");
}
}
enum VehicleType {
WITHOUT_TRAILER,
WITH_TRAILER;
}
interface Vehicle{
//definition of all common methods …Run Code Online (Sandbox Code Playgroud) 是否可以在Java中定义以下内容:
public interface IGenericRepo<T> {
void add();
void delete();
void attach();
}
public interface IGenericRepo<Book> {
default String bookSpecificMethod(){
return "smthn";
}
}
public class NHGenericRepo<T> implements IGenericRepo<T>{
/* implementation */
}
public class NHUnitOfWork implements UnitOfWork{
@Autowired
public void setBookRepo(NHGenericRepo<Book> bookRepo) {
this.bookRepo= bookRepo;
}
public NHGenericRepo<Book> getBookRepo() {
return bookRepo;
}
private NHGenericRepo<Book> bookRepo;
}
Run Code Online (Sandbox Code Playgroud)
并且能够在代码中的某个地方拥有:
{
@Autowired
public void setNhuw(NHUnitOfWork nhuw) {
this.nhuw = nhuw;
}
private NHUnitOfWork nhuw;
/**/
{
String st = this.nhuw.getBookRepo().bookSpecificMethod();
}
} …Run Code Online (Sandbox Code Playgroud) 在运行时构造它的最简单方法是什么?
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "providedAtRuntime", durable = "true"),
exchange = @Exchange(value = "providedAtRuntime", ignoreDeclarationExceptions = "true"),
key = "providedAtRuntime"), containerFactory = "cFac")
public class RabbitProcessor {
@RabbitHandler
public void receive (String smth){
System.out.println(smth);
}
}
Run Code Online (Sandbox Code Playgroud)
我想定义监听器,但在运行时提供交换,队列名称和绑定.此侦听器也不应自动启动,而应由start()方法调用.同时它应该自动声明绑定和队列等.当调用stop()时,它应该停止消耗.
我想这是非常基本的 F# 问题:
类型有:
type Id1 =
| Id1 of int
type Id2 =
| Id2 of string
type Id =
| Id1
| Id2
type Child = {
Id : Id;
Smth : string list
}
type Node =
| Child of Child
| Compos of Node * Node
Run Code Online (Sandbox Code Playgroud)
哪里Node和Child应该代表复合 OOP 设计模式的替代品。
问题是我不能以这种方式实例化类型:
let i1 : Child = {Id = Id1(1); Smth = []} //Id1 value is not a function and cannot be applied
let …Run Code Online (Sandbox Code Playgroud) java ×5
generics ×2
amqp ×1
collectors ×1
composite ×1
f# ×1
hibernate ×1
java-stream ×1
jpa ×1
oop ×1
rabbitmq ×1
spring ×1
spring-amqp ×1