当前位置:网站首页>2022 summer vacation software innovation laboratory training project practice 1
2022 summer vacation software innovation laboratory training project practice 1
2022-07-23 13:45:00 【Flying dinosaur】
List of articles
Class learning system
Database creation
First , We must realize that database is the foundation of application development , Without that foundation , There are many things we can't complete , For example, some of the projects UI Design ( Forms, etc )、 Code writing and so on . If this project is developed by individuals, it may not be very troublesome , Because if the database needs to be modified during development , You can modify it by yourself slowly , from UI To code writing ( But if you are in the late stage of development , It is found that the database needs to be modified , That's a high probability ). however , Let's think about it from another angle , If you are a team developer , Each person is responsible for a module , Suppose that each module needs to be coded based on the database , So if in the development , It is found that the database needs to be modified , It is also a very time-consuming and labor-intensive thing for the team , It can lead to a lot of serious problems , Such as code rewriting .
The users of this project are students , Students can use this website to join study groups , Then students can speak and discuss in the study group , Users can also use the existing website to log in and register accounts that do not exist .
So before the formal coding of the project , First, let's build a database
Hereby explain , The database may also need to be modified later , Because problems always appear , Here is also the process
First , It is necessary to analyze users , Here we will simply give the key fields of users , user
ID、 user name 、 User password 、 User creation time ( You can improve the database fields by yourself ).
Then there are students , Student information needs student number 、 full name 、QQ、 Phone number 、 Authority level ( You can improve the database fields by yourself )

You also need a data sheet for the study group , Study groups need groups
ID、 Team leaderID、 The number of team 、 Team name 、 Group Introduction 、 Among them, the groupIDPrimary key .
Because it can be discussed among users , We need to use database to store the content discussed here , The required field content has comments
IDNumber 、 The user who commentedID、 Comment on your study group 、 Comment content 、 Comment on time .
So far , We have created the database of the class learning system ( Very, very simple ), Convert the model we just built into a database , Here's the picture .


after , We have successfully imported the newly created database .
Create project
After we create the database , You need to create a good project , And layer the project . Use IDEA Enterprise edition to create Web project .

First , We need to configure the database in the project , Because of this Web The project will definitely use JDBC To interact with the underlying database , For example, the user login will access the database to query whether the current user exists , When registering an account, we will use the database to add users .
Configuration database
stay WEB-ING establish lib Catalog , Import the driver of the database under this directory jar package ( Namely JDBC That set of operation )

Above resources Create database connection profile db.properties
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/study?&useSSL=false&serverTimezone=UTC
username=root
password=123456
Then if you remember JDBC Students of operation should also know the time of database operation , There is a database operation tool class , Namely JDBCUtil, First we need to create a util File to store our customized tool classes
public class JDBCUtil {
private static final String driver;
private static final String url;
private static final String userName;
private static final String password;
static {
InputStream is = JDBCUtil.class.getClassLoader().getResourceAsStream("db.properties");
Properties properties = new Properties();
try {
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}
driver = properties.getProperty("driver");
url = properties.getProperty("url");
userName = properties.getProperty("username");
password = properties.getProperty("password");
}
// Get database connection
public static Connection getConnection() {
Connection con = null;
try {
Class.forName(driver);
con = DriverManager.getConnection(url, userName, password);
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
return con;
}
// Database query , Return result set
public static ResultSet query(Connection con, PreparedStatement st, ResultSet rs, String sql
, Object[] params) throws SQLException {
st = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
if (params != null) {
for (int i = 0; i < params.length; i++) {
st.setObject(i + 1, params[i]);
}
}
rs = st.executeQuery();
return rs;
}
// Database addition, deletion and modification
public static int update(Connection con, String sql
, Object[] params, ResultSet rs, PreparedStatement st) throws SQLException {
st = con.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
st.setObject(i + 1, params[i]);
}
return st.executeUpdate();
}
// Close database connection
public static void release(Connection con, Statement st, ResultSet rs) {
boolean flag = true;
if (rs != null) {
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
flag = false;
}
}
if (st != null) {
try {
st.close();
st = null;
} catch (SQLException e) {
e.printStackTrace();
flag = false;
}
}
if (con != null) {
try {
con.close();
con = null;
} catch (SQLException e) {
e.printStackTrace();
flag = false;
}
}
}
}
That's what it is Web In the project , Our configuration operations for databases and database operation classes .
establish entity file
Creating entity The function of is to turn each table of the database into an entity in the project entity, This is more in line with Java Object oriented design thinking .

