Template engine: Chapter 3: using Freemark to promote enterprise SEO

Posted by Cagez on Tue, 28 Sep 2021 21:36:03 +0200

Why do SEO?

When the company's project is nearing the end, it needs to be promoted at this time. At this time, it needs SEO. What is SEO? SEO Chinese translation is search engine optimization. It uses the rules of search engines to improve the natural ranking of websites in relevant search engines. The purpose is to make it occupy a leading position in the industry and obtain brand revenue. To a large extent, it is a kind of business behavior of website operators, which moves themselves or their company forward.

Common misunderstandings:

In terms of speed, generally, static web pages are faster than dynamic web pages. But many times, we make the website static for SEO. Is this necessary? We know that it is basically impossible to make the website purely static. Except for some websites such as wikibaihu, our websites need to be modified and users need to participate in interaction. There are a lot of reasons for our websites to change dynamically. As a result, we sacrifice the user-friendly experience to "win the favor of search engines". But you know search engines don't like static pages.

Search engines do not like the origin of static pages:

Web page static this thing, is purely a false thing. We want to talk about the origin of this thing. When the search engine just started, dynamic pages just emerged. Many web pages have a lot of parameters behind their addresses, and these parameters may change dynamically. They will have different parameters according to different user operations. Search engines don't like such addresses. Why? Let's first look at what the search engine is doing. The search engine is actually a program called Spider. After it is released, download a website for analysis, and then put the summary part into its own database. The next time users search, they will directly search its database.

How search engines work:

For example, if Google wants to index my website, it will visit it first http://iove.net This primary domain name, but actually http://iove.net Yes, locate http://iove.net/index.php Of this page. In this way, the spider first downloads the html content of the current page of index.php. Note that the spider only needs the native html content (including text of course), does not include any content in iframe, any content generated by js and other scripts, and does not include multimedia content such as pictures and flash. It only indexes the html tag and the content in the tag. When your html is a piece of text, analyze it to obtain the text content and link content, and then carry out the next index according to the link. Search engines actually analyze the text and put it into the database. Pay attention to the database! Some people with basic technology know that as long as it is a database, there will be a primary key. According to the paradigm theory, the database should have a unique primary key, and the data indexed by the search engine should also have a unique primary key. What is the primary key? This is our website.

All right, finish the theory and start

pom.xml introduces freemark related dependencies:


SpringMvc configuration file:

<!-- register freemarker Configuration class -->
            <bean id="freeMarkerConfigurer" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
                <!-- ftl Template file path  -->
                <property name="templateLoaderPath" value="classpath:freemarker/"></property>
                <!-- Page coding -->
                <property name="defaultEncoding" value="utf-8" />
                <property name="freemarkerSettings">
                        <!-- The template cache refresh time is not written. The default unit is seconds -->
                        <prop key="template_update_delay">0</prop>
                        <!-- Time zone and time formatting -->
                        <prop key="locale">zh_CN</prop>
                        <prop key="datetime_format">yyyy-MM-dd</prop>
                        <prop key="date_format">yyyy-MM-dd</prop>
                        <!-- Digital use.To separate -->
                        <prop key="number_format">#.##</prop>
                <!--Static resource access path-->
                <property name="freemarkerVariables">
                        <entry key="resPath" value="${resources.server}"/>
            <!-- register freemarker view resolver  -->
            <bean id="freeMarkerViewResolver"
                <!-- The view parsing order is behind other view parsers. The higher the number, the lower the priority -->
                <property name="order" value="0" />
                <!-- Enable template cache -->
                <property name="cache" value="true" />
                <!-- It's already equipped. You don't need it here -->
                <property name="prefix" value="" />
                <!-- Profile suffix -->
                <property name="suffix" value=".ftl" />
                <property name="contentType" value="text/html;charset=UTF-8" />
                <!-- Allow session Attribute overrides model data,default false -->
                <property name="allowSessionOverride" value="false" />
                <!-- Allow request Attribute overrides model data,default false -->
                <property name="allowRequestOverride" value="false" />
                <!-- open spring Macro help provided(macro) -->
                <property name="exposeSpringMacroHelpers" value="true" />
                <!-- add to request attributes Attribute to ModelAndView in -->
                <property name="exposeRequestAttributes" value="true" />
                <!-- add to session attributes Attribute to ModelAndView in -->
                <property name="exposeSessionAttributes" value="true" />
                <property name="viewClass"  value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
                <property name="requestContextAttribute" value="request" />

For more information, see: http://www.mark-to-win.com/tutorial/51236.html

Topics: FreeMarker seo