From ba9e100a1897a8c423374a71ec36f6a42f2a2cae Mon Sep 17 00:00:00 2001 From: Chantha Date: Sun, 17 May 2020 13:35:32 +0700 Subject: [PATCH] config cors header --- .idea/workspace.xml | 62 +++++++++--------- .../com/chantha/jdbc/config/CORSConfig.kt | 13 ++++ .../jdbc/controller/ProductController.kt | 8 ++- .../com/chantha/jdbc/jpa/model/Product.java | 14 +++- .../com/chantha/jdbc/jpa/repo/ProductRepo.kt | 4 ++ .../jpa/service/product/ProductServiceImpl.kt | 2 + .../com/chantha/jdbc/config/CORSConfig.class | Bin 0 -> 1692 bytes .../jdbc/controller/ProductController.class | Bin 1639 -> 2180 bytes .../com/chantha/jdbc/jpa/model/Product.class | Bin 2481 -> 2798 bytes .../chantha/jdbc/jpa/repo/ProductRepo.class | Bin 1163 -> 1362 bytes .../service/product/ProductServiceImpl.class | Bin 4671 -> 4671 bytes 11 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt create mode 100644 target/classes/com/chantha/jdbc/config/CORSConfig.class diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2f9d634..5bdc19a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,14 @@ - - - + - - - - - + + + + + + @@ -102,10 +102,10 @@ - + - + @@ -118,49 +118,49 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + \ No newline at end of file diff --git a/src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt b/src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt new file mode 100644 index 0000000..775a085 --- /dev/null +++ b/src/main/kotlin/com/chantha/jdbc/config/CORSConfig.kt @@ -0,0 +1,13 @@ +package com.chantha.jdbc.config + +import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.CorsRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer + +@Configuration +class CORSConfig :WebMvcConfigurer{ + + override fun addCorsMappings(registry: CorsRegistry) { + registry.addMapping("/**").allowedOrigins("http://localhost:3001") + } +} diff --git a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt index 172b0e0..87c1181 100644 --- a/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt +++ b/src/main/kotlin/com/chantha/jdbc/controller/ProductController.kt @@ -9,11 +9,15 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController @RestController -public class ProductController @Autowired constructor(private val productService: ProductService) { +public class ProductController @Autowired constructor(private val productService: ProductService,private val productRepo: ProductRepo) { - @GetMapping("/product") + @GetMapping("/api/product/order") fun product():List{ return productService.fetchAllProducts() } + @GetMapping("/api/product/getproduct") + fun getAllProduct():List{ + return productRepo.readAllRecord() + } } \ No newline at end of file diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java b/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java index aca6da2..bcd809f 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java +++ b/src/main/kotlin/com/chantha/jdbc/jpa/model/Product.java @@ -8,6 +8,7 @@ import java.util.List; @Entity //@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "productId") +@JsonPropertyOrder({"productId"}) public class Product implements Serializable { @Id @@ -17,6 +18,16 @@ public class Product implements Serializable { private String productName; private double price; + public String getImg() { + return img; + } + + public void setImg(String img) { + this.img = img; + } + + private String img; + public Product() { } @@ -53,11 +64,12 @@ public class Product implements Serializable { this.orderDetails = orderDetails; } - public Product(Long productId, String productName, double price, List orderDetails) { + public Product(Long productId, String productName, double price, List orderDetails,String img) { this.productId=productId; this.productName=productName; this.price=price; this.orderDetails=orderDetails; + this.img=img; } // @JsonManagedReference diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt b/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt index 992c05f..5b3fec2 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt +++ b/src/main/kotlin/com/chantha/jdbc/jpa/repo/ProductRepo.kt @@ -10,4 +10,8 @@ interface ProductRepo : CrudRepository{ @Query("SELECT * FROM product INNER JOIN order_detail ON (product.product_id=order_detail.product_id)" , nativeQuery = true) override fun findAll(): MutableIterable + + @Query("SELECT * FROM product",nativeQuery = true) + fun readAllRecord():List + } \ No newline at end of file diff --git a/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt b/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt index e99b733..7c4e0c2 100644 --- a/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt +++ b/src/main/kotlin/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.kt @@ -16,6 +16,8 @@ class ProductServiceImpl @Autowired constructor(private val productRepo: Product return productRepo.findAll().map { toView(it) } } + + private fun toView(data: Product): ProductWithOrderDetail { val view = ProductWithOrderDetail() view.productId = data.productId diff --git a/target/classes/com/chantha/jdbc/config/CORSConfig.class b/target/classes/com/chantha/jdbc/config/CORSConfig.class new file mode 100644 index 0000000000000000000000000000000000000000..cb0a7229d18d425f3284b6bccc7722a0327abd85 GIT binary patch literal 1692 zcmb_c-)|E~5dQWY`>t0*98>bEEiEJ^PSR$bgi;#QKw?zYm6M>P3ZOi#&x^hG`7XL$ zJLN5ZOP~763q_TRA|Cmps?MFA;G&2ksC0L;GdKIq>^HOX>hC{a0JwoohHGBf;a*b& zrYU%HoWgX_ac1&zm%=*Xim zYV#vm<61^NUz$@e5d@(TMuh=?AZuGauaDe~WMm`FaI<<=ThU$QJFFzI3( zQ~&Czeh3?%GF)yNbGXL2A9})XhT5#H7K_UcK7X%v8>(!QfQ>I0E(+fdk7Ru(QVl8& z!=u8%Ib8og=e>$+F22MJ!-#1r3N~B)?>k4WefPt{KOufJI7b93; z7^@C?bxRsi7e`Y9a9IseKwwZqUTZVr9oXe%At>VZ^CYL6e`Dy&+?-@JBS|P0WIO3c0gE9wE8;>rA z3$LfvQrnQZ9M&aGiK+_ZcDGZL(J!LrlOYuW6g}?^9fn~b!>E8vTd`70DPPvoVrj9hiluH03!`DtG=&(FDulr`n7B7} z)^1$6Y@>}I3qx4?3tYSL54bkoH$Z9|lX>^vbLO4<^?qru0>1BmzJ3F+ga-^MJIYhX zs}j3lWcFH(Osn0jz1Z($n(bP>{h`EE7Vtf-cQy|W9uEI7+b6X6={k((3suZd_sTwd;E|>Z4NMr{*+V zh1-iLW*FqP#`8v}$gmry3OP|lKcB*W&1)=f|K=q#fdv)wNGdQHr1<2es7Uy*;Yt#8?w$LJS&lRk)Ig6lesSM z_;q(gFAt%9J}f0b_q`qULL`(ykjF8|zK{{~RT>bWejm{Zt4 zXg9vsI~P?ZnG`F{R$SYjHp3`QpVIgTWrNSJsU9hj@# z#-Nv$Jjo^Z20ckf`;Nl1+8^|sL~_t8@_?;9bZlREJjDZJcr3VQZo8h9a(vV0fgOm= z#7B3O{W3f<6@wZMPlUt38$|}tY#-|FZ-x5qPOG!KQ`l=nUky8IS>o_-I_g{hx(q(X z;L?_y*a9{UTGl%=!hp42nqHwZ9xCL=M=VSrLFkRMLA_y@S!VNJQLTI=cqWB*s#Z6KG diff --git a/target/classes/com/chantha/jdbc/jpa/model/Product.class b/target/classes/com/chantha/jdbc/jpa/model/Product.class index 3cb7783431e4ea6697cfdd03459a54419ec5eb84..860302b19aa1b8c2637d87f23f37ab182079a78f 100644 GIT binary patch literal 2798 zcmbVN+fo}x5be=r1+oGT1{@%^@f8rZ*9jzcEKCeYfE;ltpr}gaX;=+niL|R)tz0G_ zl-DFxrc#xMd_X=bmD97!BBX^fdD*#jpE-THd-k7y|N5JV=4rd1GPIVZK3eBlnLqFN z^88QRFuW`?!|^*24Y+P3_1RnX1Kv3xJhx^!x0#dT^0L1Q~@$G015-)`9lb+zO; zt}lJtby|W(wfP6Lsl1lm@|9yLvs{JKgP4Og=lq`6uv5zh_kh-HB0d%Tasoh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)JP z+tbRB=zL&`N@zqs{*S;LVjDSfJD#O>Y*w}rYVs++bb>M()8!|ufCmp()1Z5F-=JX{ zF=&D&4Vt29gJx(J@6|OgLYN=A?Y^b^Cv|1{f~K{}cFiM&o7J#?=G%obDZJCr93?2m z_3(WQ5BLOD2IkMO9#u3(<1hdTOfd$dXW+r=bNxN1!@j_J9wC`F!1Cg@qC4~@ebuJB zIya7m?FR^Xj#*$%=Kdh@yUwwIaRfnx{0Ss@h%X~>qOa)@R)Vs$h>;VRn1ckLDE1o+ zG2#R%ZJZkzoTJC^;^0lpTqu=$d`_|c^0z4o*j%0u$T@@Z{1tGt1Zxs+Hzq+(=qbj2 zO!0n9cL!oJ>6<~A;{BKwfa&2Cn7A>5LQE4H(=+-u!W6?76a9%2zv82pr|dvX&+!Al z;3-aV#H4bM&MDE4X$hE~T!D#25@DLsm|oBdlJ)bH?C0s(08D|%zSAP(4!_h1U(srq z@BnzDekK`bT&p3F(+l8SxdJDPSkM|G0;#1Sytyv&8Egc_*I~Rz8)3m;FsHDWVfkti z<(AGVo?8S>x%uQd^?=A|&zI2jD=21_Mp15x)^SrdG^l03L#9Y%nNVbG48$i-;~{w#>o80+>i>QL+e_^e%i>{A*ZZ^nJwQ7SX?#&jK$1 diff --git a/target/classes/com/chantha/jdbc/jpa/repo/ProductRepo.class b/target/classes/com/chantha/jdbc/jpa/repo/ProductRepo.class index 5f6934c9990d188a5f3fe24259f039c1665478fc..b28e83285949955b854ad6f4e53a77fbc36258d3 100644 GIT binary patch delta 379 zcmeC?yu`(O>ff$?3=9k=4BCtgs*?+tR5u!>FL& zmL=+!mSpDW`(zfESTizMU*H~qv+)GKs=4fLMiq@gB%x=1QP-a zaB>}J;9?Sxg-{BUUovTkc<~9aNpT3V2r(Hj8L)e(A6mi2F8-MGbk`9Ml*00 YGYA(mC>1j(7c;07gSbFa1Wc*|0Fp2}>;M1& delta 210 zcmcb_)y>I!>ff$?3=9k=4C;&ws*^7=iB4{164+>z#xz-g*^I^QK!e0&FJ`I9+03de zhgPt$OGk%5zei-DOz8K{+sftx`ENDDA9GVlO-yu}QB4E#|*zA8|Z4JaxI zq+x2A8Pvdfl)!p?f$BMcd=Um#2GM8+W={qIFcM=Bhw&sl86+8`fT9f2(F}~m3^ELo ave69e#SFs5406Q`^2H1a#SENaQV{_D938&^ diff --git a/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class b/target/classes/com/chantha/jdbc/jpa/service/product/ProductServiceImpl.class index 2f7042635bd711c3dfe0a719c5abd609a2557099..43c5dc4348401016b77ffac4f1397346b4221dbc 100644 GIT binary patch delta 189 zcmdn5vR`F`7_X=*gEE5}gB^o9gAaoMLmZHu$e^)Vn>UeBQ;dOwK^!P30fdqaIt-c& zE(}@>2@Ki{c|d*}klhIsoz5UNc`M%uK{=pmd7x?qplU@RskFI|zm-wn%*v3<(AdmO z*~rS+oXgO}*i_j_$Jol)0w!t#l!u9$7)^E(ER+SRGgCH%s4_BDHnak&0ntDapo$BE F`2b5uAsPSx delta 189 zcmdn5vR`F`7_X=@gEE5(gB^n^gAaoMLmZHu$e^}an>UeBQ-pzoK@=z`#vs8U&Y;7f z&fvnJ!H~e9$&d%+w*lFm3|b7+86+le*i_j_$Jol)3@&Pk5H&HF>?Bwy3sh&OYzR?hWUOpxWo*d>qJbhn I6&D2a0W>%u>;M1&