• 2020-12-17日报博客-周四


    1. 学到的东西:

    案例:图书管理系统的重新实现

    package service;
    
    import domain.Book;
    import domain.PageBean;
    import domain.User;
    
    import java.util.List;
    import java.util.Map;
    
    /**
     * 用户管理的业务接口
     */
    public interface BookService {
    
    
        public List<Book> findAll();
    
    
        void addBook(Book book);
    
        /**
         * 根据id删除User
         * @param id
         */
        void deleteBook(String id);
    
        /**
         * 根据id查询
         * @param id
         * @return
         */
        Book findBookById(String id);
    
        /**
         * 修改用户信息
         * @param book
         */
        void updateBook(Book book);
    
        /**
         * 批量删除用户
         * @param ids
         */
        void delSelectedBook(String[] ids);
    
        /**
         * 分页条件查询
         * @param currentPage
         * @param rows
         * @param condition
         * @return
         */
        PageBean<Book> findBookByPage(String currentPage, String rows, Map<String, String[]> condition);
    }
    
    
    package service;
    
    import domain.Book;
    import domain.BorrowInfo;
    import domain.PageBean;
    
    import java.util.List;
    import java.util.Map;
    
    /**
     * 用户管理的业务接口
     */
    public interface BorrowInfoService {
    
    
        public List<BorrowInfo> findAll();
    
    
        void addBorrowInfo(BorrowInfo borrowInfo);
    
        /**
         * 根据id删除User
         * @param id
         */
        void deleteBorrowInfo(String id);
    
        /**
         * 根据id查询
         * @param id
         * @return
         */
        BorrowInfo findBorrowInfoById(String id);
    
        /**
         * 修改用户信息
         * @param borrowInfo
         */
    //    void updateBorrowInfo(BorrowInfo borrowInfo);
    
        /**
         * 批量删除用户
         * @param ids
         */
        void delSelectedBorrowInfo(String[] ids);
    
        /**
         * 分页条件查询
         * @param currentPage
         * @param rows
         * @param condition
         * @return
         */
        PageBean<BorrowInfo> findBorrowInfoByPage(String currentPage, String rows, Map<String, String[]> condition);
    }
    
    
    package service;
    
    import domain.PageBean;
    import domain.User;
    
    import java.util.List;
    import java.util.Map;
    
    /**
     * 用户管理的业务接口
     */
    public interface UserService {
    
        /**
         * 查询所有用户信息
         * @return
         */
        public List<User> findAll();
    
        /**UserService
         * 登录方法
         * @param user
         * @return
         */
        User login(User user);
    
        /**
         * 保存User
         * @param user
         */
        void addUser(User user);
    
        /**
         * 根据id删除User
         * @param id
         */
        void deleteUser(String id);
    
        /**
         * 根据id查询
         * @param id
         * @return
         */
        User findUserById(String id);
    
        /**
         * 修改用户信息
         * @param user
         */
        void updateUser(User user);
    
        /**
         * 批量删除用户
         * @param ids
         */
        void delSelectedUser(String[] ids);
    
        /**
         * 分页条件查询
         * @param currentPage
         * @param rows
         * @param condition
         * @return
         */
        PageBean<User> findUserByPage(String currentPage, String rows, Map<String, String[]> condition);
    }
    
    
    package service.impl;
    
    import dao.BookDao;
    import dao.UserDao;
    import dao.impl.BookDaoImpl;
    import dao.impl.UserDaoImpl;
    import domain.Book;
    import domain.PageBean;
    import domain.User;
    import service.BookService;
    import service.UserService;
    
    import java.util.List;
    import java.util.Map;
    
    public class BookServiceImpl implements BookService {
        private BookDao dao = new BookDaoImpl();
    
        @Override
        public List<Book> findAll() {
            //调用Dao完成查询
            return dao.findAll();
        }
    
    
        @Override
        public void addBook(Book book) {
            dao.add(book);
        }
    
        @Override
        public void deleteBook(String id) {
            dao.delete(Integer.parseInt(id));
        }
    
        @Override
        public Book findBookById(String id) {
            return dao.findById(Integer.parseInt(id));
        }
    
        @Override
        public void updateBook(Book book) {
            dao.update(book);
        }
    
        @Override
        public void delSelectedBook(String[] ids) {
            if(ids != null && ids.length > 0){
                //1.遍历数组
                for (String id : ids) {
                    //2.调用dao删除
                    dao.delete(Integer.parseInt(id));
                }
            }
    
        }
    
        @Override
        public PageBean<Book> findBookByPage(String _currentPage, String _rows, Map<String, String[]> condition) {
    
            int currentPage = Integer.parseInt(_currentPage);
            int rows = Integer.parseInt(_rows);
    
            if(currentPage <=0) {
                currentPage = 1;
            }
            //1.创建空的PageBean对象
            PageBean<Book> pb = new PageBean<Book>();
            //2.设置参数
            pb.setCurrentPage(currentPage);
            pb.setRows(rows);
    
            //3.调用dao查询总记录数
            int totalCount = dao.findTotalCount(condition);
            pb.setTotalCount(totalCount);
            //4.调用dao查询List集合
            //计算开始的记录索引
            int start = (currentPage - 1) * rows;
            List<Book> list = dao.findByPage(start,rows,condition);
            pb.setList(list);
    
            //5.计算总页码
            int totalPage = (totalCount % rows)  == 0 ? totalCount/rows : (totalCount/rows) + 1;
            pb.setTotalPage(totalPage);
    
            return pb;
        }
    }
    
    
    package service.impl;
    
    import dao.BookDao;
    import dao.BorrowInfoDao;
    import dao.impl.BookDaoImpl;
    import dao.impl.BorrowInfoDaoImpl;
    import domain.Book;
    import domain.BorrowInfo;
    import domain.PageBean;
    import service.BookService;
    import service.BorrowInfoService;
    
    import java.util.List;
    import java.util.Map;
    
    public class BorrowInfoServiceImpl implements BorrowInfoService {
        private BorrowInfoDao dao = new BorrowInfoDaoImpl();
    
        @Override
        public List<BorrowInfo> findAll() {
            //调用Dao完成查询
            return dao.findAll();
        }
    
    
        @Override
        public void addBorrowInfo(BorrowInfo borrowInfo) {
            dao.add(borrowInfo);
        }
    
        @Override
        public void deleteBorrowInfo(String id) {
            dao.delete(id);
        }
    
        @Override
        public BorrowInfo findBorrowInfoById(String id) {
            return dao.findById(Integer.parseInt(id));
        }
    
        @Override
        public void delSelectedBorrowInfo(String[] ids) {
            if(ids != null && ids.length > 0){
                //1.遍历数组
                for (String id : ids) {
                    //2.调用dao删除
                    dao.delete(id);
                }
            }
    
        }
    
        @Override
        public PageBean<BorrowInfo> findBorrowInfoByPage(String _currentPage, String _rows, Map<String, String[]> condition) {
    
            int currentPage = Integer.parseInt(_currentPage);
            int rows = Integer.parseInt(_rows);
    
            if(currentPage <=0) {
                currentPage = 1;
            }
            //1.创建空的PageBean对象
            PageBean<BorrowInfo> pb = new PageBean<BorrowInfo>();
            //2.设置参数
            pb.setCurrentPage(currentPage);
            pb.setRows(rows);
    
            //3.调用dao查询总记录数
            int totalCount = dao.findTotalCount(condition);
            pb.setTotalCount(totalCount);
            //4.调用dao查询List集合
            //计算开始的记录索引
            int start = (currentPage - 1) * rows;
            List<BorrowInfo> list = dao.findByPage(start,rows,condition);
            pb.setList(list);
    
            //5.计算总页码
            int totalPage = (totalCount % rows)  == 0 ? totalCount/rows : (totalCount/rows) + 1;
            pb.setTotalPage(totalPage);
    
            return pb;
        }
    }
    
    
    package service.impl;
    
    import dao.BookDao;
    import dao.UserDao;
    import dao.impl.BookDaoImpl;
    import dao.impl.UserDaoImpl;
    import domain.Book;
    import domain.PageBean;
    import domain.User;
    import service.BookService;
    import service.UserService;
    
    import java.util.List;
    import java.util.Map;
    
    public class BookServiceImpl implements BookService {
        private BookDao dao = new BookDaoImpl();
    
        @Override
        public List<Book> findAll() {
            //调用Dao完成查询
            return dao.findAll();
        }
    
    
        @Override
        public void addBook(Book book) {
            dao.add(book);
        }
    
        @Override
        public void deleteBook(String id) {
            dao.delete(Integer.parseInt(id));
        }
    
        @Override
        public Book findBookById(String id) {
            return dao.findById(Integer.parseInt(id));
        }
    
        @Override
        public void updateBook(Book book) {
            dao.update(book);
        }
    
        @Override
        public void delSelectedBook(String[] ids) {
            if(ids != null && ids.length > 0){
                //1.遍历数组
                for (String id : ids) {
                    //2.调用dao删除
                    dao.delete(Integer.parseInt(id));
                }
            }
    
        }
    
        @Override
        public PageBean<Book> findBookByPage(String _currentPage, String _rows, Map<String, String[]> condition) {
    
            int currentPage = Integer.parseInt(_currentPage);
            int rows = Integer.parseInt(_rows);
    
            if(currentPage <=0) {
                currentPage = 1;
            }
            //1.创建空的PageBean对象
            PageBean<Book> pb = new PageBean<Book>();
            //2.设置参数
            pb.setCurrentPage(currentPage);
            pb.setRows(rows);
    
            //3.调用dao查询总记录数
            int totalCount = dao.findTotalCount(condition);
            pb.setTotalCount(totalCount);
            //4.调用dao查询List集合
            //计算开始的记录索引
            int start = (currentPage - 1) * rows;
            List<Book> list = dao.findByPage(start,rows,condition);
            pb.setList(list);
    
            //5.计算总页码
            int totalPage = (totalCount % rows)  == 0 ? totalCount/rows : (totalCount/rows) + 1;
            pb.setTotalPage(totalPage);
    
            return pb;
        }
    }
    
    

    2. 遇到的问题:

    3. 明日计划:继续完成图书管理系统

  • 相关阅读:
    Path Sum
    Restore IP Addresses
    Subsets II
    N-Queens
    Subsets
    Combination Sum II
    Combination Sum
    Sudoku Solver
    Valid Sudoku
    【贪心】【Uva11292】 勇者斗恶龙
  • 原文地址:https://www.cnblogs.com/gongyunlong-blogs/p/14161601.html
Copyright © 2020-2023  润新知