Write point front-end, VM + jquery + Controller

Source: Internet
Author: User

I want some things. The following statements are based on these facts:

Front-end page:. VM, velocity + jquery

MVC: enhanced version of spring MVC

Controller: @ controller, @requestmapping,.htm,. JSON, get, post

 

12.16.htm

For every .htm, @ controller in the controller means to write a method with @ requestmapping (value = "/topiceventcode.htm", method = requestmethod. Get) in the header of the method ). In this way, the page can be refreshed multiple times and executed in this method.

I encountered such a problem before. I did not write get, but post. After the page was refreshed, I couldn't find the controller. I couldn't get any break in the method, this is silly.

Refresh/reload the page, and your content will be re-assigned for rendering. These values are brought back from the Controller. You can bring them back in modelmap or directly write them into response.

I generally use modelmap to store some string-type values. Previously, complicated objects are stored, and the rendering results are unavailable because the serialization of this object fails during JSON serialization.

 

Table 1-1

# If ($! Mode = "topicstatistics") # foreach ($ line in $! Data) <tr> <TD >$! Line. Topic </TD> <TD >$! Line. eventcode </TD> <TD >$! Line. fromapps </TD> <TD >$! Line. toapps </TD> <TD >$! Line. numperday </TD> <TD >$! Line. exproperty </TD> <TD >$! Line. statusenum </TD> <TD >$! Line. gmtcreate </TD> <TD >$! Line. gmtmodified </TD> <TD >$! Line. Operator </TD> <a href = "# updatedatadiv" onclick = "replaceformts ('$! Line. Topic ',' $! Line. eventcode', '$! Line. fromapps ',' $! Line. toapps ',' $! Line. numperday ',' $! Line. exproperties', '$! Line. statusenum ') "class =" boxlink "> modify </a> </TD> </tr> # End

 

 

2) controller, Method

Public String query (modelmap, webrequest request); then, you can use request. getparameter ("Mode") to obtain. VM

Public String query (modelmap, string mode );

Both methods can obtain the value of the page element submitted by the front-end.

However, during use, Public String uploadfile (modelmap, multipartfile file) is found. In this way, the content of the uploaded file is always unavailable. You need to perform the following operations:

Write a class and use this class as the Public String uploadfile (modelmap, fileform) parameter. In this way, you can retrieve the file content through the fileform get method.

Public class fileform {

Private multipartfile file;

//... Getters and setters

}

 

3). JSON

Writing a page is still complicated, so I am more inclined to use the lightweight method of JSON.

. JSON can be used to submit only part of the content on the page to the Controller. For example, only one form is submitted. But it also means that the whole page will not be refreshed again, and the value will not be automatically reloaded.

If you really need to load some values or just remind the user of something, you need to use ajax to submit a. JSON request and inject a callback function when calling Ajax.

In this way, we can write the value to be updated/the value to be prompted to the user in modelmap/response, and perform corresponding processing in the callback function.

   function postAddFormTM(){        jQuery.post("insertRecordTM.json",                             {topic:$("input[name='aaa']").val(), eventcode:$("input[name='bbb']").val() },                             function(result){                                alert(result.result.resultMsg);                            }        );    }

In use, my AAA value isChineseAfter being transferred to the Controller, the garbled characters are changed.Special Encoding, VAR aaachinese = encodeuricomponent ($ ("input [name = 'aaa']"). Val ());

In the controller, AAA = urldecoder. Decode (aaachinese, "UTF-8"); decoding can correctly retrieve Chinese characters.

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.