第一周练习

任务1

1.①行元素列举

    <span>、<strong>、<em>、<text>、<a>、<br>

  ②块元素列举

    <div>、<h1>~<h6>、<p>、<ul>、<ol>

  ③行内块元素

    <img>、<input>、<textarea>、<select>、<button>

2.行元素与行内块元素区别

    行元素(Inline):

        不会在其前后创建新行。

        只占据它本身内容的宽度。

        可以与其他行元素在同一行内。

    行内块元素(Inline-block):

        不会在其前后创建新行。

        可以设置宽度和高度。

        可以与其他行元素在同一行内,但表现得像块元素一样,可以设置宽高。

3.HTML标签占用的位置与占用像素的量分别被哪些CSS属性所决定?

    ①占用位置:position属性

                static(静态定位):默认值,忽略top、bottom、left、right等属性,适用于不需要特殊定位的元素

                relative(相对定位):可设置top、bottom、left、reght属性,未设置时与static一样,适用于需要微调位置的元素(菜单项、按钮)

                absolute(绝对定位):元素位置不受其他元素影响,可设置top、bottom、left、reght属性,适用于需要精确控制位置的元素(弹出窗口、工具提示)

                fixed(固定定位):元素位置不受其他元素影响,位置相对浏览器窗口固定,可设置top、bottom、left、reght属性,适用于需要固定在页面某位置的元素(导航栏、广告横幅)

                sticky(粘性定位):在滚动到特定位置时将元素固定。通过设置top、right、bottom和left属性来确定元素在视口中的位置,同时还可以设置z-index属性来指定元素在z轴上的层级关系,适用于需要在用户滚动到特定位置时固定的元素(回到顶部按钮)

    ②占用像素的量

        width、height

        <!-- 从外到内 -->

        margin:可设置top、bottom、left、reght属性

        border:可设置top、bottom、left、reght属性

        padding:可设置top、bottom、left、reght属性

       

4.CSS伪类是什么?分别有哪些状态?

    ①css伪类是用于选择元素特定状态的关键字

    ②伪类状态:

            :hover 鼠标悬停在元素时的状态(按钮)

            :active 当前被用户点击的元素状态(按钮)

            :focus 获得焦点时的状态(表单)

            :visited 链接已被访问时

            :first-child 选中父元素第一个子元素

            :last-child 选中父元素最后一个子元素

            :disabled 被禁用的元素

            :required 必填的表单元素

练习

<!DOCTYPE html>
<body>
    <div class="red"></div>
    <div class="blue"></div>
    <div class="pink"></div>
    <div class="orange"></div>
    <div class="green"></div>
</body>
</html>
<style>
    .red{
        /* 宽度、高度、距离上边距、距离左边距 */
        width: 250px;
        height: 130px;
        top: 100px;
        left:100px;
        background-color: rgba(255, 28, 36);
        /* 位置 */
        position: absolute;
    }
    .orange{
        width: 300px;
        height: 200px;
        top: 100px;
        left: 350px;
        /* 上左右边框 */
        border-top: 35px solid rgb(255, 127, 39);
        border-left: 5px solid rgb(255, 127, 39);
        border-right: 5px solid rgb(255, 127, 39);
        /* 下虚线边框 */
        border-bottom: 5px dashed rgb(255, 127, 39);
        position: absolute;
    }
    .pink{
        width: 100px;
        height: 100px;
        top: 200px;
        left: 200px;
        /* 圆角 */
        border-radius: 50%;
        background-color: rgb(255, 174, 201);
        /* 悬浮 */
        position: fixed;
    }
    .green{
        width: 110px;
        height: 50px;
        top: 150px;
        left: 305px;
        background-color: rgb(181, 230, 29);
        position: fixed;
    }
    .blue{
        width: 80px;
        height: 80px;
        top: 125px;
        left: 200px;
        /* 顺时针旋转并扭曲 */
        transform: rotate(45deg) skew(7deg,7deg);
        /* 旋转中心设置为水平和垂直的中心 */
        transform-origin: center center; 
        background-color: rgb(0,162,232);
        position: fixed;
    }
    /* 鼠标悬浮效果 */
    .blue:hover,.red:hover,.green:hover,.pink:hover{
        background-color: black;
    }
    /* 鼠标点击效果 */
    .red:active,.green:active,.pink:active{
        transform: scale(0.5);
    }
    .blue:active{
        transform: rotate(45deg) skew(7deg,7deg) scale(0.5);
    }
    .orange:hover{
        border-color: black;
    }
    .orange:active{
        transform: scale(0.5);
        border-color: rgb(255, 127, 39);
    }
</style>

 任务2

