写一个springmvc最基础的调查表
时间: 2024-01-16 11:44:34 浏览: 31
抱歉,作为AI语言模型,我无法提供可视化的代码,但是我可以给您提供一个基本的Spring MVC的调查表的代码框架,您可以按照此框架进行代码编写和修改。
Controller层:
```
package com.example.demo.controller;
import com.example.demo.model.Survey;
import com.example.demo.service.SurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller
public class SurveyController {
@Autowired
private SurveyService surveyService;
@GetMapping("/survey")
public String showSurveyForm(Model model) {
model.addAttribute("survey", new Survey());
return "survey-form";
}
@PostMapping("/survey")
public String submitSurveyForm(@ModelAttribute Survey survey) {
surveyService.saveSurvey(survey);
return "survey-confirmation";
}
}
```
Model层:
```
package com.example.demo.model;
public class Survey {
private String name;
private String email;
private String age;
private String gender;
public Survey() {}
public Survey(String name, String email, String age, String gender) {
this.name = name;
this.email = email;
this.age = age;
this.gender = gender;
}
// getter and setter methods
}
```
View层:
survey-form.html
```
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Survey Form</title>
</head>
<body>
<h1>Survey Form</h1>
<form action="#" th:action="@{/survey}" th:object="${survey}" method="post">
<p>Name: <input type="text" th:field="*{name}"></p>
<p>Email: <input type="email" th:field="*{email}"></p>
<p>Age: <input type="number" th:field="*{age}"></p>
<p>Gender: <input type="radio" th:field="*{gender}" value="male">Male
<input type="radio" th:field="*{gender}" value="female">Female</p>
<button type="submit">Submit</button>
</form>
</body>
</html>
```
survey-confirmation.html
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Survey Confirmation</title>
</head>
<body>
<h1>Survey Confirmation</h1>
<p>Thank you for completing the survey.</p>
</body>
</html>
```
以上是一个简单的Spring MVC调查表的示例,其中包括了Controller层、Model层和View层的代码。您可以根据自己的需求进行修改和扩展。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)