Based on OpenFire Smack, develop instant messaging applications, get offline messages, send messages, contact lists, add friends (3)

2023-01-23   ES  

Common and injected object data

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

Set file encoding in settings in IDE
在这里插入图片描述

Properties use Getter and Setter, reflective mechanism

package edu.xiao.controller;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ConfigurationProperties(prefix = "person")
public class QuickConfigurationAnnoController {
    
    private String name;
    private String address;
    private Integer age;

    @RequestMapping("/ConfigurationMethod")
    public @ResponseBody String firstMethod(){
    
        return "age:"+age+",name:"+name+",address: "+address;
    }

    public String getName() {
    
        return name;
    }

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

    public String getAddress() {
    
        return address;
    }

    public void setAddress(String address) {
    
        this.address = address;
    }

    public Integer getAge() {
    
        return age;
    }

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

It is recommended to use yml file format, there is a prompt when writing a good attribute

# server port 
 Server.Port = 8088 
 Server.servlet.context-path =/demo 
 Person.age = 18 
 Person.name = Zhang San 
 Person.address = Beijing
Effect display

When writing a good attribute, there will be a prompt function, but if Properties has the attribute, it will cover it
在这里插入图片描述

After comments on the Person property in the Properties file, create an application.yml file in the new Application.yml file

person:
  name:age: 22
  address:Hunan
Effect

Add @propertySource annotation, write the files to read, and enCoding
在这里插入图片描述

source

Related Posts

Git PULL and Git Push

javawebday12 (EL expression JSTL labeling library upload and download 196-215) vincent

topology sorting (the maximum food chain count, combination of graphic and text)

Atmega8, atmega16, the smallest system board, the first praise is here!

Based on OpenFire Smack, develop instant messaging applications, get offline messages, send messages, contact lists, add friends (3)

Random Posts

c# word Find the replacement operation jane

solve the problem of pyinstall in Python3.7.2

[Ruby-0] Regular Expression CPLUS

jmeter4.0 Performance Test Tool Install PSEUDO

(10) Getting up tutorial of MyBatis -dynamic SQL Foreach tag