java-reflection assigning values to attributes以下是通过Java反射给属性赋值的步骤:
首先,准备一个类,例如有如下的`Teacher`类:
```java
class Teacher {
private int userId;
private String userName;
public int getUserId() {
return userId;
}
public String getUserName() {
return userName;
}
private void hello(String name, Integer userId) {
System.out.println("Hello World," + name + ", " + userId);
}
}
```
若要给这个类的属性通过反射赋值,可以这样做:
1. 获取类的`Class`对象:
- 如果已经有类的实例对象,可以通过`obj.getClass()`获取,例如`Teacher`类的实例`teacher`,可以用`teacher.getClass()`。
- 如果没有实例对象,可以直接通过`Class.forName("完整类名")`获取,如`Class.forName("Teacher所在的包名.Teacher")`。
2. 获取类中的所有属性(包括私有属性):通过`Class`对象调用`getDeclaredFields()`方法得到属性数组。
3. 遍历属性数组,对每个属性进行操作:
- 先设置属性可访问(因为属性可能是私有的),通过`field.setAccessible(true)`。
- 然后给属性赋值,假设我们有一个`Map`对象`map`,其中包含了要赋给`Teacher`类属性的值(`map`中的键为属性名,值为要赋的值),可以通过`field.set(newEntity,map.get(field.getName()))`给属性赋值,这里的`newEntity`是`Teacher`类的实例对象(通过`clazz.newInstance()`创建,不过要处理好可能的异常情况)。
例如下面这种通过反射将`Map`中的值赋给类对象对应属性的代码:
```java
import java.lang.reflect.Field;
import java.util.Map;
public class MapToPOJOExample {
public static <T> T mapToPOJO(Map map, Class clazz) {
Field[] declaredFields = clazz.getDeclaredFields();
Object newEntity = null;
try {
newEntity = clazz.newInstance();
} catch (Exception e) {
// 处理获取实例对象失败的异常
}
for (Field field : declaredFields) {
field.setAccessible(true);
try {
if (map.get(field.getName())!= null) {
field.set(newEntity, map.get(field.getName()));
}
} catch (IllegalAccessException e) {
// 处理属性赋值失败的异常
}
}
return (T) newEntity;
}
}
```
<a href="/?from=ask_words" style="color:red" target="_blank">点击前往免费阅读更多精彩小说</a>
Immersion Hair WashingImmersive hair washing involved a variety of processes and experiences. For example, in some hair care places, the hair washing process would be arranged according to the condition of the scalp. First, the pores would be opened by steaming, and then the hair would be drenched with soda water. Some would provide hot packs, and there would be a massage session during the hair washing process, such as the head, shoulders, neck, hands, and other parts would be massaged. At the same time, the choice of shampoo was also very particular. Some would use a shampoo containing raw ginger juice, and they might wash it twice. They would also use a conditioner to remove excess oil and cutin from the scalp. In addition, there may be preparations such as combing, wetting and drying the hair before washing the hair. During the washing process, the comb will be used to massage the scalp. Pre-washing essential oil, pre-washing hair mask, constant temperature hair cap, soft film, etc. After washing, there may be simple skincare and hair care products, such as applying scalp essence, No. 6 hair care, etc. Finally, the hair will be dried or styled. The whole process may also be matched with some comfortable environment design to enhance the experience. Even in space, there were special immersive hair-washing methods, such as the demonstration by astronaut Zhai Zhigang using a shower cap to wash his hair.
Large Immersion TheaterThe large-scale immersive theater had the following characteristics:
** I. Scale of the venue **
1. ** Large Area **
- Some large-scale immersive theatres were thousands of square meters in size. For example, Shanghai's Pudefu Saga City of Light had a total area of 46,000 square meters, and its indoor performance area was more than 12,000 square meters. It broke the Guinness World Record and became the largest immersive theater in the performance area. There was also Shanghai's Providence immersive theater, which covered an area of 3000 square meters. It restored the entire town in 1930 with 29 scenes.
2. ** Rich Scenery **
- Large immersive theaters often had many scenes to explore. For example, the immersive theater in Providence included Chinatown, wealthy areas, cemeteries, churches, hospitals, etc. It could unlock various mysterious scenes and bring a rich experience to the audience.
** 2. Casting and performance **
1. ** Many actors **
- There might be hundreds of actors acting on the same stage. For example, some large-scale immersive theaters needed many actors to support them in order to create a grand scene and complex plot.
2. ** Acting major **
- The actors quickly got the audience into the role through their superb acting skills. For example, in the immersive theater of "Fengtian Legends," more than 130 actors and staff spent more than 210 days rehearsing for more than 3,000 hours, recreating the secret and unforgettable history of Northeast China. The actors 'acting skills were amazing, from actors, dancers to warlords and spies.
** 3. Enhanced Skills **
- VR, AR, and other technologies would be used to enhance the sense of immersion, making the audience feel as if they were in a more realistic scene. For example, some immersive parks or large-scale immersive theater projects might use these technologies to create a unique visual and sensory experience.
** 4. Problems **
1. ** Imbalance between story and interaction **
- Some large-scale immersive theatres lacked storytelling and the interaction experience was unsatisfactory. For example, Shanghai's "City of Light", which was built with 650 million yuan, had a grand scene and a professional cast, but many viewers complained that the story was not enough and the interaction experience was not good. For the audience, especially the young people who pursued novelty, just relying on gorgeous scenery and dazzling special effects could no longer satisfy their growing spiritual needs. They were more eager to truly integrate into the plot, resonate with the characters, and obtain a unique experience through interaction.
"The Legend of Pengcheng" is equally exciting. Everyone is welcome to click and read it!
Student dormitory work summaryThe following is an example of a summary of the student dormitory work:
I. Safety Management
1. Regular safety inspections: Just like the special safety inspection of the students 'dormitories led by the leadership team of Shaoyang City No. 3 Middle School, check whether the wires, sockets, and other facilities are aging and damaged, check for illegal electricity usage, check whether there are dangerous items such as secret controlled knives, flammable and explosive prohibited items, and check whether there are any safety risks in the beds, wardrobes, doors and windows, as well as fire hydrators, fire extinguisher, and other fire-fighting facilities and equipment. You can also refer to the regular time that some schools have found out. For example, after November when the weather turns cold, the inspection will be strengthened.
2. Safety education: Through various means to enhance the safety awareness of teachers and students, such as organizing boarding students to hold symposiums to emphasize discipline and safety, or conducting safety education for students in daily management to guide students to enhance safety awareness.
2. Health management
1. Daily inspection: Insist on checking the hygiene of the dormitory every day, report criticism to the dormitory with poor performance and carry out moral education to ensure that the dormitory is clean and tidy, and cultivate good hygiene habits among the students.
2. "To improve the environment: The school can invest funds to upgrade the quality of the student dormitories. For example, Hunan University of Technology invested more than 12 million yuan to upgrade the overall quality of the 1903 student dormitories, including the renovation of walls, the replacement of damaged wall tiles in the bathroom and balcony, the maintenance and replacement of furniture, and the maintenance of electrical appliances such as fans, so as to improve the living environment of the students.
Third, discipline management
1. Strictly check the dormitory: Check the dormitory discipline every day to ensure that the students have good sleep discipline, so that every student can develop good habits and ensure the safety of sleeping at night.
2. Give full play to the role of the dormitory leader: communicate with the dormitory leader once a month and work together to do a good job in the students 'dormitory.
IV. Personnel Management
1. To improve the work level of the dormitory wardens: The dormitory wardens should go through three stages: initial learning and familiarizing themselves with the rules and regulations, in-depth learning and mastering the policy provisions, and combining practical learning to continuously improve their work level.
2. To enhance the ability of the dormitory staff: to enhance their working ability and achieve the "four diligence" in their work, namely, diligence in speech (try their best to help solve the students 'problems, timely reminders, etc.), diligence in hands (work plans do not miss things, clear shifts, etc.), diligence in brains (strengthen work planning, etc.), diligence in legs (repeatedly check the dormitory to find problems and solve them in time).
3. Deal with the relationship: The dormitory committee member must deal with the relationship with the other class leaders (care for each other, unite comrades, learn modestly, etc.) and the relationship with the students (serve the students wholeheartedly).
Through the efforts of the above aspects, the management of student dormitories could be made more scientific, standardized, and humane, ensuring that boarding students could study and live safely, healthily, and efficiently during their time in school, which would help build a safe campus.
Work feedback on student suggestionsIn order to further smooth the communication channels between students and the school and establish a sound student opinion processing and feedback mechanism, the school has a variety of work feedback methods:
1. ** Construct a "zero distance" student work model **:
- Regular student symposiums were held to fully understand the students 'daily learning, life, psychological problems, and other aspects. It was to solve the problems in a timely and effective manner according to the opinions and suggestions put forward by the students, allowing the students to participate in the school management, so that the school could grasp the students 'learning and life trends at the first time.
2. ** Building a one-stop student service platform **:
- Set up suggestion boxes, email addresses, and information feedback hotlines. This made it easier for information to be transmitted, allowing the school to understand the problems that students were most concerned about and needed to be solved. Since it went online, it had received nearly a hundred student messages and emails related to dormitory maintenance, curriculum structure, and many other aspects.
3. ** Creating a "family-style" communication atmosphere **:
- The relevant leaders of the school visited the student dormitories and conducted in-depth research on the students 'true demands. From the perspective of relatives or friends, they cared and cared for students, asked for students 'suggestions and opinions on school work, and understood their demands in a timely manner. At the same time, they put forward requirements for dormitory hygiene, safe electricity, etc., reminding students to develop good living habits, create a positive and healthy dormitory culture, and create a good and warm living environment for students.
In addition, in the Institute of Information Technology, the counselor was the direct manager of the class where the students were in school. He was the person directly responsible for accepting the students 'opinions, suggestions, or complaints. When students have opinions, suggestions, or demands, they should generally report to the counselor first. After receiving it, the counselor must report it to the relevant departments as soon as possible (except for the class affairs).
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>
the best thing I liked about this novel is the numeric values of various abilities and attributes were consistent in most system novels the numeric values are always a mess like xp and sometimes even levels and I like the novels where mc always keeps evolving it's a good novel give it a try and tell me if you know any like it or chrysalis novels where mc keeps evolving