谁有视图层完整的代码啊
想要View层完整的可执行代码
想要View层完整的可执行代码
2016-04-14
package com.View; 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.Action.StudentAction; import com.Entity.Student; 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"+ "[FQUERY/F:]查询学生信息(根据姓名、手机号...查询)\n"+ "[EXIT/E]:退出学生管理系统。\n"+ "[BREAK/B]:结束当前操作,返回主菜单。"; private static final String ACTION_MAIN = "MAIN"; private static final String ACTION_QUERY = "QUERY"; private static final String ACTION_GET = "GET"; private static final String ACTION_ADD = "ADD"; private static final String ACTION_UPDATE = "UPDATE"; private static final String ACTION_DELETE = "DELETE"; private static final String ACTION_FQUERY = "FQUERY"; private static final String ACTION_EXIT = "EXIT"; private static final String ACTION_BREAK = "BREAK"; private static Student stu1; public static void main(String[] args) { System.out.println(CONTEXT); Scanner input = new Scanner(System.in); Student stu = new Student(); String status = null;//状态 String name = null; String value = null; Integer step = 1; while (input.hasNext()) { String in = input.next(); if (ACTION_EXIT.equals(in.toUpperCase()) || ACTION_EXIT.substring(0, 1).equals(in.toUpperCase())) { System.out.println("退出学生管理系统。"); break; }else if(ACTION_MAIN.equals(in.toUpperCase()) || ACTION_MAIN.substring(0, 1).equals(in.toUpperCase())){ System.out.println(CONTEXT); continue; } else if(ACTION_BREAK.equals(in.toUpperCase()) || ACTION_BREAK.substring(0, 1).equals(in.toUpperCase())){ status = null; System.out.println("退出当前功能。"); continue; } else if(ACTION_DELETE.equals(in.toUpperCase()) || ACTION_DELETE.substring(0, 1).equals(in.toUpperCase()) || ACTION_DELETE.equals(status)){ //根据id删除学生信息 System.out.println("请输入要删除的学生编号:"); in = input.next(); StudentAction.Delete(Integer.parseInt(in)); System.out.println("学生信息删除成功!"); }else if(ACTION_FQUERY.equals(in.toUpperCase()) || ACTION_FQUERY.substring(0, 1).equals(in.toUpperCase()) || ACTION_FQUERY.equals(status)){ //根据特定条件查询学生信息 System.out.println("请选择要查询的字段:\n[name]姓名\n[mobile]手机号"); name = input.next(); if("name".equals(name)){ System.out.println("请输入要查询的姓名:"); value = input.next(); }else if("mobile".equals(name)){ System.out.println("请输入要查询的手机号:"); value = input.next(); } List<Map<String,Object>> params = new ArrayList<Map<String,Object>>(); Map<String,Object> map = new HashMap<String,Object>(); map.put("name", name); map.put("rela", "="); map.put("value", "'"+value+"'"); params.add(map); List<Student> stulist1 = StudentAction.FuzzyQuery(params); for (Student student : stulist1) { System.out.println(student.toString()); } if(stulist1.size()==0){ System.out.println("未查询到相应学生信息!"); } continue; }else if(ACTION_GET.equals(in.toUpperCase()) || ACTION_GET.substring(0, 1).equals(in.toUpperCase()) || ACTION_GET.equals(status)){ //根据id查询学生详细信息 System.out.println("请输入学生编号:"); in = input.next(); stu.setId(Integer.parseInt(in)); stu1 = StudentAction.QueryById(stu.getId()); System.out.println(stu1.toString()); continue; }else if (ACTION_UPDATE.equals(in.toUpperCase()) || ACTION_UPDATE.substring(0, 1).equals(in.toUpperCase()) || ACTION_UPDATE.equals(status)) { //更新学生信息 /* * stu1 = StudentAction.QueryById(stu.getId()); * if("null".equals(in)){ stu.setName(stu1.getName()); }else{ stu.setName(in); } * 根据输入的id查询学生信息,当输入的值为null时,将该学生原信息赋值。 * 达到输入null,不更新字段的效果。 */ status = ACTION_UPDATE; if(1==step){ System.out.println("请输入要更新的学生编号:"); System.out.println("编号:"); }else if(2==step){ stu.setId(Integer.parseInt(in)); stu1 = StudentAction.QueryById(stu.getId()); System.out.println("当前id:"+stu.getId()+"-"+stu1.toString()); System.out.println("姓名(如果不更新该字段,则输入null):"); }else if(3==step){ if("null".equals(in)){ stu.setName(stu1.getName()); }else{ stu.setName(in); } System.out.println("性别:"); }else if(4==step){ if("null".equals(in)){ stu.setSex(stu1.getSex()); }else{ stu.setSex(Integer.parseInt(in)); } System.out.println("年龄:"); }else if(5==step){ if("null".equals(in)){ stu.setAge(stu1.getAge()); }else{ stu.setAge(Integer.parseInt(in)); } System.out.println("出生日期"); }else if(6==step){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date birthday = null; try { if("null".equals(in)){ stu.setBirthday(stu1.getBirthday()); }else{ birthday = sdf.parse(in); stu.setBirthday(birthday); } System.out.println("手机号:"); } catch (ParseException e) { e.printStackTrace(); System.out.println("您输入的日期格式有误,请重新输入!"); step = 5; } }else if(7==step){ if("null".equals(in)){ stu.setMobile(stu1.getMobile()); }else{ stu.setMobile(in); } StudentAction.Update(stu); System.out.println("学生信息更新成功。"); status = null; } if (ACTION_UPDATE.equals(status)) { step++; } } else if (ACTION_QUERY.equals(in.toUpperCase()) || ACTION_QUERY.substring(0, 1).equals(in.toUpperCase()) || ACTION_QUERY.equals(status)) { // 查询学生信息 List<Student> stulist = StudentAction.Query(); for (Student student : stulist) { System.out.println(student.getId() + "-姓名:" + student.getName()); } continue; } else if (ACTION_ADD.equals(in.toUpperCase()) || ACTION_ADD.substring(0, 1).equals(in.toUpperCase()) || ACTION_ADD.equals(status)) { // 添加学生信息 status = ACTION_ADD; if (1 == step) { System.out.println("请输入学生姓名[name]:"); } else if (2 == step) { stu.setName(in); System.out.println("请输入学生性别[sex]:"); } else if (3 == step) { stu.setSex(Integer.valueOf(in)); System.out.println("请输入学生年龄[age]:"); } else if (4 == step) { stu.setAge(Integer.valueOf(in)); System.out.println("请输入学生生日[birthday-格式yyyy-MM-dd]:"); } else if (5 == step) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date birthday = null; try { birthday = sdf.parse(in); stu.setBirthday(birthday); System.out.println("请输入学生手机号码[mobile]:"); } catch (ParseException e) { e.printStackTrace(); System.out.println("您输入的日期格式有误,请重新输入!"); step = 4; } } else if (6 == step) { stu.setMobile(in); StudentAction.Add(stu); System.out.println("学生信息添加成功。"); status = null; } if (ACTION_ADD.equals(status)) { step++; } } } } }
package view; import java.sql.SQLException; import java.util.List; import java.util.Scanner; import control.*; import model.*; public class Test { public static Scanner in = new Scanner(System.in); private static Control test = new Control(); /** * 1.循环执行输入exit才退出 * 2.执行内容 * 增删改查数据表 * 3.细节展示 * @param args * @throws SQLException */ public static void main(String[] args) throws SQLException { //外层循环 System.out.println("***********************************"); System.out.println("欢迎来到禁区!"); System.out.println("***********************************"); System.out.println("【exit】\t退出"); System.out.println("【query】\t查询女神信息"); System.out.println("【get】\t查询女神详细信息"); System.out.println("【add】\t增加女神"); System.out.println("【delete】\t删除女神"); System.out.println("【clear】\t删除所有女神信息"); System.out.println("【edit】\t修改女神信息"); String select = "null"; //创建对象 Test it = new Test(); String[] s = {"query", "get", "add", "delete", "clear", "edit"}; do { System.out.println("***********************************"); if (select.equals(s[0])) { it.query(); } else if (select.equals(s[1])) { it.get(); } else if (select.equals(s[2])) { it.add(); } else if (select.equals(s[3])) { it.delete(); } else if (select.equals(s[4])) { it.clear(); } else if (select.equals(s[5])) { it.edit(); } else { } System.out.println("***********************************"); } while (!(select = in.next()).equals("exit")); System.out.println("退出!"); } public void delete() throws SQLException { System.out.println("请输入要删除女神的ID:"); int id = in.nextInt(); test.delete(id); System.out.println("删除成功!"); } public void clear() throws SQLException { test.deleteAll(); System.out.println("所有女神信息已清除!"); } public void get() throws SQLException { System.out.println("请输入要查询女神的编号:"); int id = in.nextInt(); Goddess g = test.getQuery(id); System.out.println("ID:" + g.getId() + "\nName:" + g.getName() + "\nAge:" + g.getAge() + "\nPhone:" + g.getPhone()); } public void query() throws SQLException { List<Goddess> gList = test.getQuery(); for (Goddess goddess : gList) { System.out.println("ID:" + goddess.getId() + "\tName:" + goddess.getName() ); } } public void add() throws SQLException { System.out.println("请输入要添加女神基本信息[ID][Name][Age][Phonenumber]:"); int id = in.nextInt(); String name = in.next(); int age = in.nextInt(); String number = in.next(); Goddess g = new Goddess(id, age, name, number); test.add(g); } public void edit() throws SQLException { System.out.println("请输入要修改女神的基本信息[ID][Name][Age][Phonenumber]:"); int id = in.nextInt(); String name = in.next(); int age = in.nextInt(); String number = in.next(); Goddess g = new Goddess(id, age, name, number); test.undates(id, g); System.out.println("修改成功!"); } }
package com.imooc.view;
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.imooc.action.GoddessAction;
import com.imooc.model.Goddess;
public class GoddessView {
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) throws Exception {
System.out.println(CONTEXT);
Scanner s=new Scanner(System.in);
Goddess goddess=new Goddess();
GoddessAction action=new GoddessAction();
String prenious=null;
Integer step=1;
while(s.hasNext()){
String in=s.next().toString();
if(OPERATION_EXIT.equals(in.toUpperCase())//退出功能
||OPERATION_EXIT.substring(0, 1).equals(in.toUpperCase())){
System.out.println("您已成功退出女神禁区,欢迎下次光临!");
break;
}else if(OPERATION_BREAK.equals(in.toUpperCase())//退出当前功能返回主菜单
||OPERATION_BREAK.substring(0, 1).equals(in.toUpperCase())){
System.out.println(CONTEXT);
continue;
}else if(OPERATION_MAIN.equals(in.toUpperCase())//返回主菜单
||OPERATION_MAIN.substring(0, 1).equals(in.toUpperCase())){
System.out.println(CONTEXT);
continue;
}else if(OPERATION_QUERY.equals(in.toUpperCase())//查询全部女神信息功能
||OPERATION_QUERY.substring(0, 1).equals(in.toUpperCase())
||OPERATION_QUERY.equals(prenious)){
prenious=OPERATION_QUERY;
List<Goddess> list=action.queryAllGoddess();
for(Goddess goddessList:list){
System.out.println(goddessList.toString());
}
}else if(OPERATION_GET.equals(in.toUpperCase())//根据ID查询女神的功能
||OPERATION_GET.substring(0, 1).equals(in.toUpperCase())
||OPERATION_GET.equals(prenious)){
prenious=OPERATION_GET;
if(1==step){
System.out.println("请输入女神的ID:");
}else if(2==step){
Goddess goddess01=action.queryById(Integer.valueOf(in));
System.out.println(goddess01.toString());
}
step++;
}else if(OPERATION_UPDATE.equals(in.toUpperCase())//更新女神信息功能
||OPERATION_UPDATE.substring(0, 1).equals(in.toUpperCase())
||OPERATION_UPDATE.equals(prenious)){
prenious=OPERATION_UPDATE;
if(1==step){
System.out.println("请输入要更新女神的ID:");
}else if(2==step){
goddess.setId(Integer.valueOf(in));
System.out.println("请输入更新后女神的[年龄]:");
}else if(3==step){
goddess.setAge(Integer.valueOf(in));
System.out.println("请输入更新后女神的[生日]:(格式如:yyyy-MM-dd)");
}else if(4==step){
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
Date birthday=format.parse(in);
goddess.setBirthday(birthday);
System.out.println("请输入更新后女神的[邮箱]:");
}else if(5==step){
goddess.setEmail(in);
System.out.println("请输入更新后女神的[电话]:");
}else if(6==step){
goddess.setMobile(in);
System.out.println("请输入更新后女神的[姓名]:");
}else if(7==step){
goddess.setUser_name(in);
action.edit(goddess);
System.out.println("信息更新成功");
}
step++;
}else if(OPERATION_DELETE.equals(in.toUpperCase())//删除女神信息功能
||OPERATION_DELETE.substring(0, 1).equals(in.toUpperCase())
||OPERATION_DELETE.equals(prenious)){
prenious=OPERATION_DELETE;
if(1==step){
System.out.println("请输入要删除女神的ID:");
}else if(2==step){
action.del(Integer.valueOf(in));
System.out.println("信息删除成功!");
}
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> map=new HashMap<String,Object>();
if(1==step){
System.out.println("输入要查询的参数:");
map.put("name", in);
}else if(2==step){
System.out.println("输入查询规则:");
map.put("rela", in);
}else if(3==step){
System.out.println("输入要查询的参数名:");
map.put("value", in);
}else if(4==step){
params.add(map);
List<Goddess> list=action.queryByParams(params);
for(Goddess g:list){
System.out.println(g.toString());
}
}
step++;
}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){
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 format=new SimpleDateFormat("yyyy-MM-dd");
Date birthday=format.parse(in);
goddess.setBirthday(birthday);
System.out.println("请输入女神的[邮箱]:");
}else if(5==step){
goddess.setEmail(in);
System.out.println("请输入女神的[电话]:");
}else if(6==step){
goddess.setMobile(in);
action.add(goddess);
}
step++;
}else{
System.out.println("你输入的值为:"+in);
}
}
s.close();
}
}
举报