当前位置: 首页 > news >正文

(自用)Java学习-5.9(Thymeleaf,自动装配,自定义启动器 )

一、Thymeleaf 模板技术

  1. 片段定义与复用

    <!-- 声明片段 -->
    <div th:fragment="b1">...</div>
    <!-- 插入片段 -->
    <div th:insert="~{bottom :: b1}"></div>  <!-- 追加内容 -->
    <div th:replace="~{bottom :: b2}"></div> <!-- 替换当前标签 -->
    
  2. 内置对象应用

    <!-- 字符串处理 -->
    <span th:text="${#strings.substring(msg,0,3)}"/>
    <!-- 日期格式化 -->
    <td th:text="${#dates.format(user.birthday,'yyyy-MM-dd')}"></td>
    

二、SpringBoot 整合 MyBatis 全流程

  1. 依赖配置

    <!-- MyBatis Starter -->
    <dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId>
    </dependency>
    
  2. YML 核心配置

    mybatis:mapper-locations: classpath:/mappers/*.xmltype-aliases-package: com.zxst.pojoconfiguration:map-underscore-to-camel-case: true
    
  3. Mapper 关联查询示例

    @Select("SELECT * FROM employee")
    @Results({@Result(property = "dept", column = "dept_id",one = @One(select = "com.zxst.mapper.DeptMapper.getInfoById"))
    })
    List<Employee> getEmpInfo();
    

三、CRUD 功能实现

  1. 增删改查实现要点
    • 新增:表单绑定对象参数
      <form th:action="@{/emp/saveEmp}" method="post"><input name="ename">...
      </form>
      
    • 更新:数据回显技术
      @GetMapping("/getOneEmpById")
      public String getOneEmpById(Model model, @RequestParam Integer eid) {model.addAttribute("one", employeeMapper.getOneById(eid));return "edit";
      }
      
    • 删除:参数传递
      <a th:href="@{/emp/deleteEmp(eid=${emp.eid})}">删除</a>
      

四、自动装配原理(重点)

  1. 启动器核心机制

    @SpringBootApplication
    ↓ 包含
    @EnableAutoConfiguration
    ↓ 触发
    META-INF/spring.factories中的自动配置类
    
  2. 自定义启动器开发

    • 步骤 1:定义配置属性类
      @ConfigurationProperties(prefix = "zxst")
      public class ZxstProperties { private String name; }
      
    • 步骤 2:创建自动配置类
      @Configuration
      @EnableConfigurationProperties(ZxstProperties.class)
      public class ZxstAutoConfiguration {@Beanpublic ZxstService zxstService() {return new ZxstService(properties.getName());}
      }
      
    • 步骤 3:注册配置到META-INF/spring.factories

相关文章:

  • 旋转图像算法讲解
  • YOLOv8网络结构
  • 判断一个数是不是素数的最高效的算法
  • HTML简单语法标签(后续实操:云备份项目)
  • Vue3的命名规范
  • Python60日基础学习打卡D12【虫豸版】
  • 文档外发安全:企业数据防护的最后一道防线
  • Odoo 18 安全组与访问权限管理指南
  • 015枚举之滑动窗口——算法备赛
  • Matlab 单机无穷大系统故障
  • 什么是户用光储一体化,开启家庭用电新时代、智能电表 | 新能源发电系统配套电表 | 家用储能电表 | 防逆流监测电表
  • 【日撸 Java 三百行】Day 13(链表)
  • 关系实验课--笛卡尔积
  • Blueprints - Gameplay Message Subsystem
  • 274、H指数
  • PyCharm历史版本下载说明
  • 软件安全之内存泄漏
  • 电商平台一站式网络安全架构设计指南
  • 从PNG到矢量图:星云智控Logo的商用矢量转换全解析-优雅草卓伊凡
  • 掌握函数(二)嵌套使用与链式访问以及函数的声明与定义
  • 以色列“全面接管”加沙“雷声大雨点小”:援助政策引内讧,美欧失去耐心
  • 失智老人有两个儿子却欠费住养老院两年多,法检合力指定监护人
  • 英欧再“牵手”,友好“靠美国”
  • 受工友诱骗为获好处费代购免税品,海口海关:两当事人被立案
  • 历史缝隙里的人︱觑功名如画饼:盛世“做题家”的攀爬与坠落
  • “当代阿炳”甘柏林逝世,创办了国内第一所残疾人高等学府