<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>product</title>
</head>
<body style="font-size: 30px">
<form action="addProduct" >
产品名称:<input type="text" name="name" value="" ><br>
产品价格:<input type="text" name="price" value=""><br>
<input type="submit" value="增加商品">
</form>
</body>
</html>
package com.example.demo.work1;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Product2 {
private String name;
private Float price;
public String getName(){
return name;
}
public Float getPrice() {
return price;
}
public void setName(String name) {
this.name = name;
}
public void setPrice(Float price) {
this.price = price;
}
@RequestMapping("/addProduct")
public String Product(String name,Float price){
System.out.println("您输入的信息是:"+name+":"+price);
return "OK";
}
}
![](https://img-blog.csdnimg.cn/direct/0f79d9b8f51143beb5207812b9982b3e.png)
![](https://img-blog.csdnimg.cn/direct/8f9bcf7d5db94f53947131cf6ce5ed13.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="information">
请输入用户姓名:<input type="text" name="name" value=""><br>
选择性别:
<input type="radio" name="sex" value="男">男
<input type="radio" name="sex" value="女">女<br>
选择密码提示问题:<select name="question">
<option value="母亲生日">母亲生日</option>
<option value="宠物名称">宠物名称</option>
<option value="电脑配置">电脑配置</option>
</select><br>
请输入问题答案:<input type="text" name="answer" value=""><br>
请选择个人爱好:<br>
<input type="checkbox" name="like" value="dance">唱歌跳舞
<input type="checkbox" name="like" value="dance">上网冲浪
<input type="checkbox" name="like" value="dance">户外登山<br>
<input type="checkbox" name="like" value="dance">体育运动
<input type="checkbox" name="like" value="dance">读书看报
<input type="checkbox" name="like" value="dance">欣赏电影<br>
<input type="submit" value="提交">
</form>
</body>
</html>
package com.example.demo.work1;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Information {
private String name;
private String sex;
private String question;
private String answer;
private String like[];
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public String[] getLike() {
return like;
}
public void setLike(String[] like) {
this.like = like;
}
@Override
public String toString() {
return "Information{" +
"name='" + name + '\'' +
", sex='" + sex + '\'' +
", question='" + question + '\'' +
", answer='" + answer + '\'' +
", like=" + Arrays.toString(like) +
'}';
}
@RequestMapping("/information")
public String getInformatuon(Information information){
System.out.println(information);
return "OK";
}
}
![](https://img-blog.csdnimg.cn/direct/309b18d71c6a4941aaf95c6b63445935.png)
![](https://img-blog.csdnimg.cn/direct/abc94a5bd144478ebe320037452f3bfb.png)