In Spring, @ RequestParam is used to accept url parameters of the Date type, @ requestparamdate

Source: Internet
Author: User

In Spring, @ RequestParam is used to accept url parameters of the Date type, @ requestparamdate

First introduce the joda-time package. Maven dependency:

        <dependency>            <groupId>joda-time</groupId>            <artifactId>joda-time</artifactId>            <version>2.4</version>        </dependency>

In the Controller code:

public String testMethod(@RequestParam @DateTimeFormat(pattern="yyyy-MM-dd") Date testdate){    System.out.println(testDate);}

Use pattern to specify the date format.

Test url:

? Testdate = 2014-09-04


Spring @ RequestParam

Use the following method:
@ RequestMapping ("/addHouse. do ")
Public String addHouse (
@ RequestParam (value = "companyId", required = true) int companyId,
@ RequestParam (value = "pics", required = false) CommonsMultipartFile pics,
HttpServletRequest request, HttpServletResponse response, ModelMap model ){
...
...
Model. addAttribute ("pics", pics );
Return "redirect:/addHousePic. do ";

Sample: addHousePic. do: pics null companyId can be successfully transferred.
What's going on?
Kltbsrexgt reference ·····

What problems have you encountered during spring's opening?

• @ Controller
• @ Service
• @ Autowired
• @ RequestMapping
• @ RequestParam
• @ ModelAttribute
• @ Cacheable
• @ CacheFlush
• @ Resource
• @ PostConstruct
• @ PreDestroy
• @ Repository
• @ Component (not recommended)
• @ Scope
• @ SessionAttributes
• @ InitBinder
• @ Required
• @ Qualifier

@ Controller
• Example
@ Controller
Public class SoftCreateController extends SimpleBaseController {}

• Or
@ Controller ("softCreateController ")

• Description
@ Controller registers a bean to the spring context. bean IDs start with the class name and start with lowercase letters by default.

@ Service
• Example
@ Service
Public class SoftCreateServiceImpl implements ISoftCreateService {}

• Or
@ Service ("softCreateServiceImpl ")

• Description
@ Service registers a bean to the spring context. bean IDs start with the class name and start with lowercase letters by default.

@ Autowired
• Example
@ Autowired
Private ISoftPMService softPMService;

• Or

@ Autowired (required = false)
Private ISoftPMService softPMService = new SoftPMServiceImpl ();
... The remaining full text>

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.