springboot怎么把数据传给前端:springboot 如何引入前端 bootstrap?
这种问题网上一搜一大堆,你可以具体找一篇文章试试,遇到问题可以针对相关问题去提问。springboot通过jar包方式引入bootstrap_个人文章 - SegmentFault 思否 这不是查查就
顺晟科技
2022-10-19 12:50:06
25
我试图创建一个编辑页面,在该页面中使用PHP从MySQL读取数据,然后以HTML显示数据。 像VARCHAR这样的普通字段可以正确显示,但我在显示文本字段时有困难。
<?php
$DATABASE_HOST = '';
$DATABASE_USER = '';
$DATABASE_PASS = '';
$DATABASE_NAME = '';
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$idjob = $_POST['jobID'];
$jobquery = $mysqli->prepare('SELECT * FROM jobs WHERE id = ?');
$jobquery->bind_param('s', $idjob); // 's' specifies the variable type => 'string'
$jobquery->execute();
$jobresult = $jobquery->get_result();
while ($row = $jobresult->fetch_assoc()) {
$jobtitle = $row['jobtitle'];
$workhours = $row['workhours'];
$type = $row['type'];
$availfrom = $row['availfrom'];
$deadline = $row['deadline'];
$customer = $row['customer'];
$province = $row['province'];
$town = $row['town'];
$minreq = $row['minreq'];
$posdetails = $row['posdetails'];
$minsal = $row['minsal'];
$maxsal = $row['maxsal'];
}
mysqli_free_result($jobresult);
mysqli_close($mysqli);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Edit Job Listing</title>
<link rel="shortcut icon" type="image/jpg" href="images/Logo.jpg">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0 shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="../assets/css/style.css" type="text/css"/>
</head>
<body id="editjoblisting">
<!-- Container (About Add New Job Listing Section) -->
<div id="abouteditnewjob" class="container-fluid bg-grey">
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<div class="text-center">
<h2> Edit Job Listing </h2>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</div>
<div class="container-fluid bg-grey">
<form method="post" id="updedit_form" action="../php/updeditjob.php">
<div class="form-row">
<div class="col-sm-2"></div>
<div class="col-sm-4">
<div class="form-group">
<label for="jobtitle"> Job Title</label>
<input type="text" class="form-control" name="jobtitle" value='<?php echo $jobtitle; ?>'>
<label for="workhours"> Working Hours</label>
<input type="text" class="form-control" name="workhours" value='<?php echo $workhours; ?>'>
<label for="worktype">Type</label>
<select class="form-control" name="worktype" >
<option value='<?php echo $type; ?>' selected><?php echo $type; ?></option>
<option>--None--</option>
<option>Temporary</option>
<option>Permanent</option>
</select>
<label for="availfrom"> Available From</label>
<input type="date" class="form-control" id="availfrom" name="availfrom" required maxlength="50" value='<?php echo $availfrom; ?>'>
<label for="deadline"> Application Deadline</label>
<input type="date" class="form-control" id="deadline" name="deadline" required maxlength="50" value='<?php echo $deadline; ?>'>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="minreq">Minimum Requirements</label>
<textarea class="form-control" type="textarea" name="minreq" id="minreq" maxlength="6000" rows="5" value='<?php echo $minreq; ?>'></textarea>
<label for="posdetails">Position Details</label>
<textarea class="form-control" type="textarea" name="posdetails" id="posdetails" maxlength="6000" rows="5" value='<?php echo $posdetails; ?>'></textarea>
<label for="minsal"> Minimum Salary</label>
<input type="text" class="form-control" id="minsal" name="minsal" value='<?php echo $minsal; ?>'>
<label for="maxsal"> Maximum Salary</label>
<input type="text" class="form-control" id="maxsal" name="maxsal" value='<?php echo $maxsal; ?>'>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</form>
</div>
</body>
</html>
这是我试图显示/编辑的数据。
<?php
$DATABASE_HOST = '';
$DATABASE_USER = '';
$DATABASE_PASS = '';
$DATABASE_NAME = '';
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$idjob = $_POST['jobID'];
$jobquery = $mysqli->prepare('SELECT * FROM jobs WHERE id = ?');
$jobquery->bind_param('s', $idjob); // 's' specifies the variable type => 'string'
$jobquery->execute();
$jobresult = $jobquery->get_result();
while ($row = $jobresult->fetch_assoc()) {
$jobtitle = $row['jobtitle'];
$workhours = $row['workhours'];
$type = $row['type'];
$availfrom = $row['availfrom'];
$deadline = $row['deadline'];
$customer = $row['customer'];
$province = $row['province'];
$town = $row['town'];
$minreq = $row['minreq'];
$posdetails = $row['posdetails'];
$minsal = $row['minsal'];
$maxsal = $row['maxsal'];
}
mysqli_free_result($jobresult);
mysqli_close($mysqli);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Edit Job Listing</title>
<link rel="shortcut icon" type="image/jpg" href="images/Logo.jpg">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0 shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="../assets/css/style.css" type="text/css"/>
</head>
<body id="editjoblisting">
<!-- Container (About Add New Job Listing Section) -->
<div id="abouteditnewjob" class="container-fluid bg-grey">
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<div class="text-center">
<h2> Edit Job Listing </h2>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</div>
<div class="container-fluid bg-grey">
<form method="post" id="updedit_form" action="../php/updeditjob.php">
<div class="form-row">
<div class="col-sm-2"></div>
<div class="col-sm-4">
<div class="form-group">
<label for="jobtitle"> Job Title</label>
<input type="text" class="form-control" name="jobtitle" value='<?php echo $jobtitle; ?>'>
<label for="workhours"> Working Hours</label>
<input type="text" class="form-control" name="workhours" value='<?php echo $workhours; ?>'>
<label for="worktype">Type</label>
<select class="form-control" name="worktype" >
<option value='<?php echo $type; ?>' selected><?php echo $type; ?></option>
<option>--None--</option>
<option>Temporary</option>
<option>Permanent</option>
</select>
<label for="availfrom"> Available From</label>
<input type="date" class="form-control" id="availfrom" name="availfrom" required maxlength="50" value='<?php echo $availfrom; ?>'>
<label for="deadline"> Application Deadline</label>
<input type="date" class="form-control" id="deadline" name="deadline" required maxlength="50" value='<?php echo $deadline; ?>'>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="minreq">Minimum Requirements</label>
<textarea class="form-control" type="textarea" name="minreq" id="minreq" maxlength="6000" rows="5" value='<?php echo $minreq; ?>'></textarea>
<label for="posdetails">Position Details</label>
<textarea class="form-control" type="textarea" name="posdetails" id="posdetails" maxlength="6000" rows="5" value='<?php echo $posdetails; ?>'></textarea>
<label for="minsal"> Minimum Salary</label>
<input type="text" class="form-control" id="minsal" name="minsal" value='<?php echo $minsal; ?>'>
<label for="maxsal"> Maximum Salary</label>
<input type="text" class="form-control" id="maxsal" name="maxsal" value='<?php echo $maxsal; ?>'>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</form>
</div>
</body>
</html>
除了minreq(在MySQL中是一个文本字段)之外,所有内容都工作得很好。它没有显示,但echo显示它是在$row数组中检索的。
顺晟科技:
请删除文本区域中的值,并按以下方式编写代码:
尝试回显textarea标记之间的值,而不是value属性中的值:
<?php
$DATABASE_HOST = '';
$DATABASE_USER = '';
$DATABASE_PASS = '';
$DATABASE_NAME = '';
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if ( mysqli_connect_errno() ) {
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
$idjob = $_POST['jobID'];
$jobquery = $mysqli->prepare('SELECT * FROM jobs WHERE id = ?');
$jobquery->bind_param('s', $idjob); // 's' specifies the variable type => 'string'
$jobquery->execute();
$jobresult = $jobquery->get_result();
while ($row = $jobresult->fetch_assoc()) {
$jobtitle = $row['jobtitle'];
$workhours = $row['workhours'];
$type = $row['type'];
$availfrom = $row['availfrom'];
$deadline = $row['deadline'];
$customer = $row['customer'];
$province = $row['province'];
$town = $row['town'];
$minreq = $row['minreq'];
$posdetails = $row['posdetails'];
$minsal = $row['minsal'];
$maxsal = $row['maxsal'];
}
mysqli_free_result($jobresult);
mysqli_close($mysqli);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Edit Job Listing</title>
<link rel="shortcut icon" type="image/jpg" href="images/Logo.jpg">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0 shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="../assets/css/style.css" type="text/css"/>
</head>
<body id="editjoblisting">
<!-- Container (About Add New Job Listing Section) -->
<div id="abouteditnewjob" class="container-fluid bg-grey">
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<div class="text-center">
<h2> Edit Job Listing </h2>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</div>
<div class="container-fluid bg-grey">
<form method="post" id="updedit_form" action="../php/updeditjob.php">
<div class="form-row">
<div class="col-sm-2"></div>
<div class="col-sm-4">
<div class="form-group">
<label for="jobtitle"> Job Title</label>
<input type="text" class="form-control" name="jobtitle" value='<?php echo $jobtitle; ?>'>
<label for="workhours"> Working Hours</label>
<input type="text" class="form-control" name="workhours" value='<?php echo $workhours; ?>'>
<label for="worktype">Type</label>
<select class="form-control" name="worktype" >
<option value='<?php echo $type; ?>' selected><?php echo $type; ?></option>
<option>--None--</option>
<option>Temporary</option>
<option>Permanent</option>
</select>
<label for="availfrom"> Available From</label>
<input type="date" class="form-control" id="availfrom" name="availfrom" required maxlength="50" value='<?php echo $availfrom; ?>'>
<label for="deadline"> Application Deadline</label>
<input type="date" class="form-control" id="deadline" name="deadline" required maxlength="50" value='<?php echo $deadline; ?>'>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="minreq">Minimum Requirements</label>
<textarea class="form-control" type="textarea" name="minreq" id="minreq" maxlength="6000" rows="5" value='<?php echo $minreq; ?>'></textarea>
<label for="posdetails">Position Details</label>
<textarea class="form-control" type="textarea" name="posdetails" id="posdetails" maxlength="6000" rows="5" value='<?php echo $posdetails; ?>'></textarea>
<label for="minsal"> Minimum Salary</label>
<input type="text" class="form-control" id="minsal" name="minsal" value='<?php echo $minsal; ?>'>
<label for="maxsal"> Maximum Salary</label>
<input type="text" class="form-control" id="maxsal" name="maxsal" value='<?php echo $maxsal; ?>'>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</form>
</div>
</body>
</html>
05
2022-12
02
2022-12
02
2022-12
29
2022-11
29
2022-11
24
2022-11