代码语言:javascript复制
public class JDBCutil {
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
private static final String DB_CONNECTION_URL = "jdbc:mysql://localhost/x";
private static final String DB_USERNAME = "root";
private static final String DB_PASSWORD = "root";
/**
* 获取MySQL数据库连接
* @return
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection getConnection() throws ClassNotFoundException, SQLException {
Connection connection = null;
try {
// 加载MySQL数据库驱动程序
Class.forName(DB_DRIVER);
// 获取数据库连接
connection = DriverManager.getConnection(DB_CONNECTION_URL, DB_USERNAME, DB_PASSWORD);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw e;
} catch (SQLException e) {
e.printStackTrace();
throw e;
}
return connection;
}
/**
* 执行查询并返回ResultSet对象
* @param sql
* @return
* @throws ClassNotFoundException
* @throws SQLException
*/
public static ResultSet query(String sql) throws ClassNotFoundException, SQLException {
ResultSet resultSet = null;
try{
Connection connection = getConnection();
Statement statement = connection.createStatement();
// 执行查询语句,并返回ResultSet
resultSet = statement.executeQuery(sql);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw e;
} catch (SQLException e) {
e.printStackTrace();
throw e;
}
return resultSet;
}
}
代码语言:javascript复制//Java对象的创建
User u1 = new User("admin", "123456", 20, false);
//创建Gson对象
Gson gson = new Gson();
//序列化
String json = gson.toJson(u1);
System.out.println("序列化:" json);
//反序列化
User u2 = gson.fromJson(json, User.class);
System.out.println("反序列化:" u2);
//输出结果
//序列化:{"name":"admin","password":"123456","age":20,"isStudent":false}
//反序列化:User{name='admin', password='123456', age=20, isStudent=false, job=null}
代码语言:javascript复制<link rel="stylesheet" href="./css/bootstrap.min.css">
<script src="./js/jquery-3.6.0.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- 轮播图的图片 -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="image1.jpg" alt="Image 1">
</div>
<div class="carousel-item">
<img src="image2.jpg" alt="Image 2">
</div>
<div class="carousel-item">
<img src="image3.jpg" alt="Image 3">
</div>
</div>
<!-- 左右箭头 -->
<a class="carousel-control-prev" href="#myCarousel" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#myCarousel" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>