Spring其他【学习笔记】

注解说明

  • @Autowired:自动装配通过类型。名字
    如果Autowired不能唯一自动装配上属性,则需要通过@Qualifier(value=“xxx”)配合使用
  • @Nullable:字段标记了这个注解,说明这个字段可以为null
  • @Resource:自动装配通过名字。类型
  • @Component:组件,放在类上,说明这个类被Spring管理了,就是bean!
    @Component有几个衍生注解,我们在web开发中,会按照mvc三成架构分层
    • dao【@Repository】
    • service【@Service】
    • controller【@Controller】
  • @Value:能,其作用是通过注解将常量、配置文件中的值、其他bean的属性值注入到变量中,作为变量的初始值。可以直接写在属性上也可以写在set方法上。
  • @Configuration:用于定义配置类,可替换xml配置文件
  • @ComponentScan(“xxx”):主要就是定义扫描的路径从中找出标识了需要装配的类自动装配到spring的bean容器中
  • @Bean
// 注册一个bean,就相当于我们之前写的一个bean标签
// 这个方法的名字,就相当于bean标签中的id属性
// 这个方法的返回值,就相当于bean标签中的class属性
@Bean
public User user(){
    return new User();// 就是要注入到bean的对象!
}

一些包

<dependencies>
        <!--mysql的包-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>

        <!--mybatis的包-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.11</version>
        </dependency>

        <!--spring的包-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.0.RELEASE</version>
        </dependency>

        <!--spring操作数据库的话,还需要一个spring-jdbc-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.2.0.RELEASE</version>
        </dependency>

        <!--aop织入包-->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.13</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值