我想向特定客户发送通知.
例如用户名用户
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends
AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/socket")
.setAllowedOrigins("*")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic", "/queue");
registry.setApplicationDestinationPrefixes("/app");
}
Run Code Online (Sandbox Code Playgroud)
调节器
@GetMapping("/notify")
public String getNotification(Principal principal) {
String username = "user";
notifications.increment();
logger.info("counter" + notifications.getCount() + "" + principal.getName());
// logger.info("usersend:"+sha.getUser().getName()) ; //user
template.convertAndSendToUser(principal.getName(), "queue/notification", notifications);
return "Notifications successfully sent to Angular !";
}
Run Code Online (Sandbox Code Playgroud)
客户端
角度服务
connect() {
let socket = new SockJs(`api/socket`);
let stompClient = Stomp.over(socket);
return stompClient;
} …Run Code Online (Sandbox Code Playgroud) 我附上了我的表数据的快照。表名称是orderdetail。
我想获取有关客户的数据。就像我的例子一样,数据应该基于PurchasedBy.
@Entity
public class OrderDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name="purchased_By")
private User purchasedBy;
Run Code Online (Sandbox Code Playgroud)
OrderDetailDao我正在尝试在存储库中使用以下查询
List<OrderDetail> findByPurchasedBy(User user);
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [purchasedBy] on this ManagedType [com.example.Domain.OrderDetail]
Run Code Online (Sandbox Code Playgroud)
编辑摘要 >
当我使用findAll()并返回 json 时,该purchasedBy部分如下所示:
"purchasedBy":{
"id":15,
"email":"admin@gmail.com",
"password":"$2a$10$jj41EbJZTOBfbKdJ6wAdx.rdQq8qU3OqoSzS5mvDVaiL33G1U4pPC",
"name":"admin",
"lastName":"admin",
"active":1,
"roleselected":null,
"roles":[
{
"id":1,
"role":"admin",
"users":[
],
"new":false
}
],
"new":false
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个从服务器获取的部门列表的动态数组。我想在初始化时将该数组推入数组,基本上我想根据部门名称或数组中的ID显示复选框。我知道如何以反应形式推送空数组,但是如何使用现有数组初始化。实际上是一个更新/编辑组件
departmentList:any=[]; //array contains all departments
SelectedDeptList:any=[]; //fetched from db , selected departments
userForm: FormGroup;
this.userForm = this.fb.group({ //fb form builder
'phone': [null],
'departmentList': this.fb.array([this.createDepartment()]),
})
createDepartment(): FormGroup {
return this.fb.group({
'name': ''//checkbox value true or false
});
}
Run Code Online (Sandbox Code Playgroud)
模板
<div formArrayName="departmentList"
*ngFor="let item of
userForm.get('departmentList').controls; let i = index;">
<div class="col-md-6" [formGroupName]="i">
<div class="form-group">
<div class="col-md-4">
<label class="mt-checkbox mt-checkbox-outline">
<input formControlName="name" type="checkbox" > Department Name
<span></span>
</label>
</div>
</div>
</div></div>
Run Code Online (Sandbox Code Playgroud)
去做 ?
1)我怎么能填充或初始化所有的dept复选框的列表,那些应该是真实的存在或存在于我的“ SelectedDeptList”数组中(从数据库中获取)。
在此先感谢,任何建议将不胜感激。
实体正在追踪
产品表
@Entity
public class Product implements Serializable {
/*@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@NotNull(message = "Product name must not be null")
@NotEmpty
private String name;
@ManyToOne
@JoinColumn(name="category_id")
private Category category;
@ManyToMany(mappedBy = "productlist")
private List<OrderDetail> orderDetail =new ArrayList<OrderDetail>();
//getters setter
Run Code Online (Sandbox Code Playgroud)
订单明细表
@Entity
public class OrderDetail {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ManyToOne
@JoinColumn(name="purchased_By")
private user PurchasedBy;
@ManyToMany
private Set<Product> productlist = new HashSet<Product>();
Run Code Online (Sandbox Code Playgroud)
这些实体生成的表名为“ order_detail_productlist”,其字段如下order_detail_id和productlist_id
我正在mysql编辑器中运行以下查询,并且正在运行
select u.id, …Run Code Online (Sandbox Code Playgroud) hibernate ×2
java ×2
spring ×2
angular ×1
forms ×1
jpql ×1
spring-boot ×1
spring-data ×1
stomp ×1