こんにちは私は、Javaのコーディングには新しく、いくつかのオンラインチュートリアルを経て、私は春のMVCで小さなプロジェクトを書くことができました。アプリケーション名、ホスト名(実行中の場所)、アプリケーションタイプ、環境タイプ(DEV、TEST、QA、PROD)のようなアプリケーションリポジトリをmysqlテーブルに格納し、同じ情報をフォームのWebページに取得できるWebアプリケーションを構築するテーブルの私はこの部分を達成するのに成功しましたが、Webページ(テーブル情報はmysql dbからフェッチされました)に表示されたテーブルの上部に検索フィールドを持っている次のステップで立ち往生しました。そこでキーワードやテキストを入力すればdbを検索し、テーブルの結果を取得します(同じページ)。Webページのmysqlデータベースの結果を表示するためにJava Webページのフィールドを検索
この表
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE>
<html>
<head>
<link type="text/css" rel="stylesheet" href="<c:url value="resources/style.css" />" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Client Management</title>
</head>
<body>
<h1>Client Data</h1>
<div >
<form:form method="POST" commandName="client">
<table class="myTable myTable-zebra myTable-horizontal">
<thead>
<tr>
<th>Application Name</th>
<th>Client Type</th>
<th>Client Name</th>
<th>Hostname</th>
<th>Environment</th>
</tr>
</thead>
<c:forEach items="${clientList}" var="client">
<tr>
<td>${client.applicationname}</td>
<td>${client.clienttype}</td>
<td>${client.clientname}</td>
<td>${client.hostname}</td>
<td>${client.envtype}</td>
</tr>
</c:forEach>
</tbody>
</table>
</form:form>
</div>
</body>
</html>
を表示私が今持っているもの enter image description here
JSPページでコントローラー
package com.webappdemo01.controller;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.webappdemo01.model.Client;
import com.webappdemo01.service.ClientService;
@Controller
public class ClientController {
@Autowired
private ClientService clientService;
@RequestMapping(value = "/AdminPage", method = RequestMethod.GET)
public String adminpage() {
return "AdminPage";
}
@RequestMapping("/addclient")
public String setupForm(Map<String, Object> map){
Client client = new Client();
map.put("client", client);
map.put("clientList", clientService.getAllClient());
return "client";
}
@RequestMapping(value="/client.do", method=RequestMethod.POST)
public String doActions(@ModelAttribute Client client, BindingResult result, @RequestParam String action, Map<String, Object> map){
Client clientResult = new Client();
switch(action.toLowerCase()){
case "add":
clientService.add(client);
clientResult = client;
break;
case "edit":
clientService.edit(client);
clientResult = client;
break;
case "delete":
clientService.delete(client.getClientname());
clientResult = new Client();
break;
case "search":
Client searchedClient = clientService.getClient(client.getClientname());
clientResult = searchedClient!=null ? searchedClient : new Client();
break;
}
map.put("client", clientResult);
return "ClientAddSuccess";
}
@RequestMapping("/clientlist")
public String clientPage(Map<String, Object> map){
Client client = new Client();
map.put("client", client);
map.put("clientList", clientService.getAllClient());
return "clientlist";
}
}
今、私が取得するために一番上に検索フィールドを持つようにしたいですdbの結果とウェブページの同じテーブルに表示されます。