完整版的View代码块有谁写出来了吗
完整版的View代码块有谁写出来了吗
完整版的View代码块有谁写出来了吗
2015-09-20
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) { Scanner input = new Scanner(System.in); Goddess g = new Goddess(); GoddessAction ga = new GoddessAction(); System.out.println(CONTEXT); // 保持程序持续运行 String cpu = null; Integer step = 0; while (input.hasNext()) {// 如果有输入值,则返回true String in = input.next(); if (OPERATION_EXIT.equals(in.toUpperCase()) || OPERATION_EXIT.substring(0, 1).equals(in.toUpperCase())) { System.out.println("您已成功退出女神后宫"); break; } else if (OPERATION_MAIN.equals(in.toUpperCase()) || OPERATION_MAIN.substring(0, 1).equals(in.toUpperCase())) { System.out.println(CONTEXT); } else if (OPERATION_BREAK.equals(in.toUpperCase()) || OPERATION_BREAK.substring(0, 1).equals(in.toUpperCase())) { cpu = null; step = 0; System.out.println(CONTEXT); } else if (OPERATION_ADD.equals(in.toUpperCase()) || OPERATION_ADD.substring(0, 1).equals(in.toUpperCase()) || OPERATION_ADD.equals(cpu)) { cpu = OPERATION_ADD; if (step == 0) { System.out.println("请输入女神的[姓名]"); } else if (step == 1) { g.setUser_name(in); System.out.println("请输入女神的[年龄]"); } else if (step == 2) { g.setSex(1); g.setAge(Integer.parseInt(in)); System.out.println("请输入女神的[生日],格式为:yyyy-MM-dd"); } else if (step == 3) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date birthday = null; try { birthday = sdf.parse(in); g.setBirthday(birthday); System.out.println("请输入女神的[邮箱]"); } catch (ParseException e) { e.printStackTrace(); System.out.println("您输入的格式有误,请重新输入"); step = 2; } } else if (step == 4) { g.setEmail(in); System.out.println("请输入女神的[电话]"); } else if (step == 5) { g.setMobile(in); System.out.println("请输入添加人"); } else if (step == 6) { g.setCreate_user(in); g.setUpdate_user(in); g.setIsdel(1); try { ga.add(g); System.out.println("添加女神成功"); } catch (Exception e) { e.printStackTrace(); System.out.println("添加女神失败"); } } if (step == 6) { step = 0; } else { step++; } } else if (OPERATION_QUERY.equals(in.toUpperCase()) || OPERATION_QUERY.substring(0, 1).equals(in.toUpperCase())) { try { List<Goddess> list = ga.query(); for (Goddess goddess : list) { System.out.println(goddess.getId() + "号女神:" + goddess.getUser_name() + " 芳龄:" + goddess.getAge()); } } catch (Exception e) { e.printStackTrace(); } } else if (OPERATION_GET.equals(in.toUpperCase()) || OPERATION_GET.substring(0, 1).equals(in.toUpperCase())) { System.out.println("请输入需要查询的女神编号"); String in2 = input.next(); try { g = ga.query(Integer.valueOf(in2)); ga.show(g); } catch (Exception e) { e.printStackTrace(); } } else if (OPERATION_DELETE.equals(in.toUpperCase()) || OPERATION_DELETE.substring(0, 1).equals(in.toUpperCase())) { System.out.println("请输入要删除的女神"); String in2 = input.next(); try { ga.del(Integer.valueOf(in2)); System.out.println("删除女神成功"); } catch (Exception e) { e.printStackTrace(); System.out.println("删除女神失败"); } } else if (OPERATION_UPDATE.equals(in.toUpperCase()) || OPERATION_UPDATE.substring(0, 1).equals(in.toUpperCase()) || OPERATION_UPDATE.equals(cpu)) { cpu = OPERATION_UPDATE; if (step == 0) { System.out.println("进去更新"); System.out.println("请输入需要修改的女神编号"); } else if (step == 1) { g.setId(Integer.valueOf(in)); System.out.println("请输入女神的[姓名]"); } else if (step == 2) { g.setUser_name(in); System.out.println("请输入女神的[年龄]"); } else if (step == 3) { g.setSex(1); g.setAge(Integer.parseInt(in)); System.out.println("请输入女神的[生日],格式为:yyyy-MM-dd"); } else if (step == 4) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date birthday = null; try { birthday = sdf.parse(in); g.setBirthday(birthday); System.out.println("请输入女神的[邮箱]"); } catch (ParseException e) { e.printStackTrace(); System.out.println("您输入的格式有误,请重新输入"); step = 2; } } else if (step == 5) { g.setEmail(in); System.out.println("请输入女神的[电话]"); } else if (step == 6) { g.setMobile(in); System.out.println("请输入更新人"); } else if (step == 7) { g.setUpdate_user(in); g.setIsdel(1); try { ga.edit(g); System.out.println("更新女神成功"); } catch (Exception e) { e.printStackTrace(); System.out.println("更新女神失败"); } } if (step == 7) { step = 0; } else { step++; } } else if (OPERATION_SEARCH.equals(in.toUpperCase()) || OPERATION_SEARCH.substring(0, 1).equals(in.toUpperCase()) || OPERATION_SEARCH.equals(cpu)) { cpu = OPERATION_SEARCH; List<Map<String, Object>> list = new ArrayList<Map<String,Object>>(); Map<String, Object> map = new HashMap<String, Object>(); if (step == 0) { System.out.println("请输入搜索条件"); step++; } else if (in.equals("user_name")) { System.out.println("请输入搜索条件的值"); map.put("name", "user_name"); map.put("rela", "="); String in2 = input.next(); map.put("value", "'"+in2+"'"); list.add(map); try { List<Goddess> g3 = ga.query(list); ga.show(g3.get(0)); } catch (Exception e) { e.printStackTrace(); } } else if (!in.equals("user_name")) { System.out.println("请输入搜索条件的值"); map.put("name", in); String in2 = input.next(); map.put("rela", "like"); map.put("value", in2); list.add(map); try { List<Goddess> g3 = ga.query(list); ga.show(g3.get(0)); } catch (Exception e) { e.printStackTrace(); } } } else { System.out.println("您输入的值为:" + in); } } }
这是自己敲得代码,还没修改。我对GoddessDao里面的方法做了一些调整。“GET”部分的代码不要看。
举报