ショッピングサイトのかごシステムを作っていまして、
個数を指定、次の画面に遷移した際に在庫が足りなければエラーページに行かせたいです。
しかし、比較がうまくいかず、以下の文では文字列を演算子で処理できないと出ます。
OrderRegistCustomerContoller
1@Controller 2public class OrderRegistCustomerContoller { 3 4 @Autowired 5 HttpSession session; 6 7 @Autowired 8 OrderItemRepository orderItemRepository; 9 10 @Autowired 11 OrderRepository orderRepository; 12 13 @Autowired 14 UserRepository userRepository; 15 16 @RequestMapping(path = "/address/input", method = RequestMethod.POST) 17 public String oderRegistAddressInput(Model model, @ModelAttribute BasketForm basketForm, UserForm userForm){ 18 Order order = orderRepository.getOne(userForm.getId()); 19 OrderBean orderBean = new OrderBean(); 20 21 BeanUtils.copyProperties(order, orderBean); 22 23 model.addAttribute("order", orderBean); 24 25/** 26ここで比較しようとしています。 27*/ 28 29 if("${Basket.stock}"<="${item.stock}"){ 30 return "order/regist/address_input"; 31 } 32 } 33 34}
basket_list.html
1<!DOCTYPE html> 2 3<html xmlns:th="http://www.thymeleaf.org" 4 xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 5 layout:decorator="common/layout_5block"> 6<head></head> 7<body class="user shopping_basket"> 8 <th:block layout:fragment="layout-main" > 9 <h2 class="title" >買い物かご</h2> 10 <div th:if="${session.basketList == 1}"> 11 <p>現在、お客様の買い物かごには商品がありません。商品をお選びください。</p> 12 </div> 13 <table class="list_table basket" th:if="${session.basketList == 0}"> 14 <tr> 15 <th>商品名</th> 16 <th>個数</th> 17 <th>操作</th> 18 </tr> 19 20 <tr th:each = "Basket: ${session.basket}"> 21 <td><a th:href="@{/item/detail/{id}(id=${Basket.id})}" th:text = "${Basket.name}" ></a></td> 22 <td th:text = "${Basket.stock}"></td> 23 <td > 24 <form method="post" th:action="@{/basket/subtractcount}"> 25 <input type="hidden" name="id" th:value="${Basket.id}" /> 26 <input type="hidden" name="orderNum" th:value="${Basket.stock}" /> 27 <input type="submit" value="個数-1" /> 28 </form> 29 <form method="post" th:action="@{/basket/addcount}"> 30 <input type="hidden" name="id" th:value="${Basket.id}" /> 31 <input type="hidden" name="orderNum" th:value="${Basket.stock}" /> 32 <input type="submit" value="個数+1" /> 33 </form> 34 <form method="post" th:action="@{/basket/delete}"> 35 <input type="hidden" name="id" th:value="${Basket.id}" /> 36 <input type="submit" value="削除" class="delete" /> 37 </form> 38 </td> 39 </tr> 40 </table> 41 42 43 <div class="user_info_form_area" th:if="${session.basketList == 0}"> 44 45 <form method="post" th:action="@{/address/input}" > 46 <span> 47 <input type="hidden" name="itemId" value="1" /> 48 <input type="hidden" name="orderNum" value="1" /> 49 <input type="hidden" name="id" th:value="${session.user.id}" /> 50 </span> 51 <input type="submit" value="ご注文のお手続き" /> 52 </form> 53 54 <form method="post" th:action="@{/basket/allDelete/}"> 55 <input type="submit" value="買い物かごを空にする" class="delete" /> 56 </form> 57 </div> 58 </th:block> 59</body> 60</html> 61
address_input.html
1<!DOCTYPE html> 2 3<html xmlns:th="http://www.thymeleaf.org" 4 xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 5 layout:decorator="common/layout_5block"> 6<head> 7 <title>お届け先入力 </title> 8</head> 9<body class="user order_list"> 10 <th:block layout:fragment="layout-main"> 11 <h2 class="title">お届け先入力</h2> 12 <div class="user_info_form_area"> 13 <form method="post" th:action="@{/payment/input}"> 14 <ul class="input_list"> 15 <li> 16 <label> 17 <span class="input_title">郵便番号</span> 18 <input type="text" name="postalCode" th:value="${order.postalCode}" /> 19 </label> 20 21 </li> 22 <li> 23 <label> 24 <span class="input_title">住所</span> 25 <textarea name="address" rows="6" th:text="${order.address}"></textarea> 26 </label> 27 28 </li> 29 <li> 30 <label> 31 <span class="input_title">氏名</span> 32 <input type="text" name="name" th:value="${order.name}" /> 33 </label> 34 35 </li> 36 <li> 37 <label> 38 <span class="input_title">電話番号</span> 39 <input type="text" name="phoneNumber" th:value="${order.phoneNumber}" /> 40 </label> 41 42 </li> 43 </ul> 44 <input type="hidden" name="id" th:value="${session.user.id}" /> 45 <input type="submit" value="次へ" class="send_button" /> 46 </form> 47 <form th:action="@{/basket/list/1}"> 48 <input type="submit" value="戻る" class="back_button" /> 49 </form> 50 </div> 51 52 53</th:block> 54</body> 55</html> 56
item_detail.html
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org" 3 xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 4 layout:decorator="common/layout_4block"> 5<head> 6<title>商品詳細</title> 7</head> 8<body class="user item_detail"> 9 <th:block layout:fragment="layout-main"> 10 <h2 class="title">商品詳細</h2> 11 <div class="item_info_form_area"> 12 <div class="item_detail_area"> 13 <div class="item_image_area"> 14 <span th:if="${item.image != null}"> 15 <img th:src="@{/img/{image}(image=${item.image})}"></img> 16 </span> 17 <span th:if="${item.image == null}"> 18 <img th:src="@{/img/common/no_image.jpg}"></img> 19 </span> 20 </div> 21 <dl class="item_detail_list"> 22 <dt>商品名:</dt> 23 <dd th:text="${item.name}"></dd> 24 <dt>価格:</dt> 25 <dd th:text="${item.price}"></dd> 26 <dt>在庫:</dt> 27 <dd th:text="${item.stock}" th:if = "${item.stock != 0}"></dd> 28 <dd th:text="在庫なし" th:if = "${item.stock == 0}"></dd> 29 <dt>カテゴリ:</dt> 30 <dd th:text="${item.category.name}"></dd> 31 <dt>説明:</dt> 32 <dd th:text="${item.description}"></dd> 33 </dl> 34 </div> 35 <form method="post" class="user_info_form" th:action="@{/basket/add}"> 36 <input type="hidden" name="id" th:value="${item.id}" /> 37 <input type="hidden" name="name" th:value="${item.name}" /> 38 <input type="submit" value="買い物かごに入れる" class="send_button" /> 39 </form> 40 <form th:action="@{/}"> 41 <input type="submit" value="戻る" class="back_button" /> 42 </form> 43 </div> </th:block> 44 45</body> 46</html>
回答1件
あなたの回答
tips
プレビュー