java main框架_Main.java

package com.bdqn;

import java.util.ArrayList;

import java.util.InputMismatchException;

import java.util.Scanner;

public class Main {

//应用程序入口

public static void main(String[] args) {

//创建员工业务服务类

EmployeeService empService = new EmployeeService();

Scanner input = new Scanner(System.in);

boolean flag = false;

try {

do {

System.out.println("*************欢迎使用员工信息管理系统*************");

System.out.println("1、查看所有员工信息");

System.out.println("2、新增员工信息");

System.out.println("3、根据工号查询员工信息");

System.out.println("4、根据姓名查询员工信息");

System.out.println("5、根据工号修改员工信息");

System.out.println("6、根据工号删除员工信息");

System.out.println("0、退出系统");

System.out.println("*******************************************");

System.out.print("请选择:");

int choice = input.nextInt();

switch (choice) {

case 1:

ArrayList empList = empService.getEmpList();

empService.printAllEmp(empList);

break;

case 2:

System.out.print("请输入工号:");

int jobNo = input.nextInt();

System.out.print("请输入姓名:");

String name = input.next();

System.out.print("请输入年龄:");

int age = input.nextInt();

System.out.print("请输入工资:");

double sal = input.nextDouble();

//创建新员工对象

Employee newEmp = new Employee(jobNo, name, age, sal);

boolean res = empService.addEmp(newEmp);

if(res) {

System.out.println("添加新员工成功!");

}

else {

System.out.println("该员工工号已存在,请重新输入!");

}

break;

case 3:

break;

case 4:

break;

case 5:

break;

case 6:

System.out.print("请输入员工工号:");

int id = input.nextInt();

res = empService.deleteEmpById(id);

if(res) {

System.out.println("删除员工成功!");

}

else {

System.out.println("该名员工不存在!");

}

break;

case 0:

flag = true;

System.out.println("谢谢使用!");

break;

}

} while (!flag);

} catch (InputMismatchException e) {

System.out.println("输入错误!");

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用Java框架中的ZooKeeper时,如果需要进行SASL身份验证,可以按照以下步骤进行操作: 1.在ZooKeeper服务器端配置JVM参数,启用SASL身份验证,例如: ``` -Dzookeeper.serverCnxnFactory=org.apache.zookeeper.server.NettyServerCnxnFactory -Djava.security.auth.login.config=/path/to/zookeeper_server_jaas.conf ``` 2.在ZooKeeper客户端端配置JVM参数,启用SASL身份验证,例如: ``` -Djava.security.auth.login.config=/path/to/zookeeper_client_jaas.conf ``` 3.在ZooKeeper服务器端和客户端端分别编写对应的JAAS配置文件,例如: 服务器端配置文件zookeeper_server_jaas.conf: ``` Server { org.apache.zookeeper.server.auth.DigestLoginModule required user_admin="password"; }; ``` 客户端配置文件zookeeper_client_jaas.conf: ``` Client { org.apache.zookeeper.server.auth.DigestLoginModule required username="admin" password="password"; }; ``` 其中,user_admin和password是服务器端的用户名和密码,username和password是客户端的用户名和密码。 4.在ZooKeeper客户端端编写对应的代码,例如: ``` import org.apache.zookeeper.*; import org.apache.zookeeper.data.Stat; import java.io.IOException; import java.util.concurrent.CountDownLatch; public class ZooKeeperClient { private static final String CONNECT_STRING = "localhost:2181"; private static final int SESSION_TIMEOUT = 5000; private static final String ZOOKEEPER_PATH = "/test"; private static CountDownLatch countDownLatch = new CountDownLatch(1); public static void main(String[] args) throws IOException, InterruptedException, KeeperException { ZooKeeper zooKeeper = new ZooKeeper(CONNECT_STRING, SESSION_TIMEOUT, new Watcher() { @Override public void process(WatchedEvent event) { if (event.getState() == Event.KeeperState.SyncConnected) { countDownLatch.countDown(); } } }); countDownLatch.await(); String result = new String(zooKeeper.getData(ZOOKEEPER_PATH, false, new Stat())); System.out.println(result); zooKeeper.close(); } } ``` 以上代码中,我们使用了CountDownLatch来等待ZooKeeper客户端连接上ZooKeeper服务器。在连接成功之后,我们调用了zooKeeper.getData()方法来获取指定路径节点的数据。 以上就是在Java框架中使用ZooKeeper进行SASL身份验证的方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值