View层代码问题,急求解答
下面是我写的view代码,QUERYBYNAME根据姓名查看员工信息和 SEARCH查询员工信息(根据姓名、科室)都无法达到预期。 QUERYBYNAME在输入姓名后,程序无任何输出。SEARCH方法只根据第二个条件,科室来查找。求解答。 public class View {
public static final String CONTEXT="欢迎来到支撑网测评中心,下面是功能列表: \n"+
"[MAIN/M]:主菜单\n"+
"[QUERY/Q]:查看全部员工信息\n"+
"[QUERYBYNAME/QU]:根据姓名查看员工信息\n"+
"[ADD/A]:添加员工信息\n"+
"[UPDATE/U]:更新员工信息\n"+
"[DELEIE/D]:删除员工信息\n"+
"[SEARCH/S]:查询员工信息(根据姓名、科室)\n"+
"[EXIT/E]:退出测评中心\n"+
"[BREAK/B]:退出当前功能,返回主菜单";
public static final String OPERATION_MAIN="MAIN";
public static final String OPERATION_QUERY="QUERY";
public static final String OPERATION_QUERYBYNAME="QUERYBYNAME";
public static final String OPERATION_QUERYBYKESHI="QUERYBYKESHI";
public static final String OPERATION_ADD="ADD";
public static final String OPERATION_UPDATE="UPDATE";
public static final String OPERATION_DELETE="DELETE";
public static final String OPERATION_SEARCH="SEARCH";
public static final String OPERATION_EXIT="EXIT";
public static final String OPERATION_BREAK="BREAK";
public static void main(String[] args) {
System.out.println(CONTEXT);
//保持程序持续运行
Scanner scan=new Scanner(System.in);
User user=new User();
UserAction action=new UserAction();
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<User> list=action.query();
for (User u : list) {
System.out.println("ID:"+u.getId()+", 姓名:"+u.getName()+", 性别:"+u.getSex()+", 科室:"+u.getKeshi()
+", 集团号:"+u.getJituanhao()+", 职位:"+u.getZhiwei()+";");
}
} catch (Exception e) {
e.printStackTrace();
}
}else if(OPERATION_QUERYBYNAME.equals(in.toUpperCase())||OPERATION_QUERYBYNAME.substring(0, 2).equals
(in.toUpperCase())){
prenious=OPERATION_QUERYBYNAME;
if(1==step){
System.out.println("请输入要查询员工【姓名】:");
}else if(2==step){
try {
System.out.println("22");
List<User> list=action.queryByName(in.toString());
for(int i=0;i<list.size();i++){
System.out.println(list.get(i).toString());
}
/* for (User u : list) {
System.out.println("ID:"+u.getId()+", 姓名:"+u.getName()+", 性别:"+u.getSex()+", 科室:"+u.getKeshi()
+", 集团号:"+u.getJituanhao()+", 职位:"+u.getZhiwei()+";");
} */
} catch (Exception e) {
e.printStackTrace();
System.out.println("该员工信息不存在");
}
}
if(OPERATION_QUERYBYNAME.equals(prenious)){
System.out.println(step);
step++;
}
}else if(OPERATION_SEARCH.equals(in.toUpperCase())||OPERATION_SEARCH.substring(0, 1).equals
(in.toUpperCase())||OPERATION_SEARCH.equals(prenious)){
prenious=OPERATION_SEARCH;
List<Map<String, Object>> params=new ArrayList<Map<String, Object>>();
Map<String, Object> param1=new HashMap<String, Object>();
if(1==step){
System.out.println("请输入要查询员工【姓名】:");
}
else if(2==step){
param1.put("name","name" );
param1.put("rela", "like");
param1.put("value", "'%"+in+"%'");
params.add(param1);
System.out.println("请输入要查询员工【科室】:");
}
else if(3==step){
System.out.println(step);
Map<String, Object> param2=new HashMap<String, Object>();
param2.put("name","keshi" );
param2.put("rela", "like");
param2.put("value", "'%"+in+"%'");
params.add(param2);
List<User> list;
try {
list = action.query(params);
for (User u : list) {
System.out.println("ID:"+u.getId()+", 姓名:"+u.getName()+", 性别:"+u.getSex()+", 科室:"+u.getKeshi()
+", 集团号:"+u.getJituanhao()+", 职位:"+u.getZhiwei()+";");
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("无符号条件的员工信息!");
}
}
if(OPERATION_SEARCH.equals(prenious)){
System.out.println(step);
step++;
}
/* for(int i=0;i<list.size();i++){
System.out.println(list.get(i).toString());
} */
}else if(OPERATION_ADD.equals(in.toUpperCase())||OPERATION_ADD.substring(0, 1).equals
(in.toUpperCase())||OPERATION_ADD.equals(prenious)){
prenious=OPERATION_ADD;
if(1==step){
System.out.println("请输入员工【姓名】:");
}
else if(2==step){
user.setName(in);
System.out.println("请输入员工【性别】:");
}
else if(3==step){
user.setSex(in);
System.out.println("请输入员工【科室】:");
}
else if(4==step){
user.setKeshi(in);
System.out.println("请输入员工【集团号】:");
}
else if(5==step){
user.setJituanhao(Integer.valueOf(in));
System.out.println("请输入员工【职位】,若是普通员工,写所属小组:");
}
else if(6==step){
user.setZhiwei(in);
try {
action.add(user);
System.out.println("新增员工信息成功!");
} catch (Exception e) {
e.printStackTrace();
System.out.println("新增员工信息失败!");
}
}
if(OPERATION_ADD.equals(prenious)){
step++;
}
}
}
}
}