Java---题库管理系统项目中的Dao类

简介: Java---题库管理系统项目中的Dao类

说明

在该项目中entity建了四个实体分别是

1.Collection实体

2.User实体

3.Note实体

4.Qestions实体

Dao包只用了缓冲流与文件进行交互

代码

接口

// ICollectionDao
import studio.lyl.questionbankmanagementsystem.entity.Collection;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 17:32
 */
public interface ICollectionDao {
    /**
     * 添加到收藏
     * @param collection
     * @return boolean
     */
    boolean insetCollection(Collection collection);
    /**
     *根据用户id删除收藏夹
     * @param id
     * @return boolean
     */
    boolean deleteCollection(Integer id) throws Exception;
    /**
     * 根据用户id更改收藏
     * @param id
     * @param collection
     * @return
     */
    boolean updateCollection(Integer id,Collection collection) throws Exception;
    /**
     * 根据用户id查看收藏夹
     * @param id
     * @return List
     */
    List<Collection> selectCollectionById(Integer id) throws Exception;
    /**
     *查看所有的收藏
     * @return List
     */
    List<Collection> selectCollection() throws Exception;
}
// INoteDao
import studio.lyl.questionbankmanagementsystem.entity.Note;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 18:13
 */
public interface INoteDao {
    /**
     * 增加笔记
     * @param note
     * @return boolean
     */
    boolean insetNote(Note note) throws Exception;
    /**
     * 根据用户id删除笔记
     * @param id
     * @return boolean
     */
    boolean deleteNote(Integer id) throws Exception;
    /**
     * 根据用户id更改笔记
     * @param id
     * @param note
     * @return
     */
    boolean updateNote(Integer id,Note note) throws Exception;
    /**
     * 根据用户id查看笔记
     * @param id
     * @return
     */
    List<Note> selectNoteById(Integer id) throws Exception;
    /**
     * 查看所有的笔记
     * @return
     */
    List<Note> selectNote() throws Exception;
}
// IQuestionDao
import studio.lyl.questionbankmanagementsystem.entity.Questions;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 17:15
 */
public interface IQuestionDao{
    /**
     * 增加题目
     * @param questions
     * @return boolean
     */
    boolean insetQuestion(Questions questions) throws Exception;
    /**
     * 根据序号删除题目
     * @param sign
     * @param type
     * @return boolean
     */
    boolean deleteQuestion(int sign,String type) throws Exception;
    /**
     * 根据序号删除题目
     * @param sign
     * @param questions
     * @param type
     * @return
     */
    boolean updateQuestion(int sign ,String type ,Questions questions) throws Exception;
    /**
     * 根据序号查看题目
     * @param sign
     * @param type
     * @return String
     */
    List<Questions> selectQuestion(int sign, String type) throws Exception;
    /**
     * 查看一个类型里所有的题目
     * @param type
     * @return List
     * @throws Exception
     */
    List<Questions> selectQuestions(String type) throws Exception;
}
// IUserDao
import studio.lyl.questionbankmanagementsystem.entity.User;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 16:23
 */
public interface IUserDao {
    /**
     * 创建用户
     * @param user
     * @return boolean
     */
    boolean insertUser(User user) throws Exception;
    /**
     * 根据id删除用户
     * @param id
     * @return boolean
     */
    boolean deleteUserById(Integer id) throws  Exception;
    /**
     * 修改用户信息
     * @param id
     * @return boolean
     */
    boolean updateUser(Integer id,User user) throws Exception;
    /**
     * 根据id查看用户信息
     * @param id
     * @return List
     */
    List<User> selectUserById(Integer id) throws Exception;
    /**
     * 查看所有用户信息
     * @return
     * @throws Exception
     */
    List<User> selectUser() throws Exception;
}

实现

// CollectionDaoImpl implements ICollectionDao
import studio.lyl.questionbankmanagementsystem.dao.ICollectionDao;
import studio.lyl.questionbankmanagementsystem.entity.Collection;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/7 19:36
 */
public class CollectionDaoImpl implements ICollectionDao {
    @Override
    public boolean insetCollection(Collection collection) {
        try {
            BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Collections.txt",true));
            bufferedWriter.write( collection.getTime()+","+collection.getId()+"," + collection.getUserName() + ","+ collection.getCount()+"," + collection.getSign());
            bufferedWriter.newLine();
            bufferedWriter.flush();
            bufferedWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
    @Override
    public boolean deleteCollection(Integer id) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Collections.txt"));
        List<Collection> collectionList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Collection collection=new Collection(strings[0],Integer.parseInt(strings[1]),strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]));
            collectionList.add(collection);
        }
        for (int i = 0; i < collectionList.size(); i++) {
            Collection collection = collectionList.get(i);
            if (collection.getId().equals(id)) {
                collectionList.remove(i);
            }
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Collections.txt"));
        for (int j = 0; j < collectionList.size(); j++) {
            Collection collection=collectionList.get(j);
            String returnFile=String.format("%s,%s,%s,%s,%s",collection.getTime(),collection.getId(),collection.getUserName(),collection.getCount(),collection.getSign());
            bufferedWriter.write(returnFile);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }
        bufferedReader.close();
        bufferedWriter.close();
        return false;
    }
    @Override
    public boolean updateCollection(Integer id, Collection collection) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Collections.txt"));
        List<Collection> collectionList=new ArrayList<>();
        String s=null;
        while((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Collection returnCollection = new Collection(strings[0],Integer.parseInt(strings[1]),strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]));
            collectionList.add(returnCollection);
        }
        for (int i = 0; i < collectionList.size(); i++) {
            Collection returnCollection=collectionList.get(i);
            if(returnCollection.getId().equals(id)){
                collectionList.set(i,collection);
            }
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Collections.txt"));
        for (int i = 0; i < collectionList.size(); i++) {
            Collection returnCollection = collectionList.get(i);
            String returnString = String.format("%s,%s,%s,%s,%s",returnCollection.getTime(),returnCollection.getId(),returnCollection.getUserName(),returnCollection.getCount(),returnCollection.getSign());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }
        bufferedReader.close();
        bufferedWriter.close();
        return false;
    }
    @Override
    public List<Collection> selectCollectionById(Integer id) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Collections.txt"));
        List<Collection> collectionList=new ArrayList<>();
        String s=null;
        while((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Collection returnCollection = new Collection(strings[0],Integer.parseInt(strings[1]),strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]));
            collectionList.add(returnCollection);
        }
        for (int i = 0; i < collectionList.size(); i++) {
            Collection collection=collectionList.get(i);
            if(collection.getId().equals(id)){
                System.out.println(collection.toString());
            }
        }
        return null;
    }
    @Override
    public List<Collection> selectCollection() throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Collections.txt"));
        List<Collection> collectionList=new ArrayList<>();
        String s=null;
        while((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Collection returnCollection = new Collection(strings[0],Integer.parseInt(strings[1]),strings[2],Integer.parseInt(strings[3]),Integer.parseInt(strings[4]));
            collectionList.add(returnCollection);
        }
        for (int i = 0; i < collectionList.size(); i++) {
            Collection collection=collectionList.get(i);
            System.out.println(collection.toString());
        }
        return null;
    }
}
// NoteDaoImpl implements INoteDao
import studio.lyl.questionbankmanagementsystem.dao.INoteDao;
import studio.lyl.questionbankmanagementsystem.entity.Note;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/8 8:37
 */
