web-based improvements to: the most normal version
Copy Code code as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<beans
Xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xmlns:p= "http://www.springframework.org/schema/p"
xmlns:context= "Http://www.springframework.org/schema/context"
Xsi:schemalocation= "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd ">
<!--view configuration for Freemarker-->
<bean id= "Viewresolver"
class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver" >
<property name= "Order" value= "5"/>
<property name= "suffix" value= "FTL"/>
<property name= "ContentType" value= "Text/html;charset=utf-8"/>
</bean>
<bean id= "Freemarkerconfig"
class= "Org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" >
<property name= "Templateloaderpath" value= "/web-inf/view/"/>
<property name= "Freemarkersettings" >
<props>
<prop key= "Template_update_delay" >0</prop>
<prop key= "Default_encoding" >UTF-8</prop>
<prop key= "Number_format" >0.##########</prop>
<prop key= "Datetime_format" >yyyy-mm-dd hh:mm:ss</prop>
<prop key= "Classic_compatible" >true</prop>
<prop key= "Template_exception_handler" >ignore</prop>
</props>
</property>
</bean>
Controller established
Copy Code code as follows:
Import Javax.servlet.http.HttpServletRequest;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RequestMethod;
Import Org.springframework.web.servlet.ModelAndView;
@Controller
public class Springmvccontroller {
@RequestMapping (value= "/welcome", Method={requestmethod.get})
Public Modelandview Getfirstpage (HttpServletRequest request) {
Welcom is the name of the view (WELCOM.FTL)
Modelandview mv = new Modelandview ("welcom");
Mv.addobject ("name", "My I-Spring Mvc");
return MV;
}
}
Knocking http://localhost:8080/welcome on the URL will render the data on the WEB-INF/VIEW/WELCOM.FTL page
WELCOM.FTL page
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=iso-8859-1 ">
<title>insert title here</title>
<body>
Hello ${name}
</body>
The effect of the page:
Hello my i-Spring MVC