Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shoei.kanno
Ecsite
Commits
714a688c
Commit
714a688c
authored
Oct 23, 2020
by
issei.miyajima
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '検索機能' into 'master'
検索機能 See merge request
!88
parents
6c5981d6
5ebe065a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
25 deletions
+87
-25
ShoesForm.java
src/main/java/ShoesForm.java
+0
-17
ShoesRepository.java
src/main/java/com/example/repository/ShoesRepository.java
+14
-2
ShoesService.java
src/main/java/com/example/service/ShoesService.java
+11
-1
EcsiteController.java
src/main/java/com/example/web/EcsiteController.java
+28
-0
list.html
src/main/resources/templates/list.html
+34
-5
No files found.
src/main/java/ShoesForm.java
deleted
100644 → 0
View file @
6c5981d6
import
org.springframework.web.multipart.MultipartFile
;
import
lombok.Getter
;
import
lombok.Setter
;
//靴新規登録用フォーム
@Getter
@Setter
public
class
ShoesForm
{
private
String
name
;
private
Integer
price
;
private
Integer
stock
;
private
Integer
size
;
private
Integer
product_status
;
//画像を受け取る変数
private
MultipartFile
multipartFile
;
}
src/main/java/com/example/repository/ShoesRepository.java
View file @
714a688c
...
...
@@ -4,6 +4,7 @@ import java.util.List;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.query.Param
;
import
com.example.domain.Shoes
;
...
...
@@ -12,9 +13,21 @@ import com.example.domain.Shoes;
public
interface
ShoesRepository
extends
JpaRepository
<
Shoes
,
Integer
>{
@Query
(
value
=
"SELECT * FROM shoes WHERE product_status = ?1 ORDER BY id DESC"
,
nativeQuery
=
true
)
public
List
<
Shoes
>
findAllByStatus
(
Integer
status
);
<<<<<<<
HEAD
//商品名あいまい検索
@Query
(
value
=
"SELECT * FROM shoes WHERE name LIKE %:keyword% ORDER BY id DESC"
,
nativeQuery
=
true
)
public
List
<
Shoes
>
findAllForSearch
(
@Param
(
"keyword"
)
String
keyword
);
//サイズ検索
@Query
(
value
=
"SELECT * FROM shoes WHERE size =?1 ORDER BY id DESC"
,
nativeQuery
=
true
)
public
List
<
Shoes
>
findAllBySize
(
Integer
size
);
}
=======
//管理画面で使用
@Query
(
value
=
"SELECT * FROM shoes WHERE name = ?1 && size = ?2"
,
nativeQuery
=
true
)
public
Shoes
findOneAddStock
(
String
name
,
Integer
size
);
}
\ No newline at end of file
}
>>>>>>>
6
c5981d65b423f7ba8b4f9fef90d0047960002bb
src/main/java/com/example/service/ShoesService.java
View file @
714a688c
...
...
@@ -50,8 +50,18 @@ public class ShoesService {
return
shoesRepository
.
findAllByStatus
(
1
);
}
//名前検索用
public
List
<
Shoes
>
findAllForSearch
(
String
shoesName
){
return
shoesRepository
.
findAllForSearch
(
shoesName
);
}
//サイズ検索用
public
List
<
Shoes
>
findAllBySize
(
Integer
shoesSize
){
return
shoesRepository
.
findAllBySize
(
shoesSize
);
}
//管理画面、重複商品のバリデーション
public
Shoes
findOneAddStock
(
String
name
,
Integer
size
)
{
return
shoesRepository
.
findOneAddStock
(
name
,
size
);
}
;
}
}
src/main/java/com/example/web/EcsiteController.java
View file @
714a688c
...
...
@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
...
...
@@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
com.example.domain.Items
;
import
com.example.domain.SalesLog
;
...
...
@@ -141,6 +143,32 @@ public class EcsiteController {
return
"list"
;
}
//名前検索用
@PostMapping
(
"/search"
)
public
String
search
(
@RequestParam
String
shoesName
,
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
){
//user情報取得、格納
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
//検索に当てはまる靴取得
List
<
Shoes
>
searchShoes
=
shoesService
.
findAllForSearch
(
shoesName
);
model
.
addAttribute
(
"searchShoes"
,
searchShoes
);
return
"list"
;
}
//サイズ検索用
public
String
searchBySize
(
@RequestParam
Integer
shoesSize
,
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
){
//user情報取得、格納
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
//検索に当てはまる靴取得
List
<
Shoes
>
searchShoes
=
shoesService
.
findAllBySize
(
shoesSize
);
model
.
addAttribute
(
"searchShoes"
,
searchShoes
);
return
"list"
;
}
//購入履歴画面
@GetMapping
(
"log/{id}"
)
public
String
history
(
@PathVariable
Integer
id
,
Model
model
,
SalesLog
salesLog
,
@AuthenticationPrincipal
LoginUser
userDetails
)
{
...
...
src/main/resources/templates/list.html
View file @
714a688c
...
...
@@ -115,10 +115,39 @@
</div>
<!-- end of/. row -->
</div>
<!-- end of /.container -->
</section>
<!-- end of /.news letter section -->
<!--一覧-->
<p
id=
"cart-p-text"
><span
id=
"cart-text"
>
Product List
</span></p>
<div
class=
"listBox"
id=
"limitedListBox"
>
<!--限定商品一覧-->
<!-- 検索 -->
<form
method=
"post"
name=
"form1"
th:action=
"@{/limited/search}"
>
<table>
<tr>
<td>
Search By Name
<input
type=
"text"
class=
"form-control"
id=
"shoes_name"
name=
"shoesName"
/></td>
<td><input
type=
"submit"
value=
"search"
/></td>
</tr>
</table>
</form>
<!--一覧-->
<p
id=
"cart-p-text"
><span
id=
"cart-text"
>
Product List
</span></p>
<!-- 検索された商品一覧 -->
<div
class=
"listBox"
>
<div
class=
"productBox"
th:each=
"searchShoes : ${searchShoes}"
>
<div
class=
"shoeImageDiv"
>
<img
class=
"shoeImage"
th:src=
"@{/upload/{photo}(photo=${searchShoes.photo})}"
alt=
"productImage"
width=
"300"
height=
"200"
/>
</div>
<p
th:text=
"${searchShoes.name}"
class=
"shoeName"
>
AirMAX
</p>
<p
th:text=
"${searchShoes.size} + ' cm'"
class=
"shoeSize"
></p>
<p
th:text=
"'¥' +${searchShoes.price}"
class=
"shoePrice"
>
¥10,000
</p>
<input
type=
"hidden"
th:value=
"${searchShoes.id}"
/>
<input
type=
"hidden"
th:value=
"${searchShoes.stock}"
/>
<div
class=
"detailsBtn"
>
<button
type=
"button"
id=
"modal-open"
class=
"details"
>
Datails
</button>
</div>
</div>
</div>
<!--限定商品一覧-->
<div
class=
"listBox"
id=
"limitedListBox"
>
<div
class=
"productBox"
th:each=
"limitedShoes : ${limitedShoes}"
>
<div
class=
"shoeImageDiv"
><img
class=
"shoeImage"
th:src=
"@{/upload/{photo}(photo=${limitedShoes.photo})}"
alt=
"productImage"
width=
"300"
height=
"200"
/></div>
<p
th:text=
"${limitedShoes.name}"
class=
"shoeName shoeLimited"
>
AirMAX
</p>
...
...
@@ -130,8 +159,8 @@
<!-- <button class="js-modal-open" id="sign-up">Details</button>-->
</div>
</div>
<!--一般商品一覧-->
<div
class=
"listBox"
>
<!--一般商品一覧-->
<div
class=
"productBox"
th:each=
"generalShoes : ${generalShoes}"
>
<div
class=
"shoeImageDiv"
><img
class=
"shoeImage"
th:src=
"@{/upload/{photo}(photo=${generalShoes.photo})}"
alt=
"productImage"
width=
"300"
height=
"200"
/></div>
<p
th:text=
"${generalShoes.name}"
class=
"shoeName"
>
AirMAX
</p>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment