最近,我接受了cognizant的采访。在面试中,他们让我写一个单例设计模式,我做到了。之后他们问我'好吧,现在告诉我们你可以在哪里使用单例?'我说'管理数据库连接'。
他们对我的回答不满意,他们问'好吧,你能用单例模式管理访问你的数据库的 100 万用户吗?我无语,因为我不知道答案。
我想知道哪种设计模式最适合数据库连接?如果我必须管理超过 10000 个用户连接到我的数据库,我该怎么做?
如果你们能帮助我解决这个话题,我将不胜感激。
谢谢
我想在 junit 中为计算器程序编写测试用例。我是 junit 环境的新手。我可以为其他程序编写测试,但有点坚持测试 switch() 情况。
我真的很想知道该怎么做。
提前致谢
这是我的程序
import java.util.Scanner;
//This program performs basic math operations such as :- +,-,*,/
public class Calculator
{
public static void main(String[] args)
{
double number1, number2;
String Mathoperation;
Scanner scannerObject = new Scanner(System.in);
System.out.println("Enter first number");
number1 = scannerObject. nextDouble();
System.out.println("Enter second number");
number2 = scannerObject. nextDouble();
Scanner UserInput = new Scanner(System.in);
System.out.println("\nHere are your options:");
System.out.println("\n1. Addition, 2. Subtraction, 3. Divison, 4. Multiplication");
Mathoperation = UserInput.next();
switch (Mathoperation)
{
case …Run Code Online (Sandbox Code Playgroud) 我正在学习 spring Rest api 并编写了以下方法将数据保存到数据库中。
@GetMapping(path="/add") // Map ONLY GET Requests
public @ResponseBody String addNewUser (@RequestParam String name
, @RequestParam String email) {
// @ResponseBody means the returned String is the response, not a view name
// @RequestParam means it is a parameter from the GET or POST request
User n = new User();
n.setName(name);
n.setEmail(email);
userRepository.save(n);
return "Saved";
}
Run Code Online (Sandbox Code Playgroud)
现在我想编写 put 查询,它可以获取用户 ID,然后更新名称或电子邮件。另外,我需要检查用户名和电子邮件不应为空,并且电子邮件的格式是否有效。
我如何使用 @putmapping 构建我的方法来执行我的任务。