public class NoteDaoImpl implements INoteDao {
    @Override
    public boolean insetNote(Note note) throws Exception{
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Note.txt",true));
        bufferedWriter.write(note.getMaster()+","+note.getId()+","+note.getCount()+","+note.getSign()+","+note.getContent());
        bufferedWriter.newLine();
        bufferedWriter.flush();
        bufferedWriter.close();
        return false;
    }
    @Override
    public boolean deleteNote(Integer id) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
        List<Note> noteList=new ArrayList<>();
        String s;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Note note=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
            System.out.println(note);
            noteList.add(note);
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Note.txt"));
        for (int i = 0; i < noteList.size(); i++) {
            Note note=noteList.get(i);
            if(note.getId().equals(id)){
                noteList.remove(i);
            }
        }
        for (int i = 0; i < noteList.size(); i++) {
            Note note=noteList.get(i);
            String returnString=String.format("%s,%s,%s,%s,%s",note.getMaster(),note.getId(),note.getCount(),note.getSign(),note.getContent());
            bufferedWriter.write(returnString);
        }
        bufferedReader.close();
        bufferedWriter.flush();
        bufferedWriter.close();
        return false;
    }
    @Override
    public boolean updateNote(Integer id, Note note) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
        List<Note> noteList=new ArrayList<>();
        String s;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Note noteGet=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
            System.out.println(noteGet);
            noteList.add(noteGet);
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\Note.txt"));
        for (int i = 0; i < noteList.size(); i++) {
            Note noteSet=noteList.get(i);
            if(noteSet.getId().equals(id)) {
                noteList.add(note.getSign(), note);
            }
        }
        for (int i = 0; i < noteList.size(); i++) {
            Note returnNote=noteList.get(i);
            String returnString=String.format("%s,%s,%s,%s,%s",returnNote.getMaster(),returnNote.getId(),returnNote.getCount(),returnNote.getSign(),returnNote.getContent());
            bufferedWriter.write(returnString);
        }
        bufferedReader.close();
        bufferedWriter.flush();
        bufferedWriter.close();
        return false;
    }
    @Override
    public List<Note> selectNoteById(Integer id) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
        List<Note> noteList=new ArrayList<>();
        String s;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Note note=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
            noteList.add(note);
        }
        for (int i = 0; i < noteList.size(); i++) {
            Note note=noteList.get(i);
            if(note.getId().equals(id)){
                System.out.println(note);
            }
        }
        bufferedReader.close();
        return null;
    }
    @Override
    public List<Note> selectNote() throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\Note.txt"));
        List<Note> noteList=new ArrayList<>();
        String s;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Note note=new Note(strings[0],Integer.parseInt(strings[1]),Integer.parseInt(strings[2]),Integer.parseInt(strings[3]),strings[4]);
            noteList.add(note);
        }
        for (int i = 0; i < noteList.size(); i++) {
            Note note=noteList.get(i);
                System.out.println(note);
        }
        return null;
    }
}
// QuestionDaoImpl implements IQuestionDao
import studio.lyl.questionbankmanagementsystem.dao.IQuestionDao;
import studio.lyl.questionbankmanagementsystem.entity.Questions;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/8 20:18
 */
public class QuestionDaoImpl implements IQuestionDao {
    @Override
    public boolean insetQuestion(Questions questions) throws Exception{
    //这里不想把路径写死就做了如下处理
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+questions.getType()+".txt",true));
        bufferedWriter.write(questions.getContent()+","+questions.getType()+","+questions.getSign()+","+questions.getComplexity()+","+questions.getAnswer());
        bufferedWriter.newLine();
        bufferedWriter.flush();
        bufferedWriter.close();
        return false;
    }
    @Override
    public boolean deleteQuestion(int sign,String type) throws Exception {
        BufferedReader bufferedReader=new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
        List<Questions> questionsList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Questions questions=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
            questionsList.add(questions);
        }
        for (int i = 0; i < questionsList.size(); i++) {
            Questions questions=questionsList.get(i);
            if(questions.getSign()==sign){
                questionsList.remove(i);
            }
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
        for (int i = 0; i < questionsList.size(); i++) {
            Questions questions=questionsList.get(i);
            String returnString=String.format("%s,%s,%s,%s,%s",questions.getContent(),questions.getType(),questions.getSign(),questions.getComplexity(),questions.getAnswer());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
        }
        bufferedReader.close();
        bufferedWriter.flush();
        bufferedWriter.close();
        return false;
    }
    @Override
    public boolean updateQuestion(int sign,String type,Questions questions) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
        List<Questions> questionsList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Questions questionsSet=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
            questionsList.add(questionsSet);
        }
        for (int i = 0; i < questionsList.size(); i++) {
            Questions questionsSet=questionsList.get(i);
            if(questionsSet.getSign()==sign){
                questionsList.set(i,questions);
            }
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
        for (int i = 0; i < questionsList.size(); i++) {
            Questions questionsSet=questionsList.get(i);
            String returnString=String.format("%s,%s,%s,%s,%s",questionsSet.getContent(),questionsSet.getType(),questionsSet.getSign(),questionsSet.getComplexity(),questionsSet.getAnswer());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
        }
        bufferedReader.close();
        bufferedWriter.flush();
        bufferedWriter.close();
        return false;
    }
    @Override
    public List<Questions> selectQuestion(int sign,String type) throws Exception {
        BufferedReader bufferedReader=new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
        List<Questions> questionsList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Questions questions=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
            questionsList.add(questions);
        }
        for (int i = 0; i < questionsList.size(); i++) {
            Questions questions=questionsList.get(i);
            if(questions.getSign()==sign){
                System.out.println(questions.getContent());
            }
        }
        return null;
    }
    @Override
    public List<Questions> selectQuestions(String type) throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader(("QuestionBankManagementSystem\\Questions\\".endsWith("/") ? "QuestionBankManagementSystem\\Questions\\":"QuestionBankManagementSystem\\Questions\\"+"/")+type+".txt"));
        List<Questions> questionsList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            Questions questions=new Questions(strings[0],strings[1],Integer.parseInt(strings[2]),strings[3],strings[4]);
            questionsList.add(questions);
        }
        for (int i = 0; i < questionsList.size(); i++) {
            Questions questions=questionsList.get(i);
            System.out.println(questions.getContent());
        }
        return null;
    }
}
// UserDaoImpl implements IUserDao 
import studio.lyl.questionbankmanagementsystem.dao.IUserDao;
import studio.lyl.questionbankmanagementsystem.entity.User;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2020/12/8 22:12
 */
public class UserDaoImpl implements IUserDao {
    @Override
    public boolean insertUser(User user) throws Exception {
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
        List<User> userList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            User userGet=new User(Integer.parseInt(strings[0]),strings[1],strings[2]);
            userList.add(userGet);
        }
        for (int i = 0; i < userList.size(); i++) {
            User userGet=userList.get(i);
            if(userGet.getId()==user.getId()){
                System.out.println("用户已存在,请重新输入");
            }else {
                userList.add(user);
            }
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\User.txt",true));
        for (int i = 0; i < userList.size(); i++) {
            User userGet=userList.get(i);
            String returnString=String.format("%s,%s,%s",userGet.getId(),userGet.getPassword(),userGet.getUserName());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
        }
        bufferedReader.close();
        bufferedWriter.flush();
        bufferedReader.close();
        return false;
    }
    @Override
    public boolean deleteUserById(Integer id) throws Exception {
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
        List<User> userList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            User user=new User(Integer.parseInt(strings[0]),strings[1],strings[2]);
            userList.add(user);
        }
        for (int i = 0; i < userList.size(); i++) {
            User userGet=userList.get(i);
            if(userGet.getId()==id) {
                userList.remove(i);
            }
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\User.txt"));
        for (int i = 0; i < userList.size(); i++) {
            User user=userList.get(i);
            String returnString=String.format("%s,%s,%s",user.getId(),user.getPassword(),user.getUserName());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
        }
        bufferedReader.close();
        bufferedWriter.flush();
        bufferedReader.close();
        return false;
    }
    @Override
    public boolean updateUser(Integer id,User user) throws Exception {
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
        List<User> userList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            User userGet=new User(Integer.parseInt(strings[0]),strings[1],strings[2]);
            userList.add(userGet);
        }
        for (int i = 0; i < userList.size(); i++) {
            User userGet=userList.get(i);
            if(userGet.getId()==id) {
                userList.set(i,user);
            }
        }
        BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("QuestionBankManagementSystem\\User.txt"));
        for (int i = 0; i < userList.size(); i++) {
            User userGet=userList.get(i);
            String returnString=String.format("%s,%s,%s",userGet.getId(),userGet.getPassword(),userGet.getUserName());
            bufferedWriter.write(returnString);
            bufferedWriter.newLine();
        }
        bufferedReader.close();
        bufferedWriter.flush();
        bufferedReader.close();
        return false;
    }
    @Override
    public List<User> selectUserById(Integer id) throws Exception {
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
        List<User> userList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            User user=new User(Integer.parseInt(strings[0]),strings[1],strings[2]);
            userList.add(user);
        }
        for (int i = 0; i < userList.size(); i++) {
            User user=userList.get(i);
            if(user.getId()==id){
                System.out.println(user);
            }
        }
        return null;
    }
    @Override
    public List<User> selectUser() throws Exception{
        BufferedReader bufferedReader=new BufferedReader(new FileReader("QuestionBankManagementSystem\\User.txt"));
        List<User> userList=new ArrayList<>();
        String s=null;
        while ((s=bufferedReader.readLine())!=null){
            String[] strings=s.split(",");
            User user=new User(Integer.parseInt(strings[0]),strings[1],strings[2]);
            userList.add(user);
        }
        for (int i = 0; i < userList.size(); i++) {
            User user=userList.get(i);
            System.out.println(user);
        }
        return null;
    }
}


相关文章
|
25天前
|
监控 Java API
如何使用Java语言快速开发一套智慧工地系统
使用Java开发智慧工地系统,采用Spring Cloud微服务架构和前后端分离设计,结合MySQL、MongoDB数据库及RESTful API,集成人脸识别、视频监控、设备与环境监测等功能模块,运用Spark/Flink处理大数据,ECharts/AntV G2实现数据可视化,确保系统安全与性能,采用敏捷开发模式,提供详尽文档与用户培训,支持云部署与容器化管理,快速构建高效、灵活的智慧工地解决方案。
|
7天前
|
NoSQL Java 关系型数据库
Liunx部署java项目Tomcat、Redis、Mysql教程
本文详细介绍了如何在 Linux 服务器上安装和配置 Tomcat、MySQL 和 Redis,并部署 Java 项目。通过这些步骤,您可以搭建一个高效稳定的 Java 应用运行环境。希望本文能为您在实际操作中提供有价值的参考。
60 26
|
19天前
|
XML Java 测试技术
从零开始学 Maven:简化 Java 项目的构建与管理
Maven 是一个由 Apache 软件基金会开发的项目管理和构建自动化工具。它主要用在 Java 项目中,但也可以用于其他类型的项目。
31 1
从零开始学 Maven:简化 Java 项目的构建与管理
|
16天前
|
设计模式 消息中间件 搜索推荐
Java 设计模式——观察者模式:从优衣库不使用新疆棉事件看系统的动态响应
【11月更文挑战第17天】观察者模式是一种行为设计模式,定义了一对多的依赖关系,使多个观察者对象能直接监听并响应某一主题对象的状态变化。本文介绍了观察者模式的基本概念、商业系统中的应用实例,如优衣库事件中各相关方的动态响应,以及模式的优势和实际系统设计中的应用建议,包括事件驱动架构和消息队列的使用。
|
22天前
|
存储 缓存 安全
java 中操作字符串都有哪些类,它们之间有什么区别
Java中操作字符串的类主要有String、StringBuilder和StringBuffer。String是不可变的,每次操作都会生成新对象;StringBuilder和StringBuffer都是可变的,但StringBuilder是非线程安全的,而StringBuffer是线程安全的,因此性能略低。
42 8
|
18天前
|
Java
Java项目中高精度数值计算:为何BigDecimal优于Double
在Java项目开发中,涉及金额计算、面积计算等高精度数值操作时,应选择 `BigDecimal` 而非 `Double`。`BigDecimal` 提供任意精度的小数运算、多种舍入模式和良好的可读性,确保计算结果的准确性和可靠性。例如,在金额计算中,`BigDecimal` 可以精确到小数点后两位,而 `Double` 可能因精度问题导致结果不准确。
|
22天前
|
Java 开发者
在 Java 中,一个类可以实现多个接口吗?
这是 Java 面向对象编程的一个重要特性,它提供了极大的灵活性和扩展性。
43 1
|
28天前
|
Java Android开发
Eclipse 创建 Java 项目
Eclipse 创建 Java 项目
39 4
|
1月前
|
安全 Java
Java多线程集合类
本文介绍了Java中线程安全的问题及解决方案。通过示例代码展示了使用`CopyOnWriteArrayList`、`CopyOnWriteArraySet`和`ConcurrentHashMap`来解决多线程环境下集合操作的线程安全问题。这些类通过不同的机制确保了线程安全,提高了并发性能。
|
28天前
|
Java Android开发
Eclipse 创建 Java 类
Eclipse 创建 Java 类
26 0