Initial Commit
This commit is contained in:
		@@ -0,0 +1,13 @@
 | 
			
		||||
package com.example.springdemo;
 | 
			
		||||
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
public class SpringDemoApplication {
 | 
			
		||||
 | 
			
		||||
	public static void main(String[] args) {
 | 
			
		||||
		SpringApplication.run(SpringDemoApplication.class, args);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
package com.example.springdemo.config;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.springframework.boot.context.properties.ConfigurationProperties;
 | 
			
		||||
import org.springframework.stereotype.Component;
 | 
			
		||||
 | 
			
		||||
@Data
 | 
			
		||||
@Component
 | 
			
		||||
@ConfigurationProperties(prefix = "business.security")
 | 
			
		||||
public class DataBaseProperties {
 | 
			
		||||
 | 
			
		||||
    private String dbUrl;
 | 
			
		||||
 | 
			
		||||
    //@Value("${db.username}")
 | 
			
		||||
    private String username ;
 | 
			
		||||
 | 
			
		||||
    //@Value("${db.password}")
 | 
			
		||||
    private String password ;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,42 @@
 | 
			
		||||
package com.example.springdemo.controller;
 | 
			
		||||
 | 
			
		||||
import com.example.springdemo.entities.Business;
 | 
			
		||||
import com.example.springdemo.config.DataBaseProperties;
 | 
			
		||||
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestParam;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping("/student")
 | 
			
		||||
public class StudentController {
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    DataBaseProperties dbProps;
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/get")
 | 
			
		||||
    public List<String> getStudent() {
 | 
			
		||||
        //  DataBaseProperties dbProps = new DataBaseProperties();
 | 
			
		||||
        return List.of(dbProps.getUsername(), dbProps.getPassword(), dbProps.getDbUrl());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/getBy")
 | 
			
		||||
    public Business getStudentById(@RequestParam String id) {
 | 
			
		||||
 | 
			
		||||
        var bs = Business.builder()
 | 
			
		||||
                .name(id)
 | 
			
		||||
                .tel(dbProps.getPassword())
 | 
			
		||||
                .build();
 | 
			
		||||
 | 
			
		||||
        if (!Objects.equals(bs.getTel(), "")) {
 | 
			
		||||
            bs.setTel("");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return bs;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/main/java/com/example/springdemo/entities/Business.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/main/java/com/example/springdemo/entities/Business.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
package com.example.springdemo.entities;
 | 
			
		||||
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Builder;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
 | 
			
		||||
@Data
 | 
			
		||||
@Builder
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
public class Business {
 | 
			
		||||
    private String name;
 | 
			
		||||
    private String tel;
 | 
			
		||||
    private String address;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								src/main/resources/application.properties
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/main/resources/application.properties
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user