servlet
为什么需要Servlet
使用JSP技术如何编写服务器动态网页?
什么是Servlet
定义
Servlet 是一个 Java程序,是在服务器上运行以处理客户端请求并做出响应的程序
Servlet生命周期 示例
Servlet的生命周期由Servlet容器(如:Tomcat)控制,主要有以下阶段:
实例化
初始化
服务
如果请求 Servlet,则容器调用 service() 方法
销毁
HelloServlet // 导入必需的 java 库
import java.io.IOException ;
import jakarta.servlet.ServletConfig ;
import jakarta.servlet.ServletException ;
import jakarta.servlet.http.HttpServlet ;
import jakarta.servlet.http.HttpServletRequest ;
import jakarta.servlet.http.HttpServletResponse ;
//扩展 HttpServlet 类
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L ;
public HelloServlet () {
// 执行必需的初始化
}
public void init ( ServletConfig config ) throws ServletException {
}
public void destroy () {
}
protected void service ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
response . getWriter (). append ( "Served at: " ). append ( request . getContextPath ());
}
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
response . getWriter (). append ( "Served at: " ). append ( request . getContextPath ());
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
Servlet定义
创建Servlet分两步:
创建Servlet类
URL映射
建立Servlet业务类与URL地址之间的映射关系
创建Servlet类
HelloAnnotationServlet @WebServlet ( "/HelloAnnotation" ) // 映射URL
public class HelloAnnotationServlet extends HttpServlet {
protected void service ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
response . getWriter (). append ( "Served at: " ). append ( request . getContextPath ());
}
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
response . getWriter (). append ( "Served at: " ). append ( request . getContextPath ());
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
源代码
HelloAnnotationServlet // 导入必需的 java 库
import java.io.IOException ;
import jakarta.servlet.ServletConfig ;
import jakarta.servlet.ServletException ;
import jakarta.servlet.annotation.WebServlet ;
import jakarta.servlet.http.HttpServlet ;
import jakarta.servlet.http.HttpServletRequest ;
import jakarta.servlet.http.HttpServletResponse ;
//扩展 HttpServlet 类
@WebServlet ( "/HelloAnnotation" ) // 映射URL
public class HelloAnnotationServlet extends HttpServlet {
private static final long serialVersionUID = 1L ;
public HelloAnnotationServlet () {
// 执行必需的初始化
}
public void init ( ServletConfig config ) throws ServletException {
}
public void destroy () {
}
protected void service ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
response . getWriter (). append ( "Served at: " ). append ( request . getContextPath ());
}
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
response . getWriter (). append ( "Served at: " ). append ( request . getContextPath ());
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
URL映射
Servlet有两种映射方式:注解、web.xml
Servlet与JSP关系
Servlet与JSP之间的关系
Servlet应用流程
前台页面的创建
后台Servlet的创建
示例
登录
CRUD操作
为了实现代码的可维护性、可扩展性和可测试性。分层架构将系统分解为不同的层次,每个层次都有明确的职责和功能。通常将应用程序分为四个层次结构:控制层、服务层、数据访问层和实体层。
graph TD;
subgraph 上层应用
A[Web App] -->|请求和响应| B[控制层];
C[Web Api] -->|请求和响应| B[控制层];
D[App] -->|请求和响应| B[控制层];
end
subgraph 系统层次
B[控制层] -->|业务服务功能| E[服务层];
E[服务层] -->|数据存储交互| F[数据访问层];
F[数据访问层] -->|业务实体| G[域模型层];
style B fill:#f9f,stroke:#333,stroke - width:2px
style E fill:#a9f,stroke:#333,stroke - width:2px
style F fill:#9ff,stroke:#333,stroke - width:2px
style G fill:#99f,stroke:#333,stroke - width:2px
note[Spring MVC, Servlet/JSP] --> B
note2[Spring] --> E
note3[MyBatis, Hibernate, JDBC] --> F
note4[POJO] --> G
end
下面是基于Servlet 的实现这些层级的详细介绍:
控制层 :负责处理来自客户端的 HTTP 请求,并将请求路由到正确的服务方法中。在基于 Servlet 的架构中,通常使用一个名为 "Front Controller" 的 Servlet 来作为控制器,该 Servlet 负责管理请求和响应,以及进行必要的身份验证和授权。
服务层 :负责执行业务逻辑,例如处理请求并生成相应的数据模型。在基于 Servlet 的架构中,通常将服务层实现为简单的 POJO(普通的Java 对象),它们可能会从数据库中读取数据并通过 Servlet 控制器发送响应。
数据访问层 :负责提供与数据存储系统的交互,并负责将数据转换为可在服务层中使用的格式。在基于Servlet 的架构中,数据访问层通常使用称为 DAO(数据访问对象)的对象来隐藏底层数据源的复杂性和细节。
实体层 :表示应用程序的业务实体和规则。在基于Servlet 的架构中,通常使用 POJO 来表示域对象,并将其与数据访问层和服务层结合使用。
这种基于 Servlet 的架构模式主要优势是可扩展性高,可以快速部署和调试,以及具有良好的分离关注点的能力,使得不同的开发人员可以同时工作,从而提高生产率和代码质量。
优点:
易于维护: 分层结构使得系统代码更具有可读性和可维护性,因为每个层都有清晰的职责和功能,易于定位和排除问题。
可扩展性: 由于架构的松耦合性,每个层次的改变不会影响到其他层次,因此添加新功能或更改现有功能变得更容易实现。
可测试性: 分离出的业务逻辑层可以进行单元测试,以便快速检测问题并改进代码。而且,数据访问层可以使用内存数据库或者Mock数据来进行单元测试,而不需要考虑外部存储的依赖性。
易于协作开发: 分层结构可以使不同团队或不同开发者之间互相独立地开发代码,因为他们只需要知道接口而无需关注底层实现。
表结构 实体 数据访问对象DAO 服务对象 控制对象 测试
demo/DaoTest/Student.sql create table Student (
no TEXT primary key ,
name TEXT not null ,
gender TEXT ,
age INTEGER ,
dept TEXT
);
xust.demo.stu.domain.Student public class Student {
/**
* 学号
*/
private String no ;
public String getNo (){
return no ;
}
public void setNo ( String newValue ){
no = newValue ;
}
}
源代码
xust.demo.stu.domain.Student package xust.demo.stu.domain ;
/**
* Class Student
* 学生表
* @author XUST
* @version 1.0, 2023-04-20
*/
public class Student {
/**
* 学号
*/
private String no ;
public String getNo (){
return no ;
}
public void setNo ( String newValue ){
no = newValue ;
}
/**
* 姓名
*/
private String name ;
public String getName (){
return name ;
}
public void setName ( String newValue ){
name = newValue ;
}
/**
* 性别
*/
private String gender ;
public String getGender (){
return gender ;
}
public void setGender ( String newValue ){
gender = newValue ;
}
/**
* 年龄
*/
private Integer age ;
public Integer getAge (){
return age ;
}
public void setAge ( Integer newValue ){
age = newValue ;
}
/**
* 所在系
*/
private String dept ;
public String getDept (){
return dept ;
}
public void setDept ( String newValue ){
dept = newValue ;
}
@Override
public String toString () {
return "{" + "\"no\": " + "\"" + no + "\"" + ", " + "\"name\": " + "\"" + name + "\"" + ", " + "\"gender\": " + "\"" + gender + "\"" + ", " + "\"age\": " + age + ", " + "\"dept\": " + "\"" + dept + "\"" + "}" ;
}
}
xust.demo.stu.dao.StudentDao package xust.demo.stu.dao ;
import xust.demo.Result ;
import xust.demo.stu.domain.Student ;
public interface StudentDao {
/**
* 初始化表
* @return
*/
Result init ();
/**
* 增
* @param o
* @return
*/
Result create ( Student o );
/**
* 删
* @param id
* @return
*/
Result delete ( String no );
/**
* 改
* @param o
* @return
*/
Result update ( Student o );
/**
* 查
* @param no
* @return
*/
Result get ( String no );
/**
* 查
* @return
*/
Result getAll ();
}
源代码
xust.demo.stu.dao.StudentDaoImpl package xust.demo.stu.dao ;
import java.sql.* ;
import java.util.ArrayList ;
import xust.demo.ConnectionUtil ;
import xust.demo.Result ;
import xust.demo.stu.domain.Student ;
public class StudentDaoImpl implements StudentDao {
public Result init () {
Result res = new Result ( false );
Connection con = null ;
Statement stmt = null ;
String sql = "create table Student(" +
"no TEXT primary key," +
"name TEXT not null," +
"gender TEXT," +
"age INTEGER," +
"dept TEXT" +
");" ;
con = ConnectionUtil . getConnection ();
if ( con != null ){
try {
stmt = con . createStatement ();
ResultSet rs = stmt . executeQuery ( String . format ( "select count(*) from sqlite_master where type = 'table' and Upper(name) = '%s'" , "Student" . toUpperCase ()));
while ( rs . next ()){
int count = rs . getInt ( 1 );
if ( count == 0 && stmt . executeUpdate ( sql ) > 0 ){
res . code = 0 ;
}
}
} catch ( Exception e ) {
e . printStackTrace ();
res . message = e . getMessage ();
} finally {
ConnectionUtil . closeStmt ( stmt );
ConnectionUtil . closeConnection ( con );
}
}
return res ;
}
/**
* 对象填充到关系
*/
private void toR ( Student o , PreparedStatement stmt ) throws Exception {
if ( o != null && stmt != null ){
String no = o . getNo ();
if ( no != null ){
stmt . setString ( 1 , no );
}
String name = o . getName ();
if ( name != null ){
stmt . setString ( 2 , name );
}
String gender = o . getGender ();
if ( gender != null ){
stmt . setString ( 3 , gender );
}
Integer age = o . getAge ();
if ( age != null ){
stmt . setInt ( 4 , age );
}
String dept = o . getDept ();
if ( dept != null ){
stmt . setString ( 5 , dept );
}
}
}
/**
* 关系填充到对象
*/
private Student toO ( ResultSet rs ) throws Exception {
Student res = null ;
if ( rs != null ){
res = new Student ();
res . setNo ( rs . getString ( "no" ));
res . setName ( rs . getString ( "name" ));
res . setGender ( rs . getString ( "gender" ));
res . setAge ( rs . getInt ( "age" ));
res . setDept ( rs . getString ( "dept" ));
}
return res ;
}
public Result create ( Student o ) {
Result res = new Result ( false );
Connection con = null ;
PreparedStatement stmt = null ;
String sql = "insert into Student values (?, ?, ?, ?, ?)" ;
con = ConnectionUtil . getConnection ();
if ( o != null && con != null ) {
try {
stmt = con . prepareStatement ( sql );
toR ( o , stmt );
if ( stmt . executeUpdate () > 0 ){
res . code = 0 ;
}
} catch ( Exception e ) {
res . message = e . getMessage ();
e . printStackTrace ();
} finally {
ConnectionUtil . closePstmt ( stmt );
ConnectionUtil . closeConnection ( con );
}
}
return res ;
}
public Result delete ( String no ) {
Result res = new Result ( false );
Connection con = null ;
PreparedStatement stmt = null ;
String sql = "delete from Student where no = ?;" ;
con = ConnectionUtil . getConnection ();
if ( con != null ){
try {
stmt = con . prepareStatement ( sql );
stmt . setString ( 1 , no );
res . code = 0 ;
} catch ( Exception e ) {
res . message = e . getMessage ();
e . printStackTrace ();
} finally {
ConnectionUtil . closePstmt ( stmt );
ConnectionUtil . closeConnection ( con );
}
}
return res ;
}
public Result update ( Student o ) {
Result res = new Result ( false );
Connection con = null ;
PreparedStatement stmt = null ;
String sql = "update Student set No = ?, Name = ?, Gender = ?, Age = ?, Dept = ? where no = ?" ;
con = ConnectionUtil . getConnection ();
if ( o != null && con != null ) {
try {
stmt = con . prepareStatement ( sql );
toR ( o , stmt );
stmt . setString ( 6 , o . getNo ());
if ( stmt . executeUpdate () > 0 ){
res . code = 0 ;
}
} catch ( Exception e ) {
e . printStackTrace ();
res . message = e . getMessage ();
} finally {
ConnectionUtil . closePstmt ( stmt );
ConnectionUtil . closeConnection ( con );
}
}
return res ;
}
public Result get ( String no ) {
Result res = new Result ( false );
Connection con = null ;
PreparedStatement stmt = null ;
String sql = "select * from Student where no = ?" ;
con = ConnectionUtil . getConnection ();
if ( con != null ){
try {
stmt = con . prepareStatement ( sql );
stmt . setString ( 1 , no );
ResultSet rs = stmt . executeQuery ();
Student last = null ;
while ( rs . next ()) {
last = new Student ();
last . setNo ( rs . getString ( "no" ));
last . setName ( rs . getString ( "name" ));
last . setGender ( rs . getString ( "gender" ));
last . setAge ( rs . getInt ( "age" ));
last . setDept ( rs . getString ( "dept" ));
}
res . code = 0 ;
res . data = last ;
} catch ( Exception e ) {
res . message = e . getMessage ();
e . printStackTrace ();
} finally {
ConnectionUtil . closePstmt ( stmt );
ConnectionUtil . closeConnection ( con );
}
}
return res ;
}
public Result getAll () {
Result res = new Result ( false );
Connection con = null ;
PreparedStatement stmt = null ;
String sql = "select * from Student" ;
con = ConnectionUtil . getConnection ();
if ( con != null ){
try {
stmt = con . prepareStatement ( sql );
ResultSet rs = stmt . executeQuery ();
ArrayList < Student > data = new ArrayList < Student > ();
while ( rs . next ()) {
Student last = toO ( rs );
data . add ( last );
}
res . code = 0 ;
res . data = data ;
} catch ( Exception e ) {
res . message = e . getMessage ();
e . printStackTrace ();
} finally {
ConnectionUtil . closePstmt ( stmt );
ConnectionUtil . closeConnection ( con );
}
}
return res ;
}
}
xust.demo.stu.service.StudentService package xust.demo.stu.service ;
import jakarta.servlet.http.HttpServletRequest ;
import xust.demo.Result ;
import xust.demo.stu.domain.Student ;
public interface StudentService {
Student toO ( HttpServletRequest request );
/**
* 增
* @param o
* @return
*/
Result create ( Student o );
/**
* 删
* @param id
* @return
*/
Result delete ( String no );
/**
* 改
* @param o
* @return
*/
Result update ( Student o );
/**
* 查
* @param no
* @return
*/
Result get ( String no );
/**
* 查
* @return
*/
Result getAll ();
}
源代码
xust.demo.stu.service.StudentServiceImpl package xust.demo.stu.service ;
import jakarta.servlet.http.HttpServletRequest ;
import xust.demo.Result ;
import xust.demo.stu.dao.StudentDao ;
import xust.demo.stu.dao.StudentDaoImpl ;
import xust.demo.stu.domain.Student ;
public class StudentServiceImpl implements StudentService {
private StudentDao _StudentDao ;
public StudentServiceImpl (){
_StudentDao = new StudentDaoImpl ();
_StudentDao . init ();
}
/**
* 参数填充到对象
*/
public Student toO ( HttpServletRequest request ){
Student res = null ;
if ( request != null ){
res = new Student ();
String p = null ;
p = request . getParameter ( "no" );
if ( p != null ){
res . setNo ( request . getParameter ( "no" ));
}
p = request . getParameter ( "name" );
if ( p != null ){
res . setName ( request . getParameter ( "name" ));
}
p = request . getParameter ( "gender" );
if ( p != null ){
res . setGender ( request . getParameter ( "gender" ));
}
p = request . getParameter ( "age" );
if ( p != null ){
res . setAge ( Integer . parseInt ( request . getParameter ( "age" )));
}
p = request . getParameter ( "dept" );
if ( p != null ){
res . setDept ( request . getParameter ( "dept" ));
}
}
return res ;
}
public Result create ( Student o ) {
Result res = new Result ( false );
if ( _StudentDao != null && o != null ){
res = _StudentDao . create ( o );
}
return res ;
}
public Result delete ( String no ) {
Result res = new Result ( false );
if ( _StudentDao != null ){
res = _StudentDao . delete ( no );
}
return res ;
}
public Result update ( Student o ) {
Result res = new Result ( false );
if ( _StudentDao != null && o != null ){
res = _StudentDao . update ( o );
}
return res ;
}
public Result get ( String no ) {
Result res = new Result ( false );
if ( _StudentDao != null ){
res = _StudentDao . get ( no );
}
return res ;
}
public Result getAll () {
Result res = new Result ( false );
if ( _StudentDao != null ){
res = _StudentDao . getAll ();
}
return res ;
}
}
xust.demo.stu.action.StudentGetServlet.java @WebServlet ( "/demo/Student/Get" )
public class StudentGetServlet extends HttpServlet {
private StudentService _StudentService = new StudentServiceImpl ();
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
Result res = _StudentService . get ( request . getParameter ( "no" ));
response . setCharacterEncoding ( "utf-8" );
response . setContentType ( "application/json" );
response . getWriter (). append ( String . format ( "{\"code\":%d, \"message\":\"%s\", \"data\":%s}" , res . code , res . message , res . data ));
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
源代码-Add
xust.demo.stu.action.StudentAddServlet package xust.demo.stu.action ;
import java.io.IOException ;
import jakarta.servlet.ServletConfig ;
import jakarta.servlet.ServletException ;
import jakarta.servlet.annotation.WebServlet ;
import jakarta.servlet.http.HttpServlet ;
import jakarta.servlet.http.HttpServletRequest ;
import jakarta.servlet.http.HttpServletResponse ;
import xust.demo.Result ;
import xust.demo.stu.domain.Student ;
import xust.demo.stu.service.StudentService ;
import xust.demo.stu.service.StudentServiceImpl ;
@WebServlet ( "/demo/Student/Add" )
public class StudentAddServlet extends HttpServlet {
private StudentService _StudentService = new StudentServiceImpl ();
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
Student o = _StudentService . toO ( request );
Result res = _StudentService . create ( o );
response . setCharacterEncoding ( "utf-8" );
response . setContentType ( "application/json" );
response . getWriter (). append ( String . format ( "{\"code\":%d, \"message\":\"%s\"}" , res . code , res . message ));
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
源代码-Delete
xust.demo.stu.action.StudentDeleteServlet package xust.demo.stu.action ;
import java.io.IOException ;
import jakarta.servlet.ServletConfig ;
import jakarta.servlet.ServletException ;
import jakarta.servlet.annotation.WebServlet ;
import jakarta.servlet.http.HttpServlet ;
import jakarta.servlet.http.HttpServletRequest ;
import jakarta.servlet.http.HttpServletResponse ;
import xust.demo.Result ;
import xust.demo.stu.domain.Student ;
import xust.demo.stu.service.StudentService ;
import xust.demo.stu.service.StudentServiceImpl ;
@WebServlet ( "/demo/Student/Delete" )
public class StudentDeleteServlet extends HttpServlet {
private StudentService _StudentService = new StudentServiceImpl ();
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
Result res = _StudentService . delete ( request . getParameter ( "no" ));
response . setCharacterEncoding ( "utf-8" );
response . setContentType ( "application/json" );
response . getWriter (). append ( String . format ( "{\"code\":%d, \"message\":\"%s\"}" , res . code , res . message ));
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
源代码-Update
xust.demo.stu.action.StudentUpdateServlet package xust.demo.stu.action ;
import java.io.IOException ;
import jakarta.servlet.ServletConfig ;
import jakarta.servlet.ServletException ;
import jakarta.servlet.annotation.WebServlet ;
import jakarta.servlet.http.HttpServlet ;
import jakarta.servlet.http.HttpServletRequest ;
import jakarta.servlet.http.HttpServletResponse ;
import xust.demo.Result ;
import xust.demo.stu.domain.Student ;
import xust.demo.stu.service.StudentService ;
import xust.demo.stu.service.StudentServiceImpl ;
@WebServlet ( "/demo/Student/Update" ) // 映射URL
public class StudentUpdateServlet extends HttpServlet {
private StudentService _StudentService = new StudentServiceImpl ();
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
Student o = _StudentService . toO ( request );
Result res = _StudentService . update ( o );
response . setCharacterEncoding ( "utf-8" );
response . setContentType ( "application/json" );
response . getWriter (). append ( String . format ( "{\"code\":%d, \"message\":\"%s\"}" , res . code , res . message ));
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
源代码-Get
xust.demo.stu.action.StudentGetServlet package xust.demo.stu.action ;
import java.io.IOException ;
import jakarta.servlet.ServletConfig ;
import jakarta.servlet.ServletException ;
import jakarta.servlet.annotation.WebServlet ;
import jakarta.servlet.http.HttpServlet ;
import jakarta.servlet.http.HttpServletRequest ;
import jakarta.servlet.http.HttpServletResponse ;
import xust.demo.Result ;
import xust.demo.stu.domain.Student ;
import xust.demo.stu.service.StudentService ;
import xust.demo.stu.service.StudentServiceImpl ;
@WebServlet ( "/demo/Student/Get" )
public class StudentGetServlet extends HttpServlet {
private StudentService _StudentService = new StudentServiceImpl ();
protected void doGet ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
Result res = _StudentService . get ( request . getParameter ( "no" ));
response . setCharacterEncoding ( "utf-8" );
response . setContentType ( "application/json" );
response . getWriter (). append ( String . format ( "{\"code\":%d, \"message\":\"%s\", \"data\":%s}" , res . code , res . message , res . data ));
}
protected void doPost ( HttpServletRequest request , HttpServletResponse response )
throws ServletException , IOException {
doGet ( request , response );
}
}
demo/DaoTest/StudentServletTest.txt HTTP / 1 . 1 200
Content - Type : application / json ; charset = utf - 8
Content - Length : 103
Date : Sun , 23 Apr 2023 04 : 42 : 37 GMT
Connection : close
{
"code" : 0 ,
"message" : "null" ,
"data" : {
"no" : "X5" ,
"name" : "X5" ,
"gender" : "X5" ,
"age" : 2 ,
"dept" : "X2"
}
}
demo/DaoTest/StudentServletTest.http ### 查
POST http : // localhost : 8080 / {{ app }} / demo / Student / Get HTTP / 1 . 1
Content - Type : application / x - www - form - urlencoded
no = X2
源代码
demo/DaoTest/StudentServletTest.http @ app = DaoTest
### 增
POST http : // localhost : 8080 / {{ app }} / demo / Student / Add HTTP / 1 . 1
Content - Type : application / x - www - form - urlencoded
id = 1
& no = X2
& name = X2
& gender = X2
& age = 2
& dept = X2
### 删
POST http : // localhost : 8080 / {{ app }} / demo / Student / Delete HTTP / 1 . 1
Content - Type : application / x - www - form - urlencoded
no = X1
### 改
POST http : // localhost : 8080 / {{ app }} / demo / Student / Update HTTP / 1 . 1
Content - Type : application / x - www - form - urlencoded
id = 1
& no = X2
& name = X2
& gender = X2
& age = 2
& dept = X2
### 查
POST http : // localhost : 8080 / {{ app }} / demo / Student / Get HTTP / 1 . 1
Content - Type : application / x - www - form - urlencoded
no = X2