2020
09-25
09-25
Spring boot整合Mybatis-plus过程解析
Mybatis初期使用比较麻烦,需要很多配置文件、实体类、dao层映射、还有很多其他的配置。初期开发使用generator可以根据表结构自动生产实体类、dao层代码,这样是可以减轻一部分开发量;后期mybatis进行大量的优化,现在可以使用注解版本,自动管理dao层和配置文件。maven依赖注意:本文使用的是mysql,数据库依赖就不展示了<!--引入mvbatie-plusstarter--><dependency><groupId>com.baomidou</groupId><artifactI...
继续阅读 >
一、前言在SpringBootAdminServer中撒送预警邮件通知是很简单的,只需要简单的几个配置就可以了。二、代码演示1、microservice-monitor-server->pom.xml<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="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.0http://maven.apache.org/xsd/maven-4....
1、@Configuration&@Bean给容器中注册组件@Configuration及@Bean的使用参考如下代码:packagecom.atguigu.config;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.ComponentScan;importorg.springframework.context.annotation.Configuration;importorg.springframework.context.annotation.FilterType;importorg.springframework.context.annotation.ComponentScan.Filt...
1、生命周期-@Bean指定初始化和销毁方法配置时指定初始化及销毁方法:Bean中提供对应的初始化及销毁方法:packagecom.atguigu.bean;importorg.springframework.stereotype.Component;@ComponentpublicclassCar{publicCar(){System.out.println("carconstructor...");}publicvoidinit(){System.out.println("car...init...");}publicvoiddetory(){System.out.println("car...detor...
工厂模式Spring中bean的创建,默认是框架利用反射new出来的bean实例。有时候也会有一些复杂的情况。假设有一个飞机,属性如下,现在需要造很多同型号的飞机,那么唯一需要改变的属性只有DriverName(机长姓名),此时可以使用工厂模式帮我们创建对象,有一个专门帮我们创建对象的类帮我们创建对象,这个类就叫工厂。publicclassAirPlane{privateStringDriverName;//机长姓名privateStringAirPlaneName;//飞机名字private...
常用的从容器中获取bean实例使用这样的方式:@Testpublicvoidtest(){Persionp=(Persion)ioc.getBean("p1");System.out.println(p);}常用的在容器中配置组件使用这样的方式:<beanid="p1"class="com.gql.bean.Persion"><propertyname="name"value="张三"></property><propertyname="age"value="18"></property><propertyname="email"value="zs@163.com"></property><propertyname="gender"value="...
在IOC容器中学习相关注解(常用)1.@Autowireda.作用对象:(官网解释)1.Youcanapplythe@Autowiredannotationtoconstructors:2.youcanalsoapplythe@Autowiredannotationto"traditional"settermethods:3.Youcanalsoapplytheannotationtomethodswitharbitrarynamesand/ormultiplearguments:4.Youcanapply@Autowiredtofieldsaswellandevenmixitwithconstructors:5.Itisalsopossibleto...