stay entity in , We need to change the data table just created in the database into an entity , For example, in the database user The corresponding is entity Under the user class , The fields in the database correspond to Java Properties in .
User The categories are as follows :
public class User {
private int uid;
private String uname;
private String upassword;
private Date ucreatetime;
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getUpassword() {
return upassword;
}
public void setUpassword(String upassword) {
this.upassword = upassword;
}
public Date getUcreatetime() {
return ucreatetime;
}
public void setUcreatetime(Date ucreatetime) {
this.ucreatetime = ucreatetime;
}
}
The rest of the database tables correspond to this Java class , And so on .

establish dao Folder
stay dao Under the folder Java It is a file that operates on the underlying database , Is similar to the JDBC To add, delete, modify and check the database , We won't do it today to write the database operation class .
establish filter file
filter The folder is the file where the filter is stored , stay Java Web In the project , We need to let users have access rights , Filter visitor users ( For example, tourists can only view the homepage of the website , Unable to access other pages ), At this time, you need to use filters to filter permissions . Another application scenario is to use filters to filter character encoding .
establish servlet file
servlet Mainly to respond to the operation of the front end , For example, when the front end needs to log in , Just want to give this request to servlet, And then through this servlet, To encapsulate the data from the front end , Such as user login , Package the front-end data into User class , And then call service Services operate .
establish service file
service The classes in the file are servlet A class is called , adopt servlet The encapsulated class passed , Carry out specific business operations , And call dao Database operation class in layer , Each business can operate the specific data in the database .
The above is the first step of the project
servlet, And then through this servlet, To encapsulate the data from the front end , Such as user login , Package the front-end data into User class , And then call service Services operate .
establish service file
service The classes in the file are servlet A class is called , adopt servlet The encapsulated class passed , Carry out specific business operations , And call dao Database operation class in layer , Each business can operate the specific data in the database .
The above is the first step of the project
边栏推荐
- Optimising a 3D convolutional neural network for head and neck computed tomography segmentation with
- ROS中引用和输出消息类型
- 数据库系统原理与应用教程(042)—— MySQL 查询(四):使用通配符构造查询条件
- The principle of Google interview questions is to analyze 12 table tennis balls, one of which is defective. Weigh it with a balance for 3 times to find it
- 魔兽地图编辑器触发器笔记
- docker mysql
- Running matlab program on GPU
- Unity关于本地加载图片涉及webrequest或者byte
- Light chain dissection / tree chain dissection
- Kotlin - Job 任务/取消
猜你喜欢

Kotlin - Job 任务/取消

专题讲座5 组合数学 学习心得(长期更新)
![Shell运算符、$((运算式))” 或 “$[运算式]、expr方法、条件判断、test condition、[ condition ]、两个整数之间比较、按照文件权限进行判断、按照文件类型进行判断](/img/65/a735ca2c2902e3fc773dda79438972.png)
Shell运算符、$((运算式))” 或 “$[运算式]、expr方法、条件判断、test condition、[ condition ]、两个整数之间比较、按照文件权限进行判断、按照文件类型进行判断

Learn about canvas

Remote editing and debugging with vscode

【可视化调度软件】上海道宁为SMB组织带来NETRONIC下载、试用、教程

中国在又一个新兴科技领域领先美国,站在科技创新制高点

Charles抓包工具测试实战

IP地址分类及范围

【可視化調度軟件】上海道寧為SMB組織帶來NETRONIC下載、試用、教程
随机推荐
数据库系统原理与应用教程(039)—— MySQL 查询(一):SELECT 命令的语法分析
Smart canteen data analysis system
[Muduo] poller abstract class
欧洲“气荒”对中国有哪些影响?
docker mysql
Client does not support authentication protocol requested by server; consider upgrading MySQL client
MySQL index transaction & JDBC programming
Learn about canvas
Changes in the pattern of NFT trading market: from one dominant company to a hundred schools of thought
Optimising a 3D convolutional neural network for head and neck computed tomography segmentation with
[record] golang cross platform compilation
同花顺开户风险性大吗,安全吗?
vs2019:constexpr 函数“qCountLeadingZeroBits”不能生成常量表达式
docker redis
Backtracking method to solve the eight queens problem
Point target simulation of SAR imaging (II) -- matlab simulation
决策树详解
回溯法解决 八皇后问题
2. Les règles quantitatives
【可視化調度軟件】上海道寧為SMB組織帶來NETRONIC下載、試用、教程