1.JDBC是什么?它有哪些常用组件?
①JDBC(Java Database Connectivity)是Java提供的一套API,用来帮助开发者链接和操作数据库

②常用组件:DriverManager:管理数据库驱动程序、提供getConnection()方法,用于建立数据库连接
Connection:标识与数据库的连接,用于执行SQL和管理事务.
Statement:执行Sql语句,适合简单SQL
PreparedStatement:支持预编译,防止SQL注入
ResultSet:保存SQL查询的结果集

2.JDBC和mysql-driver的关系
mysql-driver是针对于MYSQL数据库的JDBC驱动程序,可以通过引用jar包(mysql-connector-java-jar)或使用Maven依赖(pom.xml)
加载驱动:Class.forName("com.mysql.cj.jdbc.Driver")
获取需数据链接DriverManager.getConnection(url,username,password)
注:url通常为 jdbc:mysql://服务器地址/数据库名

3.JavaX的DataSource是什么?他有什么作用?
DataSource是Java中用于获取数据库连接的标准接口,定义在javax.sql.DataSource包中.主要职责是创建和管理数据库连接
作用: 连接管理:管理数据库连接的创建、分配和回收
连接池:维护一个连接池,预先创建一定数量的数据库连接,当应用陈鼓需要时从中取出,不需要时放回池中
性能优化:通过连接池可以减少创建和销毁连接的开销,提高应用的性能
事务管理:支持事务处理,可以自动参与应用程序的事务管理.

练习

pom.xml

<?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>com.example</groupId>
    <artifactId>myapp</artifactId>
    <version>2.1.0.RELEASE</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.6.13</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

 DatabaseController.java

package com.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/database")
public class DatabaseController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    // 1. 建库
    @PostMapping("/createDatabase")
    public String createDatabase(@RequestParam String dbName) {
        String sql = "CREATE DATABASE " + dbName;
        jdbcTemplate.execute(sql);
        return "数据库" + dbName + "创建成功";
    }

    // 2. 建表
    @PostMapping("/createTable")
    public String createTable(@RequestParam String tableName, @RequestParam String columnsDefinition) {
        String sql = "CREATE TABLE " + tableName + " (" + columnsDefinition + ")";
        jdbcTemplate.execute(sql);
        return "表格" + tableName + "创建成功";
    }

    // 3. 删表
    @DeleteMapping("/dropTable")
    public String dropTable(@RequestParam String tableName) {
        String sql = "DROP TABLE " + tableName;
        jdbcTemplate.execute(sql);
        return "表格" + tableName + "删除成功";
    }

    // 4. 截断表
    @PostMapping("/truncateTable")
    public String truncateTable(@RequestParam String tableName) {
        String sql = "TRUNCATE TABLE " + tableName;
        jdbcTemplate.execute(sql);
        return "表格" + tableName + "清空成功";
    }

    // 5. 插入数据
    @PostMapping("/insertData")
    public String insertData(@RequestParam String tableName, @RequestBody Map<String, Object> data) {
        StringBuilder sql = new StringBuilder("INSERT INTO " + tableName + " (");
        StringBuilder values = new StringBuilder("VALUES (");
        data.forEach((key, value) -> {
            sql.append(key).append(", ");
            values.append("'").append(value).append("', ");
        });
        sql.setLength(sql.length() - 2);
        values.setLength(values.length() - 2);
        sql.append(") ").append(values).append(")");
        jdbcTemplate.execute(sql.toString());
        return tableName + "插入数据成功";
    }

    // 6. 删除数据
    @DeleteMapping("/deleteData")
    public String deleteData(@RequestParam String tableName, @RequestParam String condition) {
        String sql = "DELETE FROM " + tableName + " WHERE " + condition;
        jdbcTemplate.execute(sql);
        return tableName + "删除数据成功";
    }

    // 7. 查询数据
    @GetMapping("/selectData")
    public String selectData(@RequestParam String tableName, @RequestParam String condition) {
        String sql = "SELECT * FROM " + tableName + " WHERE " + condition;
        return jdbcTemplate.queryForList(sql).toString();
    }

    // 8. 更新数据
    @PutMapping("/updateData")
    public String updateData(@RequestParam String tableName, @RequestBody Map<String, Object> data, @RequestParam String condition) {
        StringBuilder sql = new StringBuilder("UPDATE " + tableName + " SET ");
        data.forEach((key, value) -> sql.append(key).append(" = '").append(value).append("', "));
        sql.setLength(sql.length() - 2);
        sql.append(" WHERE ").append(condition);
        jdbcTemplate.execute(sql.toString());
        return tableName + "数据更新成功";
    }
}

 Application.java

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值