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

一、Thymeleaf 模板技术

  1. 片段定义与复用

    
    
    ...
  2. 内置对象应用

    
    
    
    
    

二、SpringBoot 整合 MyBatis 全流程

  1. 依赖配置

    
    
      org.mybatis.spring.boot
      mybatis-spring-boot-starter
    
    
  2. YML 核心配置

    mybatis:
      mapper-locations: classpath:/mappers/*.xml
      type-aliases-package: com.zxst.pojo
      configuration:
        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 getEmpInfo();
    

三、CRUD 功能实现

  1. 增删改查实现要点
    • 新增:表单绑定对象参数
      ...
    • 更新:数据回显技术
      @GetMapping("/getOneEmpById")
      public String getOneEmpById(Model model, @RequestParam Integer eid) {
        model.addAttribute("one", employeeMapper.getOneById(eid));
        return "edit";
      }
      
    • 删除:参数传递
      删除
      

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

  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 {
        @Bean
        public ZxstService zxstService() {
          return new ZxstService(properties.getName());
        }
      }
      
    • 步骤 3:注册配置到META-INF/spring.factories

你可能感兴趣的:(Java学习之路,java,学习,开发语言)