写出vue根据后端审核状态的值,来显示审核按钮的隐藏与显示的前端代码,并且写出java后端的代码
时间: 2024-02-26 08:58:05 浏览: 22
前端代码:
```
<button v-if="status === '待审核'" @click="submitForReview">提交审核</button>
<button v-if="status === '审核中'" disabled>审核中</button>
<button v-if="status === '已通过'" disabled>已通过</button>
<button v-if="status === '未通过'" @click="submitForReview">重新提交审核</button>
```
Java后端代码:
```
public class MyController {
@GetMapping("/getReviewStatus")
public String getReviewStatus() {
// 假设从数据库中获取审核状态
String status = reviewService.getStatus();
return status;
}
}
```
相关问题
写出根据学号,姓名使用vue实现按钮查询功能的前端代码,并且使用java语言写出后端代码
前端代码:
```html
<template>
<div>
<input v-model="queryName" placeholder="姓名">
<input v-model="queryId" placeholder="学号">
<button @click="query">查询</button>
<div>{{result}}</div>
</div>
</template>
<script>
export default {
data() {
return {
queryName: '',
queryId: '',
result: ''
}
},
methods: {
async query() {
const response = await fetch(`/api/query?name=${this.queryName}&id=${this.queryId}`)
const data = await response.json()
this.result = data.result
}
}
}
</script>
```
后端代码:
```java
import java.util.HashMap;
import java.util.Map;
import static spark.Spark.get;
import static spark.Spark.port;
public class Main {
public static void main(String[] args) {
port(8080);
Map<String, String> studentMap = new HashMap<>();
studentMap.put("20210001", "张三");
studentMap.put("20210002", "李四");
get("/api/query", (req, res) -> {
String name = req.queryParams("name");
String id = req.queryParams("id");
String result = "未找到该学生";
if (studentMap.containsKey(id) && studentMap.get(id).equals(name)) {
result = "姓名:" + name + ",学号:" + id;
}
Map<String, String> resultMap = new HashMap<>();
resultMap.put("result", result);
return resultMap;
}, JsonUtil.json());
}
}
```
请注意,这只是一份简单的样例代码,实际项目中需要根据具体需求进行修改和完善。
写出根据学号,姓名使用vue实现按钮查询功能的前端代码,需要联动后端数据库,并且使用java语言写出后端代码
前端代码:
```html
<template>
<div>
<label>
学号:
<input type="text" v-model="id" />
</label>
<label>
姓名:
<input type="text" v-model="name" />
</label>
<button @click="search">查询</button>
<div v-if="result">{{ result }}</div>
</div>
</template>
<script>
export default {
data() {
return {
id: '',
name: '',
result: '',
};
},
methods: {
search() {
// 根据学号和姓名查询后端接口
fetch(`/api/search?id=${this.id}&name=${this.name}`)
.then((res) => res.json())
.then((data) => {
this.result = data.result;
});
},
},
};
</script>
```
后端代码:
```java
import java.sql.*;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
public class Server {
private static final String JDBC_URL = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC";
private static final String JDBC_USERNAME = "root";
private static final String JDBC_PASSWORD = "root";
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/api/search", new SearchHandler());
server.setExecutor(null);
server.start();
}
static class SearchHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
String query = exchange.getRequestURI().getQuery();
String[] params = query.split("&");
String id = null;
String name = null;
for (String param : params) {
String[] pair = param.split("=");
if (pair[0].equals("id")) {
id = pair[1];
} else if (pair[0].equals("name")) {
name = pair[1];
}
}
String result = null;
try (Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD)) {
String sql = "SELECT * FROM students WHERE id=? AND name=?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, id);
stmt.setString(2, name);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
result = "查询成功";
} else {
result = "查询失败";
}
}
}
} catch (SQLException e) {
e.printStackTrace();
result = "查询出错";
}
String response = "{\"result\": \"" + result + "\"}";
exchange.sendResponseHeaders(200, response.length());
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
}
```
需要注意的是,这里使用了MySQL数据库,需要提前安装MySQL并创建名为`test`的数据库,以及名为`students`的表并插入一些数据。如果使用其他类型的数据库,需要根据实际情况修改JDBC连接URL和用户名密码等参数。