2015-10-07 28 views
0

我的表格中我有表格顯示一些客戶data.user可以點擊行查看所有的客戶數據。春天mvc返回ajax後的modelandview調用

<div class="container"> 
    <table class="table table-bordered" style="direction: rtl"> 
     <thead> 
     <tr> 
      <th style="text-align: center">customer name</th> 
      <th style="text-align: center">customer ID</th> 
     </tr> 
     </thead> 
     <tbody> 
     <c:forEach items="${customers}" var="customer" varStatus="loop"> 
      <tr onclick="retrieveCustomer('${loop.index}')"> 
       <td id="id-${loop.index}">${customer.customerId}</td> 
       <td>${customer.customerName}</td> 
      </tr> 
     </c:forEach> 
     </tbody> 
    </table> 
</div> 

<script> 
    function retrieveCustomer(id) { 
     debugger; 
     $.ajax({ 
      url: "<%=request.getContextPath()%>/show_selected_customer", 
      data: {customerId: $('#id-' + id).text()}, 
      type: "GET", 

      success: function (response) { 
      }, 
      error: function (xhr, status, error) { 
       alert(error); 
      } 
     }); 
    }; 
</script> 

,並在我的控制器:

@RequestMapping(value = "/show_selected_customer", method = RequestMethod.GET) 
public ModelAndView showSelectedCustomer(@RequestParam("customerId") String customerId) { 
    Map<String, Object> model = new HashMap<>(); 
    Customer customer = coreService.getCustomer(customerId); 
    model.put("customer", customer); 

    return new ModelAndView("showCustomerData", model); 
} 

瓷磚:

<definition name="showCustomerData" extends="base.definition"> 
    <put-attribute name="title" value="customer data"/> 
    <put-attribute name="content" value="/WEB-INF/jsp/show_customer_data.jsp"/> 
</definition> 

到現在的每一件事情正常工作。 enter image description here

我的問題是,它不顯示show_customers.jsp頁面,甚至我沒有在我的日誌中的錯誤。 我的問題是什麼,是因爲ajax調用?我沒有使用@responsebody,並且想要使用return modelandview顯示customers.jsp頁面。謝謝

+0

你可以顯示你的Controller類定義嗎? – Arpit

+0

@Controller public class AdminController private final Logger logger = .. – farhad

回答

0

使用響應主體註釋並將您的實體轉換爲JSON並返回它。