From 96adc9ec9ad81a2f5fd1443aa23408ba231e85cd Mon Sep 17 00:00:00 2001 From: Song-EunJu Date: Thu, 17 Nov 2022 18:34:05 +0900 Subject: [PATCH] =?UTF-8?q?add:=20crossorigin=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goorm/FileItemReaderJobConfig.java | 33 +++++++++------- .../com/example/goorm/oreum/CsvReader.java | 4 +- .../com/example/goorm/oreum/CsvWriter.java | 4 +- .../example/goorm/oreum/OreumController.java | 8 +--- .../java/com/example/goorm/oreum/Test.java | 39 +++++++++++++++++++ .../oreum/repository/TestRepository.java | 8 ++++ 6 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/example/goorm/oreum/Test.java create mode 100644 src/main/java/com/example/goorm/oreum/repository/TestRepository.java diff --git a/src/main/java/com/example/goorm/FileItemReaderJobConfig.java b/src/main/java/com/example/goorm/FileItemReaderJobConfig.java index a51184b..a87d8d2 100644 --- a/src/main/java/com/example/goorm/FileItemReaderJobConfig.java +++ b/src/main/java/com/example/goorm/FileItemReaderJobConfig.java @@ -3,7 +3,9 @@ //import com.example.goorm.oreum.CsvReader; //import com.example.goorm.oreum.CsvWriter; //import com.example.goorm.oreum.Oreum; +//import com.example.goorm.oreum.Test; //import com.example.goorm.oreum.repository.OreumRepository; +//import com.example.goorm.oreum.repository.TestRepository; //import lombok.RequiredArgsConstructor; //import lombok.extern.slf4j.Slf4j; //import org.springframework.batch.core.Job; @@ -21,7 +23,7 @@ // private final JobBuilderFactory jobBuilderFactory; // private final StepBuilderFactory stepBuilderFactory; // -// private final OreumRepository oreumRepository; +// private final TestRepository testRepository; // private final CsvReader csvReader; // private final CsvWriter csvWriter; // @@ -38,9 +40,21 @@ // .build(); // } // +// // csvFileItemReaderStep 이라는 이름의 Step 생성 +// @Bean +// public Step csvFileItemReaderStep() { +// return stepBuilderFactory.get("csvFileItemReaderStep") +// .chunk(chunkSize) +// // Reader 에서 읽어올 타입 - String, Writer에 넘겨줄 타입이 Oreum +// .reader(csvReader.csvFileItemReader()) // 일단 csv에서 String 읽기 +// .processor(csvProcessor()) // String을 가공 +// .writer(csvWriter) +// .build(); +// } // @Bean -// public ItemProcessor csvProcessor() { +// public ItemProcessor csvProcessor() { // return oreumStr -> { +// System.out.println(oreumStr); // String[] lineArr = oreumStr.split(","); // String name = lineArr[0]; // String type = lineArr[1].split("/")[1]; @@ -50,7 +64,7 @@ // double y = Double.parseDouble(pos.split(" ")[1]); // double z = Double.parseDouble(pos.split(" ")[2]); // -// Oreum oreum = Oreum.builder() +// Test oreum = Test.builder() // .name(name) // .xPos(x) // .yPos(y) @@ -60,7 +74,7 @@ // .build(); // // oreum.toTypeEnum(type); -// oreumRepository.save(oreum); +// testRepository.save(oreum); // if((monthCheck == 1 || monthCheck == 3 || monthCheck == 5 || monthCheck == 7 // || monthCheck == 8 || monthCheck == 10 || monthCheck ==12) && dayCheck == 31) { // monthCheck++; @@ -79,15 +93,4 @@ // }; // } // -// // csvFileItemReaderStep 이라는 이름의 Step 생성 -// @Bean -// public Step csvFileItemReaderStep() { -// return stepBuilderFactory.get("csvFileItemReaderStep") -// .chunk(chunkSize) -// // Reader 에서 읽어올 타입 - String, Writer에 넘겨줄 타입이 Oreum -// .reader(csvReader.csvFileItemReader()) // 일단 csv에서 String 읽기 -// .processor(csvProcessor()) // String을 가공 -// .writer(csvWriter) -// .build(); -// } //} diff --git a/src/main/java/com/example/goorm/oreum/CsvReader.java b/src/main/java/com/example/goorm/oreum/CsvReader.java index e23145f..bf7025e 100644 --- a/src/main/java/com/example/goorm/oreum/CsvReader.java +++ b/src/main/java/com/example/goorm/oreum/CsvReader.java @@ -2,8 +2,6 @@ // //import lombok.RequiredArgsConstructor; //import org.springframework.batch.item.file.FlatFileItemReader; -//import org.springframework.batch.item.file.mapping.DefaultLineMapper; -//import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; //import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Configuration; //import org.springframework.core.io.ClassPathResource; @@ -16,7 +14,7 @@ // /* file read */ // FlatFileItemReader flatFileItemReader = new FlatFileItemReader<>(); // flatFileItemReader.setResource(new ClassPathResource("C:\\Users\\Windows10\\Desktop\\오름.txt")); -// flatFileItemReader.setEncoding("UTF-8"); // encoding +// flatFileItemReader.setEncoding("UTF-8"); // return flatFileItemReader; // } //} \ No newline at end of file diff --git a/src/main/java/com/example/goorm/oreum/CsvWriter.java b/src/main/java/com/example/goorm/oreum/CsvWriter.java index c6f868a..d91f4fe 100644 --- a/src/main/java/com/example/goorm/oreum/CsvWriter.java +++ b/src/main/java/com/example/goorm/oreum/CsvWriter.java @@ -1,6 +1,7 @@ //package com.example.goorm.oreum; // //import com.example.goorm.oreum.repository.OreumRepository; +//import com.example.goorm.oreum.repository.TestRepository; //import lombok.RequiredArgsConstructor; //import org.springframework.batch.item.ItemWriter; //import org.springframework.context.annotation.Configuration; @@ -11,8 +12,9 @@ //@Configuration //@RequiredArgsConstructor //public class CsvWriter implements ItemWriter { +//// private final OreumRepository oreumRepository; // -// private final OreumRepository oreumRepository; +// private final TestRepository testRepository; // // @Override // public void write(List list) throws Exception { diff --git a/src/main/java/com/example/goorm/oreum/OreumController.java b/src/main/java/com/example/goorm/oreum/OreumController.java index 8b05f6d..c5e9325 100644 --- a/src/main/java/com/example/goorm/oreum/OreumController.java +++ b/src/main/java/com/example/goorm/oreum/OreumController.java @@ -5,15 +5,11 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; - -import java.util.List; +import org.springframework.web.bind.annotation.*; @Controller +@CrossOrigin(origins = "*") @RequiredArgsConstructor public class OreumController { diff --git a/src/main/java/com/example/goorm/oreum/Test.java b/src/main/java/com/example/goorm/oreum/Test.java new file mode 100644 index 0000000..6e801f6 --- /dev/null +++ b/src/main/java/com/example/goorm/oreum/Test.java @@ -0,0 +1,39 @@ +package com.example.goorm.oreum; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.Arrays; + +@Entity +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Test { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + + @Enumerated(EnumType.STRING) + private OreumType type; + private double xPos; + private double yPos; + private double zPos; + private int month; + private int day; + + // 랜덤 색상값 추가해줘야 함 + public void toTypeEnum(String type) { + this.type = Arrays.stream(OreumType.values()) + .filter(o1 -> o1.getTitle().equals(type)) + .findFirst() + .get(); + } + +} + diff --git a/src/main/java/com/example/goorm/oreum/repository/TestRepository.java b/src/main/java/com/example/goorm/oreum/repository/TestRepository.java new file mode 100644 index 0000000..4b07003 --- /dev/null +++ b/src/main/java/com/example/goorm/oreum/repository/TestRepository.java @@ -0,0 +1,8 @@ +package com.example.goorm.oreum.repository; + +import com.example.goorm.oreum.Oreum; +import com.example.goorm.oreum.Test; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TestRepository extends JpaRepository { +} \ No newline at end of file