//UserDaoImpl.javapublicclassUserDaoImplimplementsUserDao{private QueryRunner qr=newQueryRunner(DruidUtils.getDataSouce());@Overridepublic Boolean login(String username, String password){try{
String sql="select * from User where username = ? and password=?";
Object []params={username,password};
User user = qr.query(sql,newBeanHandler<User>(User.class),params);if(user!=null){returntrue;}}catch(SQLException e){
System.out.println("账号输入错误");}returnfalse;}}
// BookShopSystem.javapublicclassBookShopSystem{publicstaticvoidmain(String[] args)throws ParseException {
BookServiceImpl bookService =newBookServiceImpl();
UserServiceImpl userService =newUserServiceImpl();
CategoryServiceImpl categoryService =newCategoryServiceImpl();
Scanner input =newScanner(System.in);
System.out.println("welcome to bookshop");
System.out.println("please input your username");
String username = input.next();
System.out.println("please input your password");
String password = input.next();
Boolean flag = userService.login(username, password);
lable:if(flag){
System.out.println("登陆成功");while(true){
System.out.println("1.查询所有数据 2.根据id查询书籍 3.根据书名查询数据");
System.out.println("4.删除书籍(id) 5.更新书籍 6.添加书籍 7添加书籍类型,并添加书籍 8.离开");
System.out.println("please input your options");
Integer options = input.nextInt();switch(options){case1:
List<Book> bookList = bookService.findAll();for(Book book : bookList){
System.out.println(book.toString());}break;case2:
System.out.println("please input id");
Integer id = input.nextInt();
Book book = bookService.findById(id);
System.out.println(book.toString());break;case3:
System.out.println("please input the name of book");
String title = input.next();
List<Book> bookList1 = bookService.findByTitle(title);for(Book book5 : bookList1){
System.out.println(book5.toString());}break;case4:
System.out.println("please input the id of book");
Integer id1 = input.nextInt();
bookService.deleteById(id1);break;case5:
System.out.println("please input the id of the book");
Integer id2 = input.nextInt();
System.out.println("please input the title of the book");
input.nextLine();
String title2 = input.nextLine();
System.out.println("please input the author of the book");
String author2 = input.next();
System.out.println("please input the publicDate of the book");
String publicDate2 = input.next();
System.out.println("please input the publisher of the book");
String publisher2 = input.next();
System.out.println("please input the isbn of the book");
String isbn2 = input.next();
System.out.println("please input the price of the book");
BigDecimal price2 = input.nextBigDecimal();
System.out.println("please input the picture of the book");
String picture2 = input.next();
System.out.println("please input the cid of the book");
Integer cid2 = input.nextInt();
SimpleDateFormat sdf =newSimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(publicDate2);
Book book2 =newBook(id2, title2, author2, date, publisher2, isbn2, price2, picture2, cid2);
bookService.update(book2);
System.out.println("更新成功");break;case6:
System.out.println("please input the title of the book");
input.nextLine();
String title3 = input.nextLine();
System.out.println("please input the author of the book");
String author3 = input.next();
System.out.println("please input the publicDate of the book");
String publicDate3 = input.next();
System.out.println("please input the publisher of the book");
String publisher3 = input.next();
System.out.println("please input the isbn of the book");
String isbn3 = input.next();
System.out.println("please input the price of the book");
BigDecimal price3 = input.nextBigDecimal();
System.out.println("please input the picture of the book");
String picture3 = input.next();
System.out.println("please input the cid of the book");
Integer cid3 = input.nextInt();
SimpleDateFormat sdf1 =newSimpleDateFormat("yyyy-MM-dd");
Date date1 = sdf1.parse(publicDate3);
Book book3 =newBook(null, title3, author3, date1, publisher3, isbn3, price3, picture3, cid3);
bookService.insert(book3);
System.out.println("插入成功");break;case7:try{
DruidUtils.startTransation();
System.out.println("please input cname");
String cname = input.next();
Category category=newCategory(null,cname);
categoryService.insert(category);
Category category1 = categoryService.findByTitle(cname);
System.out.println("please input the title of the book");
input.nextLine();
String title4 = input.nextLine();
System.out.println("please input the author of the book");
String author4 = input.next();
System.out.println("please input the publicDate of the book");
String publicDate4 = input.next();
System.out.println("please input the publisher of the book");
String publisher4 = input.next();
System.out.println("please input the isbn of the book");
String isbn4 = input.next();
System.out.println("please input the price of the book");
BigDecimal price4 = input.nextBigDecimal();
System.out.println("please input the picture of the book");
String picture4 = input.next();
SimpleDateFormat sdf2 =newSimpleDateFormat("yyyy-MM-dd");
Date date2 = sdf2.parse(publicDate4);
Book book4 =newBook(0, title4, author4, date2, publisher4, isbn4, price4, picture4, category1.getCid());
bookService.insert(book4);
System.out.println("插入成功");
DruidUtils.commit();}catch(Exception e){
System.out.println("失败了");
e.printStackTrace();
DruidUtils.rollback();}finally{
DruidUtils.close();}break;case8:break lable;default:
System.out.println("输入错误");break;}}}else{
System.out.println("登陆失败");}}}