小编nai*_*eem的帖子

在spring boot websocket中向特定用户发送通知

我想向特定客户发送通知.

例如用户名用户

@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)

java spring stomp spring-boot spring-websocket

13
推荐指数
2
解决办法
4949
查看次数

我如何在 Spring Data Hibernate 的关系表中使用 findBy

我附上了我的表数据的快照。表名称是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)

订单明细表图片

java spring hibernate spring-data spring-data-jpa

6
推荐指数
1
解决办法
5798
查看次数

用角反应形式的现有阵列初始化表格阵列

我有一个从服务器获取的部门列表的动态数组。我想在初始化时将该数组推入数组,基本上我想根据部门名称或数组中的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”数组中(从数据库中获取)。

在此先感谢,任何建议将不胜感激。

forms angular2-forms angular angular-reactive-forms

5
推荐指数
2
解决办法
9832
查看次数

自定义查询,用于从Spring Data Jpa中的多个表中获取数据

实体正在追踪

产品表

@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 jpql spring-data-jpa

4
推荐指数
1
解决办法
2万
查看次数