첫 커밋

This commit is contained in:
2024-10-27 16:02:01 +09:00
commit 2da57a322d
39 changed files with 13451 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.leejk0523.javavue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JavavueApplication {
public static void main(String[] args) {
SpringApplication.run(JavavueApplication.class, args);
}
}

View File

@@ -0,0 +1,13 @@
package com.leejk0523.javavue;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(JavavueApplication.class);
}
}

View File

@@ -0,0 +1,26 @@
package com.leejk0523.javavue.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig {
// @Bean
// public WebMvcConfigurer corsConfigurer() {
// return new WebMvcConfigurer() {
// @Override
// public void addCorsMappings(@Nullable CorsRegistry registry) {
// if (registry != null) {
// registry.addMapping("/api/**")
// .allowedOrigins("http://localhost:8080")
// .allowedMethods("GET", "POST", "PUT", "DELETE")
// .allowedHeaders("*")
// .allowCredentials(true);
// }
// }
// };
// }
}

View File

@@ -0,0 +1,64 @@
package com.leejk0523.javavue.controller;
import com.leejk0523.javavue.entity.UserProfile;
import com.leejk0523.javavue.repository.UserProfileRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api")
public class UserProfileController {
@Autowired
private UserProfileRepository userProfileRepository;
@GetMapping("")
public String test() {
return "Hello World!";
}
@GetMapping("/all")
public List<UserProfile> getAllUsers() {
return userProfileRepository.findAll();
}
// 특정 ID로 사용자 조회
@GetMapping("/{id}")
public UserProfile getUserById(@PathVariable String id) {
return userProfileRepository.findById(id)
.orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다."));
}
// 이름으로 사용자 조회
@GetMapping("/name/{name}")
public List<UserProfile> getUsersByName(@PathVariable String name) {
return userProfileRepository.findByName(name);
}
@PostMapping
public UserProfile createUser(@RequestBody UserProfile user) {
return userProfileRepository.save(user);
}
@PutMapping("/{id}")
public UserProfile updateUser(@PathVariable String id, @RequestBody UserProfile userDetails) {
UserProfile userProfile = userProfileRepository.findById(id).orElseThrow();
userProfile.setName(userDetails.getName());
userProfile.setPhone(userDetails.getPhone());
userProfile.setAddress(userDetails.getAddress());
return userProfileRepository.save(userProfile);
}
@DeleteMapping("/{id}")
public void deleteUser(@PathVariable String id) {
userProfileRepository.deleteById(id);
}
}

View File

@@ -0,0 +1,66 @@
package com.leejk0523.javavue.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name = "UserProfile") // 테이블 이름을 명시적으로 설정
public class UserProfile {
@Id
@Column(name = "id", length = 100)
private String id;
@Column(name = "name", length = 100)
private String name;
@Column(name = "phone", length = 100)
private String phone;
@Column(name = "address", length = 100)
private String address;
@Column(name = "filepath", length = 100)
private String filepath;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getFilepath() {
return filepath;
}
public void setFilepath(String filepath) {
this.filepath = filepath;
}
}

View File

@@ -0,0 +1,23 @@
package com.leejk0523.javavue.repository;
import com.leejk0523.javavue.entity.UserProfile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface UserProfileRepository extends JpaRepository<UserProfile, String> {
// 이름으로 검색
List<UserProfile> findByName(String name);
// 전화번호로 검색
List<UserProfile> findByPhone(String phone);
// 주소에 특정 키워드가 포함된 사용자 검색
List<UserProfile> findByAddressContaining(String keyword);
// 파일 경로가 특정 값과 일치하는 사용자 검색
UserProfile findByFilepath(String filepath);
}

View File

@@ -0,0 +1,28 @@
spring.application.name=javavue
spring.datasource.url=jdbc:mariadb://leejk0523.com:3306/profile
spring.datasource.username=leejk0523
spring.datasource.password=Ghtkssk0325
# none: ???? ???? ??? (???? DB?? ?????)
# create-drop: SessionFactory? ??? ? drop? ??? ????, SessionFactory? ??? ? drop? ???? (in-memory DB? ?? ?????)
# create: SessionFactory? ??? ? ?????? drop? ???? ??? DDL? ????
# update: ??? ???? ????
# validate: ??? ???? ??? ???? ???? ??????? ????
spring.jpa.hibernate.ddl-auto=none
# DB? ??? ?? ??? ????
spring.jpa.properties.hibernate.show-sql=true
# ???? ??? ??? ??? ???
spring.jpa.properties.hibernate.format_sql=true
# ?? ?? ???? ?? ????
logging.level.org.hibernate.type.descriptor.sql=DEBUG
# ?? ?? ??
logging.level.org.hibernate.SQL=DEBUG
#UserProfile? ???? ????? ???? ??? ??
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl