package service;
import common.Constant;
import common.Response;
import entity.Student;
import java.util.ArrayList;
import java.util.List;
public class BusinessService {
private static List businessList = new ArrayList<>();
static {
businessList.add(new Student(“1”,“张三”,“男”,“25”,“北京”));
businessList.add(new Student(“2”,“李四”,“男”,“26”,“南京”));
businessList.add(new Student(“3”,“王五”,“男”,“27”,“武汉”));
}
// 查询
public Response query(String name){
if(name == null || “”.equals(name)){
return new Response(“error”,“编号为空。”);
}
for(Student student : businessList){
if(name.equals(student.getStuId())){
return new Response(“success”,“查询成功。”, student);
}
}
return new Response(“error”,“未查询到此”+ Constant.MAIN_CLASS +“,请重新输入:”);
}
// 增加
public Response add(Student student){
for(Student s : businessList){
if(s.getStuId().equals(student.getStuId())){
return new Response(“error”,“该”+ Constant.MAIN_CLASS+“已存在。”);
}
}
businessList.add(student);
return new Response(“success”, Constant.MAIN_CLASS+“添加成功。”, student);
}
// 编辑
public Response checkProp(Student student, String prop, String value){
if(prop == null || “”.equals(prop)){
return new Response(“error”,“属性为空。”);
}
String[] props = {“stuId”,“stuName”,“stuSex”,“stuAge”,“stuWeight”};
switch(prop){
case “stuId” :
student.setStuId(value);
break;
case “stuName” :
student.setStuName(value);
break;
case “stuSex” :
student.setStuSex(value);
break;
case “stuAge” :
student.setStuAge(value);
break;
case “stuAddress” :
student.setStuAddress(value);
break;
default:
return new Response(“error”,“该属性不存在。”);
}
return new Response(“success”,“编辑成功。”);
}
// 删除
public Response delete(String name){
if(name == null || “”.equals(name)){
return new Response(“error”, Constant.MAIN_CLASS+“编号为空。”);
}
for(Student student: businessList){
if(student.getStuId().equals(name)){
businessList.remove(student);
return new Response(“success”, Constant.MAIN_CLASS+“删除成功。”);
}
}
return new Response(“error”, Constant.MAIN_CLASS+“不存在。”);
}
}
LoginService
package service;
import common.Account;
import common.Response;
import entity.User;
import java.util.ArrayList;
import java.util.List;
public class LoginService {
private static List userList = new ArrayList();
static{
userList.add(new User(Account.ADMIN.getUsername(), Account.ADMIN.getPassword()));
userList.add(new User(Account.USER1.getUsername(), Account.USER1.getPassword()));
userList.add(new User(Account.USER2.getUsername(), Account.USER2.getPassword()));
userList.add(new User(Account.USER3.getUsername(), Account.USER3.getPassword()));
}
public Response login(String username, String password){
if(username == null || “”.equals(username)){
return new Response(“error”,“用户名为空,请输入用户名。”);
}
if(password == null || “”.equals(password)){
return new Response(“error”,“密码为空,请输入密码。”);
}
for (User user : userList){
if(username.equals(user.getUsername()) && password.equals(user.getPassword())){
return new Response(“success”,“登陆成功!”);
}
}
return new Response(“error”,“用户名或密码输入错误,请检查并重新输入。”);
}
}
四、其他
====
1.其他系统实现
2.获取源码
点击以下链接获取源码。
3.运行项目
直接导入项目,打开Main运行程序。
统-Java文档类资源-CSDN下载Java实现控制台学生信息管理系统,实现登录、增删改查,系统经多次测试,运行无误,请大家放心下载。更多下载资源、学习资料请访问CSDN下载频道.[外链图片转存中…(img-zIkaC3wS-1716962311329)]https://download.csdn.net/download/helongqiang/21048450](https://download.csdn.net/download/helongqiang/21048450 “Java实现控制台学生信息管理系统-Java文档类资源-CSDN下载”)
3.运行项目
直接导入项目,打开Main运行程序。