JAVA front-end interaction

1. First, after the front-end page is written, how to accurately know which component is currently being operated on

jQuery selector, select components, operate on them

(1) Element selector

(2) ID selector

<button type="button" class="btn" id="test">一个标准的按钮</button>

This button can be selected through the id selector $("#test").

(3) class selector

This button can be selected through the class selector $("#btn").

2. After entering the address, how do I find the JSP or HTML page?

Spring first finds @Controller, finds @RequestMapping again, and returns to the corresponding page according to the value

@RequestMapping(value =  "show", method = RequestMethod.GET)
	public String showit() { // 用来返回一个页面
		return "show"; 
	}

For example: the project name is called test, enter http://localhost:8080/test/show , it will find @Controller and then @RequestMapping to find this paragraph, execute this method, and then combine the configuration file to return to the show.jsp file, The page is loaded.

springmvc: The idea of ​​MVC architecture pattern,

@Controller: Used to mark a class, the class marked with it is a SpringMVC Controller object. The dispatch processor will scan the method of the class that uses the annotation, and detect whether the method uses the @RequestMapping annotation.

@RequestMapping: @Controller just defines a controller class, and the method annotated with @RequestMapping is the processor that actually processes the request. Just using the @Controller tag on a class cannot really say that it is a controller class of SpringMVC, because Spring does not recognize it at this time.

How to let spring know him?

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!--配置JSTL表达式 -->
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <!-- 前缀 -->
        <property name="prefix" value="/WEB-INF/view/" />
        <!-- 后缀 -->
        <property name="suffix" value=".jsp" />
    </bean>

Spring will go to this directory to find a file with a specified name and a suffix of .jsp.

@ResponseBody

3. After the page is displayed, how does it work, and how does it monitor user behavior?

In the jsp file, no matter it is a table, a form, or a button, it is static. What makes them move is the part of <script>...</script>.

jQuery : jQuery is a JavaScript library that greatly simplifies Javascript programming. JQuery must be introduced before use.

<script src="res/viewer/js/jquery.min.js"></script>

Just add such a file to your project, and then add such a sentence to the page file to tell the project where I put this file.

 

Ajax : A technology that can update part of a web page without reloading the entire web page.

 

4. The database query data is displayed on the page

The @responseBody annotation converts the object returned by the controller method into a specified format through an appropriate converter, and then writes it to the body area of ​​the response object. It is usually used to return JSON data or XML data. Call the data layer method to encapsulate the query result into an object, @responseBody converts the object into JSON format, and returns to the page for display.

 

5.Layui

Using the layui framework, when rendering the table, the page property is set to true to enable paging, request.getParameter("page"), request.getParameter("limit"), you can get the current page and how many pieces of data per page.

 

request.getAttribute() needs to be used with request.setAttribute(),
        that is, request.getAttribute() gets the data stored in the servlet container on our own server*

 

Guess you like

Origin blog.csdn.net/wb_it_man/article/details/113500198