(自用)Java学习-5.8(总结,springboot)

发布于:2025-05-14 ⋅ 阅读:(14) ⋅ 点赞:(0)

一、MySQL 数据库

  1. 表关系

    • 一对一、一对多、多对多关系设计
    • 外键约束与级联操作
  2. DML 操作

    INSERT INTO table VALUES(...)
    DELETE FROM table WHERE...
    UPDATE table SET col=val WHERE...
    
  3. DQL 查询

    • 基础查询:SELECT * FROM table WHERE...
    • 聚合函数:COUNT()/SUM()/AVG()/MAX()/MIN()
    • 分组查询:GROUP BY + HAVING
    • 排序:ORDER BY col [ASC/DESC]
  4. 连接查询

    • 内连接:INNER JOIN(交集数据)
    • 外连接:LEFT/RIGHT JOIN(包含单边全数据)
  5. 子查询

    • 标量子查询(返回单个值)
    • 关联子查询(依赖外层查询)

二、前端基础

  1. HTML/CSS

    • 基础标签:<form> <input> <table>
    • 布局:盒模型、Flex 布局
    • 响应式设计:@media查询
  2. JavaScript 核心

    • DOM 操作:document.getElementById()
    • 事件处理:onclick/onsubmit
    • jQuery 核心:
      $(selector).click(function(){
        $.ajax({
          url: "...",
          success: function(data){...}
        })
      })
      


三、JDBC 编程

  1. 标准流程
    // 1. 加载驱动
    Class.forName("com.mysql.cj.jdbc.Driver");
    // 2. 获取连接
    Connection conn = DriverManager.getConnection(url,user,pwd);
    // 3. 事务管理
    try {
      conn.setAutoCommit(false);
      // 执行SQL操作
      conn.commit();
    } catch(Exception e) {
      conn.rollback();
    } finally {
      conn.close();
    }
    


四、Servlet 与 Spring MVC

  1. 核心注解

    • @RequestMapping:定义请求路径
    • @RequestParam:获取 URL 参数
    • @RequestBody:接收 JSON 数据
    • @ResponseBody:返回 JSON 数据
  2. 参数绑定

    // 基础类型绑定
    public String method(@RequestParam("id") int id)
    
    // 对象绑定(名称严格对应)
    public String method(User user)
    
  3. 返回类型

    • 视图解析:return "viewName"
    • 重定向:return "redirect:/path"
    • JSON 响应:需配合@ResponseBody


五、Spring 框架

  1. IoC 容器

    • 配置方式:
      // XML配置
      <bean id="..." class="..."/>
      
      // 注解配置
      @Component @Service @Repository
      
      // Java配置类
      @Configuration
      public class Config {
          @Bean
          public DataSource dataSource() {...}
      }
      
  2. 依赖注入

    • @Autowired(按类型优先)
    • @Resource(按名称优先)
  3. AOP 编程

    @Aspect
    @Component
    public class LogAspect {
        @Pointcut("execution(* com..service.*.*(..))")
        public void serviceLayer() {}
        
        @Around("serviceLayer()")
        public Object log(ProceedingJoinPoint pjp) {
            // 前置通知
            Object result = pjp.proceed();
            // 后置通知
            return result;
        }
    }
    


六、MyBatis

  1. 核心配置
    <!-- Mapper接口绑定 -->
    <mapper class="com.example.UserMapper"/>
    
    <!-- 动态SQL示例 -->
    <select id="findUsers" parameterType="map">
      SELECT * FROM users
      <where>
        <if test="name != null">AND name=#{name}</if>
        <if test="age != null">AND age > #{age}</if>
      </where>
    </select>
    


七、Spring Boot 核心

  1. YML 配置

    server:
      port: 8080
    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/db
    custom:
      list:
        - item1
        - item2
      map: {key1: val1, key2: val2}
    
  2. 配置注入

    @Component
    @ConfigurationProperties(prefix = "custom")
    public class CustomConfig {
        private List<String> list;
        private Map<String,String> map;
        // Getters/Setters
    }
    
    @Value("${server.port}")
    private int port;
    
  3. 静态资源

    • 默认路径:/static /public /resources
    • 自定义配置:
      spring:
        web:
          resources:
            static-locations: classpath:/custom/
      
  4. Thymeleaf 模板

    <!-- 条件判断 -->
    <div th:if="${user.age > 18}">成年人</div>
    
    <!-- 循环遍历 -->
    <tr th:each="item : ${list}">
      <td th:text="${item.id}"></td>
    </tr>
    
    <!-- 路径处理 -->
    <script th:src="@{/js/main.js}"></script>