How does Spring @RequestMapping work?

As you know, is @RequestMappingused to intercept a HttpServletRequest.

I want to know how @Controller @RequestMappingtogether a request from a client can bind to a specific method inside the java class?

I want to write a similar Java application to perform the same function. Imagine we have a class like this:

@Actor
public class JavaForever {

  @Department(value="IT")
  public void departmentIT(){...}

  @Department(value="Physic")
  public void departmentPhysic(){...}
}

And the StudentBean class:

public class StudentBean {

    private String department;
    private Integer age;
    //Other class variable
    //Getters & Setters
}

and finally, we have a test class as follows:

public class TestApplication {
   //getStudentFromDatabaseMethod() implementation here

   public static void main(String[] agrs){
     List<StudentBean> allStudents = new TestApplication().getStudentFromDatabaseMethod();
   //other codes
   }
}

As you can see, it getStudentFromDatabaseMethod()returns List< StudentBean>, now the question arises, how to make this method get an interception with our annotation @Department, which is in the JavaForeverclass before, and returns any value ...

How can we do this???

+4
1

  • Spring ( ).
  • Spring @Controller @RequestMapping.
  • Spring URL @RequestMapping.
  • , Spring,  URL. URL-, ,  @RequestMapping.

:

  • . , .

. ( ) ( ), .

+7

Source: https://habr.com/ru/post/1525850/


All Articles