求大佬看看我这是什么错误

来源:2-9 JDBC实战---搭建视图层(下)

奔丶

2019-11-27 16:52

package com.imooc.view;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

import com.imooc.action.GoddessAction;
import com.imooc.model.Goddess;

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]:退出当前菜单返回主菜单\n";

 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 scan = new Scanner(System.in);
  Goddess goddess = new Goddess();
  GoddessAction action = new GoddessAction();
  String prenious = null;
  Integer step = 1;

  while (scan.hasNext()) {
   String in = scan.next().toString();
   if (OPERATION_EXIT.equals(in.toUpperCase()) || OPERATION_EXIT.substring(0, 1).equals(in.toUpperCase())) {
    System.out.println("您已成功退出女神禁区。");
    break;
   } else if (OPERATION_QUERY.equals(in.toUpperCase()) || OPERATION_QUERY.substring(0, 1).equals(in.toUpperCase())) {
    try {
     List<Goddess> list = action.query();
     for (Goddess go : list) {
      System.out.println(go.getId()+",姓名:"+go.getUser_name());
     }
    } catch (Exception e) {
 
     e.printStackTrace();
    }
   }else if (OPERATION_ADD.equals(in.toUpperCase()) || OPERATION_ADD.substring(0, 1).equals(in.toUpperCase())
     || OPERATION_ADD.equals(prenious)) {
    // 新增女神
    if (1 == step) {
     System.out.println("请输入女神的[姓名]:");
    
    } else if (2 == step) {
     goddess.setUser_name(in);
     System.out.println("请输入女神的[年龄]:");
   
    } else if (3 == step) {
     goddess.setAge(Integer.valueOf(in));
     System.out.println("请输入女神的[生日]:格式如:yyyy-MM-dd");
     
    } else if (4 == step) {
     SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
     Date birthday = null;
     try {
      birthday = sf.parse(in);
      goddess.setBirthday(birthday);
      System.out.println("请输入女神的[邮箱]:");
     
     } catch (ParseException e) {
      e.printStackTrace();
      System.out.println("您输入的格式有误,请输入");
      step = 3;
     }
    } else if (step == 5) {
     goddess.setEmail(in);
     System.out.println("请输入女神的[手机号]:");
   
    } else if (step == 6) {
     goddess.setMobile(in);
     try {
      action.add(goddess);
      System.out.println("新增女神成功");
     } catch (Exception e) {
      e.printStackTrace();
      System.out.println("新增女神失败");
     }
    }
    if (OPERATION_ADD.equals(prenious)) {
     step++;
    }
    prenious = OPERATION_ADD;
   } else {

   }
  }

 }

}

http://img2.mukewang.com/5dde39220001bf8a08850821.jpg

我这是啥错误,按老师步骤来做的

写回答 关注

2回答

  • 慕粉2043568
    2019-12-04 22:40:10

    不是这样的哦

  • qq_慕桂英8246316
    2019-11-29 20:48:57

    感觉是倒数第六行的那个  prenious = OPERATION_ADD;引起的,删掉吧,老师的代码里好像没这一行

JDBC之 “ 对岸的女孩看过来”

一起领略JDBC的奥秘,为进一步学习集成框架打下良好的基础

99324 学习 · 856 问题

查看课程

相似问题