栏目介绍
本栏目专为入门java学习者设计的一些简单的入门项目
功能介绍
本项目为简单的基于控制台的通讯录管理系统,所需要的环境仅仅为jdk以及mysql(版本不限)!只有一个简单的eclipse软件以及我们的mysql可视化工具(视频使用navicat)
本项目数据库表仅有一个,单表操作,方便学习!
本项目使用mvc设计模式,使用面向对象的开发思想
本项目使用最基础的jdbc的方式链接的数据库
本项目主要实现的功能有:
- 系统运行成功后的欢迎及菜单页面
- 添加联系人功能
- 联系人查询功能(分名称和手机号查询)
- 显示联系人列表
- 根据编号删除指定编号的联系人
- 修改指定编号的联系人
- 退出登录
项目实现截图
项目结构:
 
数据表结构(单表user)
 
1.项目通过main方法运行后的页面
 
2.新增用户页面功能
 
3.联系人查询功能(按照姓名和手机号码)
 
4.显示联系人列表功能页面

5.根据编号删除指定编号的联系人
 
6.修改指定编号的联系人
 
7.退出
 
项目部分代码
jdbc工具:
    public static String db_url = "jdbc:mysql://localhost:3306/addressbook?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf-8";
    public static String db_user = "root";
    public static String db_pass = "123456";
    
    public static Connection getConn () {
        Connection conn = null;
        
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return conn;
    }
    
主方法类:
package com.maker.address.web;
import java.util.ArrayList;
import java.util.Scanner;
import com.maker.address.entity.User;
import com.maker.address.service.UserService;
public class UserMain {
	static UserService user = new UserService();
	static Scanner sc = new Scanner(System.in);
	public static void start() {
		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("【0】退出");
		System.out.println("=============================");
		int i = sc.nextInt();
		switch (i) {
		case 1:
			add();
			start();
			break;
		case 2:
			System.out.println("【1】通过联系人姓名查询/【2】通过联系人电话查询");
			int a = sc.nextInt();
			findbyName(a);
			start();
			break;
		case 3:
			show();
			start();
			break;
		case 4:
			del();
			start();
			break;
		case 5:
			update();
			start();
			break;
		case 0:
			System.out.println("谢谢使用,再见!");
			System.exit(0);
			break;
		default:
			System.out.println("请输入正确的指令!");
			start();
			break;
		}
	}
	//修改用户
	private static void update() {
		// TODO Auto-generated method stub
		System.out.println("请输入要修改的联系人编号:");
		int a = sc.nextInt();
		System.out.println("请输入姓名:");
		String b = sc.next();
		System.out.println("请输入手机号:");
		String c = sc.next();
		judgePhone(c);
		System.out.println("请输入QQ:");
		String d = sc.next();
		System.out.println("请输入邮箱地址:");
		String e = sc.next();
		judgeEmail(e);
		User x = new User(a, b, c, d, e);
		if (user.updateUser(x)) {
			System.out.println("修改成功!");
		}
	}
	public static void add() {
		System.out.println("请输入联系人编号:");
		int a = sc.nextInt();
		System.out.println("请输入联系人姓名:");
		String b = sc.next();
		System.out.println("请输入联系人手机号:");
		String c = sc.next();
		judgePhone(c);
		System.out.println("请输入联系人QQ:");
		String d = sc.next();
		System.out.println("请输入联系人邮箱地址:");
		String e = sc.next();
		judgeEmail(e);
		User x = new User(a, b, c, d, e);
		if (user.addUser(x)) {
			System.out.println("添加成功!");
		}
	}
	public static void judgePhone(String phone) {
		if (phone.matches("1[34589][0-9]{9}")) {
		} else {
			System.out.println("手机号输入有误,请重新输入");
			String v = sc.next();
			judgePhone(v);
		}
	}
	public static void judgeEmail(String email) {
		if (email.matches("[A-Za-z0-9]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)")) {
		} else {
			System.out.println("邮箱格式输入有误,请重新输入");
			String v = sc.next();
			judgeEmail(v);
		}
	}
	public static void findbyName(int a) {
		if (a == 1) {
			System.out.println("请输入联系人姓名");
		} else {
			System.out.println("请输入联系人电话");
		}
		String name = sc.next();
		User user = UserMain.user.searchByName(name);
		System.out.println(user);
	}
	public static void show() {
		ArrayList list = user.showInfo();
		for (Object o : list) {
			System.out.println(o);
		}
	}
	public static void del() {
		System.out.println("请输入编号");
		int no = sc.nextInt();
		if (user.delUser(no)) {
			System.out.println("删除成功");
		}
	}
	public static void main(String[] args) {
		start();
	}
}














![[STL]详解vector模拟实现](https://img-blog.csdnimg.cn/img_convert/2489d1738e6f13dc4fd2e6f8c2ea6f91.png)




