⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookshelftest.java

📁 在线读书交流平台
💻 JAVA
字号:
package com.olr.test.DAOTest;

import java.util.Set;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.olr.beans.Book;
import com.olr.beans.User;
import com.olr.dao.BookDAO;
import com.olr.dao.UserDAO;

public class BookshelfTest {
	private UserDAO userdao;
	private BookDAO bookdao;
	
	public BookshelfTest(){
		ApplicationContext ctx=new FileSystemXmlApplicationContext(
				"WebRoot/WEB-INF/applicationContext.xml"		
				);
				
				userdao=(UserDAO)ctx.getBean("UserDAO");
				bookdao=(BookDAO)ctx.getBean("BookDAO");
	}
	
	public static void main(String args[]){
		BookshelfTest test=new BookshelfTest();
		test.addToShelf(8, 3);
		test.addToShelf(8, 1);
		test.userdao.removeFormShelf(8, 4);
		//test.removeFormShelf(8, 2);
		}
	
	public void addToShelf(int userId,int bookId){
	    User user=userdao.getUserById(userId);
	    Book book=bookdao.getBookById(bookId);
	    user.getMyBooks().add(book);
	    book.getSubscribers().add(user);
	    userdao.updateUser(user);
	    bookdao.updateBook(book);
	    
	}
	
	
	
	public void removeFormShelf(int userId,int bookId){
	    User user=userdao.getUserById(userId);
	    Book book=bookdao.getBookById(bookId);
	    //Set<Book> tempBookSet=user.getMyBooks();
	    //Set<User> tempUserSet=book.getSubscribers();
	    user.getMyBooks().remove(book);
	    book.getSubscribers().remove(user);
	    //user.getMyBooks().clear();
	    //book.getSubscribers().clear();
	    //user.setMyBooks(tempBookSet);
       // book.setSubscribers(tempUserSet);
	    userdao.updateUser(user);
	    bookdao.updateBook(book);
	    
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -