记单词网站设计文档
1.背景
下学期就要考四级了,就想自己设计一个可以记单词的程序,帮助提升自己的英语能力和编程能力。
2.系统功能的设计
2.1功能需求
- 类似词达人,可以根据中文意思,在四个英文单词中选择最佳答案,也可以根据英文选择中文
- 单词可以进行收藏,可以查看收藏夹和取消收藏
- 可以进行单词翻译,也可以通过中文模糊查找英文单词
- 能进行登录注册,修改密码功能(能进行注销账号)
2.2数据库表设计
-
word单词表
字段 类型 注释 id int NOT NULL id 唯一且自增 word varchar(20) NULL 单词 meaning varchar(200) NULL 中文翻译 单词表的单词主要是四级词汇
-
user用户表
字段 类型 注释 id int NOT NULL id 唯一且自增 userName varchar(20) NULL 用户名 password varchar(20) NULL 密码 newtable int NULL 收藏表的序号 -
收藏表 ( 名称:newtable_? ,?为user表的newtable)
表的属性一 word表一致。
当用户注册时,会自动生成收藏表,可以通过用户的newtable查到该表
2.3实体类的设计
实体类与数据表一一对应,通过get,set方法进行访问内部数据
- User类,与数据表user对应
- Word类,与数据表Word对应
- NewTable类,与数据表newtable对应
2.4实现各个模块流程图
-
登录模块
js判断注册密码是否符合规范
登录时将用户的User类储存在Session中。
-
四选一模块
-
搜索查询模块
-
收藏夹模块
3.实现
3.1技术栈
前端:html,css,JavaScript,Bootstrap5(美化界面),jqurey。
后端:javaweb,Tomcat,maven
数据库:mysql
开发环境:java8,Tomcat9,maven3.8.5,mysql8.0
3.2项目结构
maven依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>loveword</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>loveword Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
</dependency>
</dependencies>
</project>
3.3接口设计
-
dao
-
UserDao
public interface UserDao { //通过用户名获得用户信息 User getUser(Connection connection, String userName) throws SQLException; //注册用户 int registerUser(Connection connection ,String userName,String password,int num); //获得用户总数 int getCount(Connection connection) throws SQLException; //更新密码 int updatePwd(Connection connection ,int id,String newPwd); //用户注销 int deleteUser(Connection connection,int id); }
-
WordDao
public interface WordDao { //根据id返回查询单词 Words getWord(Connection connection,int id) throws SQLException; //得到搜索的总单词数 int getWordCount(Connection connection,String searchWord,String searchType) throws SQLException; //得到搜索的单词链表 List<Words> getWordList(Connection connection,String searchWord,String searchType,int currentPageNo,int pageSize) throws SQLException; }
-
NewTableDao
public interface NewTableDao { //创建新表 int createTable(Connection connection,int num); //添加单词,收藏单词 int addWords(Connection connection, int tableId, Words word); //取消收藏 int deleteWords(Connection connection, int tableId, String word); //查询单词 Words selectWord(Connection connection,int tableId , String word) throws SQLException; //得到收藏夹链表 List<Words> getList(Connection connection,int tableId,int currentPageNo,int pageSize) throws SQLException; //得到单词总数 int getWordsCount(Connection connection,int tableId) throws SQLException; //删除收藏表 int deleteTable(Connection connection,int tableId); }
-
-
service
-
UserService
public interface UserService { //通过用户名获取用户数据 User getUser(String userName); //用户注册 boolean registerUser(String userName,String password,int num); //获取用户总数 int getCount(); //密码修改 boolean updatePwd(int id,String newPwd); //注销用户 boolean deleteUer(int id,int tableId); }
-
WordService
public interface WordService { //根据id得到单词 Words getWord(int id); //得到要查询单词的总数 /** * * @param searchWord 要模糊搜索的单词,或中文意思 * @param searchType 要搜索的单词类型,中译英,或者英译中 * @return 总数 */ int getWordCount(String searchWord,String searchType); /** * 分页查询 * @param currentPageNo 当前页数 * @param pageSize 一页的长度 * @return 查询的单词链表 */ List<Words> getWordList(String searchWord, String searchType, int currentPageNo, int pageSize); }
-
NewTableService
public interface NewTableService { //创建收藏表 boolean createTable(int num); //收藏单词 boolean addWords(int tableId,int wordId); //取消收藏单词 boolean deleteWord(int tableId,int wordId); //判断单词是否被收藏 boolean judgeWord(int tableId,String word); //得到单词链表 List<Words> getWordList(int tableId,int currentPageNo,int pageSize); //得到单词总数 int getWordsCount(int tableId); //收藏表移除单词 boolean removeWord(int tableId,String word); }
4.效果
-