springMVC+freemaker整合问题

发布于 2021-11-27 10:32:18 字数 5259 浏览 857 评论 12

我用springMVC+hibernate+freemaker写的一个DEMO,我前台和后台的view都是用的freemaker,后台基本东西已经写完了,在写前台的时候出现个很奇怪的问题,访问我映射的方法完全不知道访问哪个了,改了方法页面完全没改变,以下是我三个XML配制:求高手指点下啊

WEB.xml

<servlet>

<servlet-name>MyCmsAdmin</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/config/mycms-servlet-admin.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet>

<servlet-name>MyCmsFront</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/config/mycms-servlet-front.xml</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

</servlet>

 

<servlet-mapping>

<servlet-name>MyCmsAdmin</servlet-name>

<url-pattern>/jeeadmin/jeecms/*</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>MyCmsFront</servlet-name>

<url-pattern>/jeeadmin/front/*</url-pattern>

</servlet-mapping>

mycms-servlet-admin.xml:

<?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:context="http://www.springframework.org/schema/context"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"

default-lazy-init="true">

<!--HttpSession-->

<bean id="sessionProvider" class="com.cms.common.web.session.HttpSessionProvider"/>

<!-- Controller 调度器 -->

<bean

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

 

<!-- 方法映射 -->

<bean

class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">

<property name="interceptors">

<list>

<ref bean="adminContextInterceptor" />

</list>

</property>

</bean>

 

<bean id="adminContextInterceptor" class="com.cms.web.AdminContextInterceptor">

<property name="auth" value="true"/>

<property name="loginUrl" value="/jeeadmin/jeecms/login.do"/>

<property name="errorUrl" value="/jeeadmin/jeecms/error.do"/>

<property name="returnUrl" value="/jeeadmin/jeecms/index.do"/>

<property name="excludeUrls">

<list>

<value>/login.do</value>

<value>/error.do</value>

<value>/logout.do</value>

<value>/module/ajax.do</value>

<value>/role/ajax.do</value>

</list>

</property>

</bean>

<!--后台权限标签-->

<bean id="cms_perm" class="com.cms.web.freemaker.TagsDirective"/>

<!-- 工具类 -->

<bean id="tools" class="com.cms.web.freemaker.StringUpFunction"/>

<!-- freemarker -->

<bean id="freemarkerViewResolver"

class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">

<property name="prefix" value="/jeecms_sys/" />

<property name="suffix" value=".html" />

<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" />

<property name="freemarkerVariables">

<map>

<entry key="base" value="/springtest/"/>

<entry key="cms_perm" value-ref="cms_perm"/>

<entry key="tools" value-ref="tools"/>

</map>

</property>

<property name="freemarkerSettings">

<props>

<prop key="template_update_delay">900000</prop>

<prop key="defaultEncoding">UTF-8</prop>

<prop key="url_escaping_charset">UTF-8</prop>

<prop key="locale">zh_CN</prop>

<prop key="boolean_format">true,false</prop>

<prop key="datetime_format">yyyy-MM-dd HH

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

月牙弯弯 2021-11-30 09:40:31

freemarker demo教程源代码下载:http://www.zuidaima.com/share/kfreemarker-p1-s1.htm

叹沉浮 2021-11-30 09:40:29

不错

冷弦 2021-11-30 09:39:56

仅供参考

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

	<description>Spring MVC Configuration</description>

	<!-- 加载配置属性文件 -->
	<context:property-placeholder ignore-unresolvable="true" location="classpath*:/application.properties"/>

	<!-- 默认的注解映射的支持,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -->
	<mvc:annotation-driven/>

	<!-- 使用Annotation自动注册Bean,只扫描@Controller(base-package 如果多个,用“,”分隔) -->
	<context:component-scan base-package="org.jiangyong.cms.controller" use-default-filters="false">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>


	<!-- 默认的注解映射的支持,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -->
	<mvc:annotation-driven>
		<mvc:message-converters register-defaults="true">
			<!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
				<constructor-arg value="UTF-8"/>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>


	<!-- 处理 ${webAppRoot}/resources 目录下的静态资源 -->
	<mvc:resources mapping="/resources/**" location="/resources/" />


	<!-- 上传文件拦截,设置最大上传文件大小   10M=10*1024*1024(B)=10485760 bytes -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="utf-8"/>
		<property name="maxUploadSize" value="${web.maxUploadSize}"/>
	</bean>


	<!-- 配置内容协商视图解析 -->
	<bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<!-- 设置内容协商管理器 -->
		<property name="contentNegotiationManager">
			<bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
				<property name="favorPathExtension" value="true"/>
				<property name="ignoreAcceptHeader" value="true" />
				<property name="defaultContentType" value="text/html" />
				<property name="useJaf" value="false"/>
				<property name="mediaTypes">
					<map>
						<entry key="html" value="text/html" />
						<entry key="json" value="application/json" />
					</map>
				</property>
			</bean>
		</property>
		<!-- 设置默认视图 -->
		<property name="defaultViews">
			<list>
				<bean class="com.alibaba.fastjson.support.spring.FastJsonJsonView">
					<property name="charset" value="UTF-8" />
				</bean>
			</list>
		</property>
		<!-- 设置视图解析器 -->
		<property name="viewResolvers">
			<list>
				<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
					<property name="contentType" value="text/html; charset=UTF-8" />
					<property name="suffix" value="${template.suffix}" />
				</bean>
			</list>
		</property>
	</bean>

	<!-- freemarker 配置 -->
	<bean id="freeMarkerConfigure" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPaths" value="${template.loader_path}" />
		<property name="freemarkerSettings">
			<props>
				<prop key="defaultEncoding">${template.encoding}</prop>
				<prop key="url_escaping_charset">${url_escaping_charset}</prop>
				<prop key="locale">${locale}</prop>
				<prop key="template_update_delay">${template.update_delay}</prop>
				<prop key="tag_syntax">auto_detect</prop>
				<prop key="whitespace_stripping">true</prop>
				<prop key="classic_compatible">true</prop>
				<prop key="number_format">${template.number_format}</prop>
				<prop key="boolean_format">${template.boolean_format}</prop>
				<prop key="datetime_format">${template.datetime_format}</prop>
				<prop key="date_format">${template.date_format}</prop>
				<prop key="time_format">${template.time_format}</prop>
				<prop key="object_wrapper">freemarker.ext.beans.BeansWrapper</prop>
			</props>
		</property>
	</bean>

</beans>

伴我心暖 2021-11-30 09:38:14

能不能教教我配springmvc跟freemaker啊。。弄了一下午了还没配好。。hero_chong@qq.com感激。。

半世蒼涼 2021-11-30 09:32:19

它用起来还是挺方便的啊,我感觉就是前台和后台分两个serverlet的时候有些bean是一样的,不知道是不是这个原因,还不知道咋解决~~~

泛泛之交 2021-11-30 09:29:55

人的问题

一人独醉 2021-11-30 08:48:48

回复
嗯,以前是自己没用好,太浮躁,跟风说垃圾。

梦中楼上月下 2021-11-30 07:51:43

试试加上这个注解:

@RequestMapping(method={RequestMethod.GET,RequestMethod.POST})

灵芸 2021-11-30 07:15:19

此话怎讲,愿闻其详

复古式 2021-11-30 06:59:56

它用起来比struts更简单方便啊

多彩岁月 2021-11-30 06:52:21

大侠,你知道是什么原因么,我感觉好像是前后台的那两个XML配制有相同的bean,比如方法调度的bean和视图解析的bean

明月松间行 2021-11-30 00:11:06

因为跟spring扯在一起了。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文