spring mvc restful 引入 ueditor

继续spring mvc restful

ueditor 百度文本编辑器,更符合中国人 http://ueditor.baidu.com/website/

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>justforfun</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>
	
	<servlet>
		<servlet-name>springMVC</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath*:/springMVC.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springMVC</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
   
	<filter>
		<filter-name>setcharacter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>setcharacter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>
springMVC.xml 注意里面的jsp试图解析的玩意儿,最初是只想用freemarker不想用jsp的,但是ueditor给的东东里面需要用到jsp(文件上传啊这里的,他写好了的jsp不需要改直接能用)

<?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/beans   
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
    http://www.springframework.org/schema/tx   
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-3.0.xsd  
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<context:property-placeholder location="classpath:jdbc.properties" />

	<!-- 自动扫描的包名 -->
	<context:component-scan base-package="com.app,com.core,JUnit4"></context:component-scan>

	<!-- 默认的注解映射的支持 -->
	<mvc:annotation-driven />

	<!-- freemarker config -->
	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPath" value="/WEB-INF/ftl/" />
	</bean>

	<!-- View resolvers can also be configured with ResourceBundles or XML files. 
		If you need different view resolving based on Locale, you have to use the 
		resource bundle resolver. -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="cache" value="true" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
		<property name="contentType" value="text/html; charset=UTF-8" />
	</bean>
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/ueditor/jsp/" />
		<property name="suffix" value=".jsp" /><!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 -->
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
	</bean>

	<!-- 拦截器 -->
	<!-- <mvc:interceptors> <bean class="com.core.mvc.MyInteceptor" /> </mvc:interceptors> -->
	<!-- 对静态资源文件的访问 方案一 (二选一) -->
	<!-- <mvc:default-servlet-handler /> -->

	<!-- 对静态资源文件的访问 方案二 (二选一) -->
	<mvc:resources mapping="/images/**" location="/META-INF/resources/images/"
		cache-period="31556926" />
	<mvc:resources mapping="/js/**" location="/META-INF/resources/js/"
		cache-period="31556926" />
	<mvc:resources mapping="/css/**" location="/META-INF/resources/css/"
		cache-period="31556926" />
	<mvc:resources mapping="/ueditor/**" location="/ueditor/"
		cache-period="31556926" />
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClassName}" />
		<property name="jdbcUrl" value="${jdbc.url}" />
		<property name="user" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<property name="autoCommitOnClose" value="true" />
		<property name="checkoutTimeout" value="${cpool.checkoutTimeout}" />
		<property name="initialPoolSize" value="${cpool.minPoolSize}" />
		<property name="minPoolSize" value="${cpool.minPoolSize}" />
		<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
		<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
		<property name="acquireIncrement" value="${cpool.acquireIncrement}" />
		<property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" />
	</bean>
	<!-- 配置Jdbc模板 -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource"></property>
	</bean>

	<!-- 配置事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
		p:dataSource-ref="dataSource" />
	<!-- 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 -->
	<aop:config proxy-target-class="true">
		<aop:pointcut id="serviceMethod" expression=" execution(* com.app.service..*(..))" />
		<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />
	</aop:config>
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>

	<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
	<!-- Configure the multipart resolver -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- one of the properties available; the maximum file size in bytes -->
		<property name="maxUploadSize" value="100000" />
	</bean>
</beans>
然后把下好的ueditor扔进来,我用的是完全版里面jsp那个,文件结构如下

ftl如下,因为写着玩,用了zarkfx,导入ueditor的东东,ueditor.config.js里面找到var URL = window.UEDITOR_HOME_URL 加上(|| "/justforfun/ueditor/")用绝对路径。初始化编辑器,给个div 个id,然后初始化。

UE.getEditor('editor')

<#import "/spring.ftl" as s />
<#import "auth_form.ftl" as form/>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>
        users
        </title>
          <link rel="stylesheet" type="text/css" href="<@s.url '/ueditor/themes/default/css/ueditor.css' />"/>
        <script type="text/javascript" src="<@s.url '/js/jquery.min.js'/>">        
        </script>        
        <script type="text/javascript" src="<@s.url '/js/zarkfx.js'/>">        
        </script>        
        <script type="text/javascript" src="<@s.url '/ueditor/ueditor.config.js'/>">
        </script>        
        <script type="text/javascript" src="<@s.url '/ueditor/ueditor.all.min.js'/>"> 
        </script>        
        <script type="text/javascript" src="<@s.url '/ueditor/ueditor.parse.js'/>"> 
        </script>        
    </head>
    <body>
       <div fx="scroll[speed=500;scrollTop=200;style=default;]"></div>
       <div>
        <@form.userform use_default_content=false>
            <div style="width:800px;margin:20px auto 40px;">
                <script type="text/plain" id="editor" name="login_name" style="width:100%;height:200px;"></script>
            </div>
            用户名:<input name="user_name" type="text"/>
        密码:<input name="password" type="password"/>
      <button type="submit">注册新用户</button>
        </@form.userform >
       </div>
       <div>
        <table>
            <tr>
                <th>登录名</th>
                <th>用户名</th>
                <th>密码</th>
                <th></th>
            </tr>
           <#list users as user>
                <tr>
                    <td>${user.login_name}</td>
                    <td>${user.user_name}</td>
                    <td>${user.password}</td>
                    <td><a fx="confirm[msg=你确定删除?]" href="delete/${user.uuser_id}">删除</a></td>
                    <td><a href="put/${user.uuser_id}">修改</a></td>
                </tr>
           </#list>
        </table>
        </div>
        <script type="text/javascript">
           UE.getEditor('editor')
        </script>
    </body>
</html>

文件上传

直接在ueditor里面的jsp文件夹下找到imageUp.jsp,什么不需要改,把里面的jar包扔到工程里面去就能跑了,如果需要改保存文件的路径可以把这字符串变了,up.setSavePath("../upload"),不知道为什么../../upload就不行,只能上一层目录,不能两层。

暂时看到这里,明天继续。bye

转载于:https://my.oschina.net/duoduo3369/blog/168788

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值