(1) using the Set method:
public class Book {
Private String BookName;
public void Setbookname (String bookname) {
This.bookname = BookName;
}
XML configuration:
<bean id= "book" class= "Com.example.propetys.Book" >
<!--Injection Property Value Name property: The value is the name of the property that you defined, the Value property: Set the specific value--
<property name= "BookName" value= "nine Yang Canon" ></property>
</bean>
(2) structure with parameters
public class PropertDemo1 {
Private String username;
Public PropertDemo1 (String username) {
This.username = Username;
}
XML configuration:
<bean id= "Demo" class= "Com.example.propetys.PropertDemo1" >
<!--is injected with the method of construction
<constructor-arg name= "username" value= "Liuguxiia" ></constructor-arg>
</bean>
(3) using interface injection
Public Interface dao{
public void Delete (String name);
}
public class Daoimpl implements dao{
private String name;
public void Delete (String name) {
This.name=name;
}
}
In the spring framework, only the first two methods are allowed.
Three ways to inject spring attributes