package com.jxust.view;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import com.jxust.action.GoddessAction;
import com.jxust.model.Goddess;
/**
* 视图层
* 与用户进行交互的页面,这里使用控制台,没有使用jsp页面
* 页面功能还不完善
* @author Peng
*
*/
public class View {
private static final String CONTEXT="欢迎来到女神禁区:\n" +
"下面是女神禁区的功能列表:\n" +
"[MAIN/M]:主菜单\n" +
"[QUERY/Q]:查看全部女神的信息\n" +
"[GET/G]:查看某位女神的详细信息\n" +
"[ADD/A]:添加女神信息\n" +
"[UPDATE/U]:更新女神信息\n" +
"[DELETE/D]:删除女神信息\n" +
"[SEARCH/S]:查询女神信息(根据姓名、手机号来查询)\n" +
"[EXIT/E]:退出女神禁区\n" +
"[BREAK/B]:退出当前功能,返回主菜单";
private static final String OPERATION_MAIN = "MAIN";
private static final String OPERATION_QUERY = "QUERY";
private static final String OPERATION_GET = "GET";
private static final String OPERATION_ADD = "ADD";
private static final String OPERATION_UPDATE = "UPDATE";
private static final String OPERATION_DELETE = "DELETE";
private static final String OPERATION_SEARCH = "SEARCH";
private static final String OPERATION_EXIT = "EXIT";
private static final String OPERATION_BREAK = "BREAK";
public static void main(String[] args) {
System.out.println(CONTEXT);
// 怎么保持一个程序一直运行
Scanner scanner = new Scanner(System.in);
Goddess goddess = new Goddess();
GoddessAction action = new GoddessAction();
String previous = null;
Integer step = 1;
String cha = null;
while (scanner.hasNext()) {
String in = scanner.next().toString();
if (OPERATION_EXIT.equals(in.toUpperCase())// 大写
|| OPERATION_EXIT.substring(0, 1).equals(in.toUpperCase())) {// 输入e
System.out.println("您已成功退出女神禁区");
break;
}else if (OPERATION_BREAK.equals(in.toUpperCase())
|| OPERATION_BREAK.substring(0, 1).equals(in.toUpperCase())) {
System.out.println(CONTEXT);
previous = null;
step = 1;
cha = null;
continue;
}else if (OPERATION_QUERY.equals(in.toUpperCase())
|| OPERATION_QUERY.substring(0, 1).equals(in.toUpperCase())) {
System.out.println("下面是本禁区女神的基本信息");
try {
List<Goddess> list = action.query();
for (Goddess go : list) {
System.out.println("编号:" + go.getId() + ",姓名:" + go.getUser_name());
}
} catch (SQLException e) {
e.printStackTrace();
}
continue;
} else if (OPERATION_MAIN.equals(in.toUpperCase())
|| OPERATION_MAIN.substring(0, 1).equals(in.toUpperCase())) {
System.out.println(CONTEXT);
continue;
} else if (OPERATION_DELETE.equals(in.toUpperCase())
|| OPERATION_DELETE.substring(0, 1).equals(in.toUpperCase()) || OPERATION_DELETE.equals(previous)) {
previous = OPERATION_DELETE;
if (1 == step) {
System.out.println("请输入待删除女神的编号");
step++;
} else if (2 == step) {
step = 1;
try {
action.del(Integer.parseInt(in));
System.out.println("删除女神成功");
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
continue;
} else if (OPERATION_GET.equals(in.toUpperCase()) || OPERATION_GET.substring(0, 1).equals(in.toUpperCase())
|| OPERATION_GET.equals(previous)) {
previous = OPERATION_GET;
if (1 == step) {
System.out.println("请输入女神的编号,查看某位女神的详细信息");
step++;
} else if (2 == step) {
try {
step = 1;
Goddess go = action.get(Integer.parseInt(in));
System.out.println("编号:" + go.getId());
System.out.println("姓名:" + go.getUser_name());
System.out.println("年龄:" + go.getAge());
System.out.println("性别:" + "女");
System.out.println("生日:" + go.getBirthday());
System.out.println("邮箱:" + go.getEmail());
System.out.println("手机号:" + go.getMobile());
} catch (Exception e) {
System.out.println("没有找到这位女神的信息");
}
}
continue;
} else if (OPERATION_SEARCH.equals(in.toUpperCase())
|| OPERATION_SEARCH.substring(0, 1).equals(in.toUpperCase()) || OPERATION_SEARCH.equals(previous)
|| "NAME".equals(cha) || "MOBILE".equals(cha)) {
previous = OPERATION_SEARCH;
if (1 == step) {
System.out.println("输入要查询的字段" + "\n姓名[NAME]" + "\n手机号[MOBILE]");
step++;
} else if (2 == step) {
if ("NAME".equals(in.toUpperCase())) {
cha = "NAME";
System.out.println("请输入要查询的姓名:");
} else if ("MOBILE".equals(in.toUpperCase())) {
cha = "MOBILE";
System.out.println("请输入要查询的手机号:");
} else {
step = 1;
continue;
}
step++;
} else if (3 == step) {
if ("NAME".equals(cha)) {
List<Map<String, Object>> params = new ArrayList<Map<String, Object>>();
Map<String, Object> param = new HashMap<String, Object>();
param.put("name", "user_name");
param.put("rela", "like");
param.put("value", "'%" + in + "%'");
params.add(param);
List<Goddess> list;
try {
list = action.query(params);
for (int i = 0; i < list.size(); i++) {
System.out.println("编号:" + list.get(i).getId());
System.out.println("姓名:" + list.get(i).getUser_name());
System.out.println("年龄:" + list.get(i).getAge());
System.out.println("性别:" + "女");
System.out.println("生日:" + list.get(i).getBirthday());
System.out.println("邮箱:" + list.get(i).getEmail());
System.out.println("手机号:" + list.get(i).getMobile());
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
}
step = 1;
continue;
} else if ("MOBILE".equals(cha)) {
List<Map<String, Object>> params = new ArrayList<Map<String, Object>>();
Map<String, Object> param = new HashMap<String, Object>();
param.put("name", "mobile");
param.put("rela", "like");
param.put("value", "'%" + in + "%'");
params.add(param);
List<Goddess> list;
try {
list = action.query(params);
for (int i = 0; i < list.size(); i++) {
System.out.println("编号:" + list.get(i).getId());
System.out.println("姓名:" + list.get(i).getUser_name());
System.out.println("年龄:" + list.get(i).getAge());
System.out.println("性别:" + "女");
System.out.println("生日:" + list.get(i).getBirthday());
System.out.println("邮箱:" + list.get(i).getEmail());
System.out.println("手机号:" + list.get(i).getMobile());
System.out.println();
}
} catch (SQLException e) {
e.printStackTrace();
}
step = 1;
continue;
}
}
} else if (OPERATION_ADD.equals(in.toUpperCase()) || OPERATION_ADD.substring(0, 1).equals(in.toUpperCase())
|| OPERATION_ADD.equals(previous)) {
previous = OPERATION_ADD;
// 新增女神
if (1 == step) {
System.out.println("请输入女神的[姓名]");
step++;
} else if (2 == step) {
goddess.setUser_name(in);
System.out.println("请输入女神的[年龄]");
step++;
} else if (3 == step) {
goddess.setAge(Integer.valueOf(in));
System.out.println("请输入女神的[生日],格式如:yy-MM-dd");
step++;
} else if (4 == step) {
SimpleDateFormat sf = new SimpleDateFormat("yy-MM-dd");
Date birthday = null;
try {
birthday = sf.parse(in);
goddess.setBirthday(birthday);
System.out.println("请输入女神的[邮箱]");
} catch (ParseException e) {
没有合适的资源?快使用搜索试试~ 我知道了~
新 MVC架构的JDBC项目(加入存储过程和函数的调用)
共24个文件
java:10个
class:10个
classpath:1个
需积分: 10 32 下载量 124 浏览量
2016-10-07
11:57:39
上传
评论
收藏 949KB ZIP 举报
温馨提示
JDBC 连接 MySQL 数据库,进行增删该查,在控制台输入输出数据,不涉及jsp和html,加入存储过程和函数的调用
资源推荐
资源详情
资源评论
收起资源包目录
MVC架构的JDBC项目new.zip (24个子文件)
Jdbc_MySQL
.project 386B
src
com
jxust
view
View.java 10KB
action
GoddessAction.java 1KB
db
DBUtil.java 788B
model
Goddess.java 2KB
dao
GoddessDao.java 7KB
ProcedureDao.java 3KB
test
JDBCTestProcedure.java 2KB
TestDao.java 2KB
TestAction.java 1KB
TestDBUtil.java 1KB
lib
mysql-connector-java-5.1.39-bin.jar 966KB
.settings
org.eclipse.jdt.core.prefs 598B
.classpath 379B
bin
com
jxust
view
View.class 9KB
action
GoddessAction.class 2KB
db
DBUtil.class 1KB
model
Goddess.class 3KB
dao
ProcedureDao.class 4KB
GoddessDao.class 8KB
test
JDBCTestProcedure.class 909B
TestDBUtil.class 2KB
TestAction.class 3KB
TestDao.class 2KB
共 24 条
- 1
资源评论
伍Wu哈Ha
- 粉丝: 468
- 资源: 40
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功