Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write code that injects multiple types of data into Spring dependencies

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to write code for Spring dependency injection of multiple types of data". In daily operation, I believe that many people have doubts about how to write code for Spring dependency injection of multiple types of data. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to write code for Spring dependency injection of multiple types of data". Next, please follow the editor to study!

Student entity class package entity;import java.util.*;/** * @ author LeDao * @ company * @ create 2022-02-13 21:26 * / public class Student {private int id; private String name; private StudentClass studentClass; private String [] books; private List hobbies; private Map cards; private Set games; private String wife; private Properties info; 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 StudentClass getStudentClass () {return studentClass; public void setStudentClass (StudentClass studentClass) {this.studentClass = studentClass; public String [] getBooks () {return books Public void setBooks (String [] books) {this.books = books; public List getHobbies () {return hobbies; public void setHobbies (List hobbies) {this.hobbies = hobbies; public Map getCards () {return cards; public void setCards (Map cards) {this.cards = cards; public Set getGames () {return games Public void setGames (Set games) {this.games = games; public String getWife () {return wife; public void setWife (String wife) {this.wife = wife; public Properties getInfo () {return info; public void setInfo (Properties info) {this.info = info @ Override public String toString () {return "Student {" + "id=" + id + ", name='" + name +'\'+ ", studentClass=" + studentClass + ", books=" + Arrays.toString (books) + ", hobbies=" + hobbies + ", cards=" + cards + " Games= "+ games +", wife=' "+ wife +'\'+", info= "+ info +'}' } StudentsClass entity class package entity;/** * @ author LeDao * @ company * @ create 2022-02-14 14:11 * / public class StudentClass {private int id; private String name; 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;} @ Override public String toString () {return "Class {" + "id=" + id + ", name='" + name +'\'+'}';}} beans.xml

The data types shown below are: general type, object, array, List, Map, Set, null, Properties

Java programming thought MySQL must know that the ordinary world will sing, dance, rap and play basketball. LOL DNF COC root 123456 Test import config.MyConfig Import entity.Student;import org.springframework.context.ApplicationContext;import org.springframework.context.annotation.AnnotationConfigApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * @ author LeDao * @ company * @ create 2022-02-12 15:56 * / public class MyTest {public static void main (String [] args) {ApplicationContext context=new ClassPathXmlApplicationContext ("beans.xml"); Student student = (Student) context.getBean ("user1"); System.out.println (student) }} at this point, the study on "how to write code for Spring dependency injection of multiple types of data" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report