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
f7b06b21
Commit
f7b06b21
authored
Oct 23, 2020
by
issei.miyajima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
検索機能
parent
9eeaf4ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
5 deletions
+82
-5
ShoesRepository.java
src/main/java/com/example/repository/ShoesRepository.java
+9
-0
ShoesService.java
src/main/java/com/example/service/ShoesService.java
+11
-0
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/com/example/repository/ShoesRepository.java
View file @
f7b06b21
...
...
@@ -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,4 +13,12 @@ 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
);
//商品名あいまい検索
@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
);
}
src/main/java/com/example/service/ShoesService.java
View file @
f7b06b21
...
...
@@ -49,4 +49,15 @@ public class ShoesService {
public
List
<
Shoes
>
findAllLimitedShoes
()
{
return
shoesRepository
.
findAllByStatus
(
1
);
}
//名前検索用
public
List
<
Shoes
>
findAllForSearch
(
String
shoesName
){
return
shoesRepository
.
findAllForSearch
(
shoesName
);
}
//サイズ検索用
public
List
<
Shoes
>
findAllBySize
(
Integer
shoesSize
){
return
shoesRepository
.
findAllBySize
(
shoesSize
);
}
}
src/main/java/com/example/web/EcsiteController.java
View file @
f7b06b21
...
...
@@ -13,12 +13,14 @@ 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
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
com.example.domain.Items
;
import
com.example.domain.SalesLog
;
...
...
@@ -126,6 +128,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 @
f7b06b21
...
...
@@ -114,10 +114,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>
...
...
@@ -129,8 +158,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