当前位置: 首页 > 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
http://www.dtcms.com/a/186695.html

相关文章:

  • 旋转图像算法讲解
  • YOLOv8网络结构
  • 判断一个数是不是素数的最高效的算法
  • HTML简单语法标签(后续实操:云备份项目)
  • Vue3的命名规范
  • Python60日基础学习打卡D12【虫豸版】
  • 文档外发安全:企业数据防护的最后一道防线
  • Odoo 18 安全组与访问权限管理指南
  • 015枚举之滑动窗口——算法备赛
  • Matlab 单机无穷大系统故障
  • 什么是户用光储一体化,开启家庭用电新时代、智能电表 | 新能源发电系统配套电表 | 家用储能电表 | 防逆流监测电表
  • 【日撸 Java 三百行】Day 13(链表)
  • 关系实验课--笛卡尔积
  • Blueprints - Gameplay Message Subsystem
  • 274、H指数
  • PyCharm历史版本下载说明
  • 软件安全之内存泄漏
  • 电商平台一站式网络安全架构设计指南
  • 从PNG到矢量图:星云智控Logo的商用矢量转换全解析-优雅草卓伊凡
  • 掌握函数(二)嵌套使用与链式访问以及函数的声明与定义
  • 基于 Nexus 在 Dockerfile 配置 yum, conda, pip 仓库的方法和参考
  • 1.4 无穷小与无穷大
  • 计算机网络核心技术解析:从基础架构到应用实践
  • 当用户在浏览器输入一个 URL 并访问服务器时, 这个请求是如何到达对应的 Servlet 的?
  • 1.1 文章简介
  • 学习黑客5 分钟深入浅出理解Windows Firewall
  • kafka消费组
  • android14优化ntp时间同步
  • 雷池WAF的身份认证 - 钉钉配置教程
  • MyBatis 一对多关联映射在Spring Boot中的XML配置