About spring MVC
can we modify form bean?--yes.when you want to use it in page, be like this: Object["{attribute name}"]
can we modify model?--yes, if you add a new attribute with same property name, the old one will be replaced.
example:lets say we want to keep some content when we have to jump to another page:
- we use model.addAttribute to set each attribute in model. (can also through formbean, while then you can not use ${attributeName} directly, have to use formbean["attributeName"]).
- in the page we jumped to, we use <springform:hidden "path"="xxx" value="${xxx}"/> to make the properties stay on page(unvisible)
- we also make sure that those attributes defined in the pojo bean related with the from, so when the form was commitd from second page, we got the attributes from the object.
pay attention1:
if you used a<spring:url value="${path}" var="form_url"><spring:param name="twitle" value="${twitterTitle}"/></spring:url>should avoid using twitle as property of form bean, otherwise, in form bean, this property will be mess like "{perperty value},{mapping string value}"
pay attention2:
you can use same property name in model and form bean, they will not affect each other, once I used secretQuestion in both form bean and model property, to save question code and question lable, so I save both of then don't need to transfer to eachother.
--------------
form use post as method by default, spring mvc controller mathod use get as method by default, that why the form action string not lead the request to the method sometimes.
notes:
the <spring:message code="" param=""> the param should not contain ','. (other punctuation not tested)!!! otherwise the content after the puntuation will be lost!
----------------------
Can not jump to a pulic page from an securated url method, example: mathod a response for url"/resendTokenEmailForm", in the end of this method, should not return "public/resendTokenEmailForm", because it's a unsecurated page, even you call logout mehtod fist. the right way is to call 'return "redirect:/public/resendTokenEmailForm"', to go to the controller method first, then in that method, return "public/resendTokenEmailForm".
when doing this, you can use model.addattribute() to add parameter or user "?emailAddress="+tEmail+"&secretQuestion="+tQes" to transfer the parameters.
what if you do modal.addattribute("email", "abc") and add "?email=abc" at the end of url together? the model.get ("email") will be "abc,abc"
-----------------------------
How to change the mothed of form from default "POST" to "PUT"?
when we use a form to do update, we used the default path like "/mainorders" this is the same path with list and create method. So if we still use "method = RequestMethod.POST" in method mapping annotation, it will duplicated with the create method, if don't set, by default it's a GET, so it a conflict with the list method..... then what we should do is to set it to "method = RequestMethod.PUT". here is how to write in jsp file.
<input type="hidden" value="PUT" name="_method"/>
-----------------------------------------------窗口要用Post参数才能传递
that we must use Post to make sure the parameter defined in URLString can be delievered here. if we use GET, then doesn't work.
and the & in URLString must be &
如何封装多个窗口参数
use <form modelAttribute=”conditions”> in View, And use ( FilterBean conditions作为Controller里方法的参数,整个窗体里的内容就被尽量封装进一个FilterBean实例里传给控制器