SPRING-SPRINGMVC Build (iii) SPRINGMVC add support for static resource access and support for Fastjson

Source: Internet
Author: User

1. Add a visit to a static resource. Js/.img/.css

There are 3 types of methods:

1, change the path of the Springmvc Dispatherservlet urlpattern to "/*.do".

2. Add <mvc:default-servlet-handler>, and at the same time add the default mapping type in Web. xml to allow SPRINGMVC to identify those that can be released.

Add:<mvc:default-servlet-handler/> in the context of SPRINGMVC

In Web. xml
<servlet-mapping>
<servlet-name>default</servlet-name>

<url-pattern>*.js</url-pattern>

</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.ico</url-pattern>
</servlet-mapping>

3. Using <mvc:resources >

<mvc:resources mapping= "" location= ""/>
2,springmvc adding support for Fastjson

Springmvc's httpmessageconverter is the use of mappingjackjson2httpmessageconverter, but is now generally used Ali's Fastjson, So I'm going to replace Fastjsonhttpmessageconverter.

    <!--enhancement Annotations-    <mvc:annotation-driven>        <mvc:message-converters register-defaults= "false" >            <bean class= "Com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"                  id= " Fastjsonhttpmessageconverter ">                <property name=" Supportedmediatypes ">                    <list>                        < value>application/json;charset=utf-8</value>                    </list>                </property>                <!--< Property Name= "Serializerfeature" >-->                <!--This place with this function, you can configure some things, such as the format of the time, null output "" and so on                . <!--</property>-->            </bean>        </mvc:message-converters>    </MVC: Annotation-driven>

  

Add Fastjson maven dependencies to the Pom file

      <!--Https://mvnrepository.com/artifact/com.alibaba/fastjson--      <dependency>          <groupid >com.alibaba</groupId>          <artifactId>fastjson</artifactId>          <version>1.2.47 </version>      </dependency>

  

SPRING-SPRINGMVC Build (iii) SPRINGMVC add support for static resource access and support for Fastjson

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.