通过注解实现ServiceImpl业务

一、使用@Component装配Bean

1、 定义类:User

在类上面加@Component注解,在属性上面加@Value值

Spring通过注解装配Bean

package com.wbg.springxmlbean.entity;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component(value = "user")
public class User {
    @Value("2")
    private int id;
    @Value("韦邦杠")
    private String name;
    @Value("18")
    private int age;
    private Role role;

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", role=" + role +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}
View Code

相关文章:

  • 2021-11-12
  • 2021-05-08
  • 2021-10-18
  • 2021-10-20
  • 2021-07-29
  • 2021-04-23
  • 2021-11-30
  • 2021-12-12
猜你喜欢
  • 2021-11-20
  • 2021-12-01
  • 2021-08-24
  • 2021-05-21
  • 2021-04-03
  • 2021-05-24
相关资源
相似解决方案