一:HelloController
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//请求处理类
@RestController
public class HelloController {
@RequestMapping("/hello!")
public String hello(){
System.out.println("Hello World~");
return "Hello World~";
}
}
二:postman练习
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
//请求处理类
@RestController
public class HelloController {
@RequestMapping("/hello!")
public String simpleParam(HttpServletRequest request){
String name = request.getParameter("name");
String ageStr = request.getParameter("age");
int age = Integer.parseInt(ageStr);
System.out.println(name+":"+age);
return "OK";
}
}
package com.example.javaweb.pojo;
public class Address {
private String Province;
private String City;
@Override
public String toString() {
return "Address{" +
"Province='" + Province + '\'' +
", City='" + City + '\'' +
'}';
}
public String getProvince() {
return Province;
}
public void setProvince(String province) {
Province = province;
}
public String getCity() {
return City;
}
public void setCity(String city) {
City = city;
}
}
package com.example.javaweb.Controller;
import com.example.javaweb.pojo.Address;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ResponseController {
@RequestMapping("/getAddr")
public Address gtAddr()
{
Address addr=new Address();
addr.setProvince("GD");
addr.setCity("SZ");
return addr;
}
}
三,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body style="font-size: 30px">
<form action="/form">
<ul style="list-style: none; line-height: 30px">
<li>
输入用户姓名:
<input type="text" name="name" />
<br />
</li>
<li>
选择性别:
<input name="sex" type="radio" value="boy" />
男
<input name="sex" type="radio" value="girl" />
女
</li>
<li>
选择密码提示问题:
<select name="question">
<option value="母亲生日">
母亲生日
</option>
<option value="宠物名称">
宠物名称
</option>
<option value="电脑配置">
电脑配置
</option>
</select>
</li>
<li>
请输入问题答案:
<input type="text" name="key" />
</li>
<li>
请选择个人爱好:
<div style="width: 400px">
<input name="like" type="checkbox" value="dangce" />
唱歌跳舞
<input name="like" type="checkbox" value="web" />
上网冲浪
<input name="like" type="checkbox" value="hill" />
户外登山
<br />
<input name="like" type="checkbox" value="sports" />
体育运动
<input name="like" type="checkbox" value="reading" />
读书看报
<input name="like" type="checkbox" value="movie" />
欣赏电影
</div>
</li>
<li>
<input type="submit" value="提交" />
</li>
</ul>
</form>
</body>
</html>
package com.example.javaweb.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.javaweb.pojo.Information;
@RestController
public class FormController {
@RequestMapping("/form")
public String FormAdd(Information information){
System.out.println(information);
return "ok";
}
}
package com.example.javaweb.pojo;
import java.util.Arrays;
public class Information {
private String sex;
private String []like;
private String mail;
private String name;
public String getName() {
return name;
}
@Override
public String toString() {
return "Information{" +
"name='" + name + '\'' +
", sex='" + sex + '\'' +
", like=" + Arrays.toString(like) +
", mail='" + mail + '\'' +
'}';
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String[] getLike() {
return like;
}
public void setLike(String[] like) {
this.like = like;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
}