简体   繁体   English

如何在我的 Web App 上显示用户总数?

[英]How do I display the total number of users on my Web App?

I am a beginner in Java and I'm trying to display the total number of clients on my html file.我是 Java 的初学者,我正在尝试在我的 html 文件上显示客户端总数。 I tried setting it as a variable directly from my app controller but it returns a blank display.我尝试直接从我的应用程序 controller 将其设置为变量,但它返回空白显示。 Any help on how I could display the total number of client/users is greatly appreciated.非常感谢有关如何显示客户/用户总数的任何帮助。

Here's what I did这就是我所做的

MY CONTROLLER我的 CONTROLLER

@RequestMapping("/backoffice-admin/admins/editar-admin/{id}")
public String dash6a(@PathVariable("id") int id, Model model) {

     model.addAttribute("num", clientRepository.countById(id));

    return "/backoffice-admin/admins/editar-admin";

}

REPOSITORY存储库

package com.cometa.app.repository;

import javax.validation.Valid;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

import com.cometa.app.model.Client;

public interface ClientRepository extends CrudRepository<Client, Integer> {

@Query(value = "SELECT COUNT(id) FROM client;", nativeQuery = true)
    int countById(int id);
}

HTML file HTML 文件

<div class="stats-holder-2-2-2" th:each="client, custStat: ${num}">
      <a href="/backoffice-admin/clientes/todos-clientes" class="wrapper_stats-2 w-inline-block">
        <div class="div-block-99">
          <div class="div-block-137 azul">
            <div class="text-block-113">1</div>
          </div>
          <div class="div-block-101" >
            <div class="text-block-114 _303" th:text="${custStat.count}">[[${num}]]</div>
            <div class="text-block-115">Clientes</div>
          </div>

The answer will depend on what you consider to be a user that you want to count.答案将取决于您认为什么是您想要计算的用户。

It is straightforward to cound the requests.计算请求很简单。 Every time your application assembles the data to be returned to the client you can increase a count variable.每次您的应用程序组装要返回给客户端的数据时,您都可以增加一个计数变量。 Many frameworks can provide such counts on their own as well.许多框架也可以自行提供此类计数。

You could also check user sessions (given that your application works session oriented).您还可以检查用户会话(假设您的应用程序面向 session 工作)。 Many frameworks also offer such counters.许多框架也提供这样的计数器。 If need be, create and register a HttpSessionListener .如果需要,创建并注册一个HttpSessionListener With that you can count current and total amount of sessions created.有了它,您可以计算当前和创建的会话总数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想从我的Java Web应用程序访问他们自己的保管箱的用户。 我怎样才能做到这一点? - I want to give access to users of their own dropbox from my java web app. How can I do that? 我想显示设备中的消息总数 - I want to display the total number of messages in my device 我如何知道机器上Web应用程序的URL? - How do I know the URL of a web app on my machine? 如何在我的应用程序而不是网络浏览器中打开 URL? - How do I open a URL in my app instead of the web browser? 我如何在我的Web应用程序中包含Ajax - How do i include Ajax in my web app 如何让我的Android应用生成随机数? - How do I make my Android app generate a random number? 如何根据订阅级别为不同用户设计具有不同功能集的Web应用程序? - How do I design a Web app with different feature sets for different users based on subscription level? 我的应用程序正在显示图像网址。 我如何下载图像以使其可以显示在我的应用程序中 - My app is displaying the image url. How do i download the image so that it can display on my app 如何将随机数加到Java(二十一点)的总数中? - How can i add the random number to my total for java(blackjack)? 如何允许用户将图像上传到我的应用程序并使用它们? - How do I allow users to upload images to my app, and use them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM