主题 : 关于jeecms整合json |
级别: 白丁
|
1# 发表于:2011-07-02 17:35:31 IP:116.66.*.*
|
||||
---|---|---|---|---|---|
级别: 白丁
|
2# 发表于:2011-07-02 17:38:08 IP:116.66.*.*
页面代码:
<p>Demo 1 计算并返回值</p> <div style="border: 1px solid #ccc; width: 250px;"> Add Two Numbers: <br/> <input id="inputNumber1" type="text" size="5"> + <input id="inputNumber2" type="text" size="9"> <input type="submit" id="demo1" value="Add" /> <br/> Sum: <br> <span id="sum">(Result will be shown here)</span> </div> <script type="text/javascript"> $(function() { $("#demo1").click(function(){ $.post("${base}/main/ajax/addTest.jhtml", {inputNumber1: $("#inputNumber1").val(), inputNumber2: $("#inputNumber2").val() }, function(data){ $("#sum").replaceWith('<span id="sum">'+ data + '</span>'); }); }); </script> |
||
---|---|---|---|
级别: 白丁
|
3# 发表于:2011-07-02 17:38:34 IP:116.66.*.*
Action类:
/** * 提交表单并进行运算. */ @RequestMapping(value = "/addTest.jhtml", method = RequestMethod.POST) public @ResponseBody Integer add( @RequestParam(value = "inputNumber1", required = true)Integer inputNumber1, @RequestParam(value = "inputNumber2", required = true)Integer inputNumber2) { // 实现运算 Integer sum = inputNumber1 + inputNumber2; System.out.println("sum: " + sum); // @ResponseBody 会自动的将返回值转换成JSON格式 // 但是你必须添加jackson的jar包!!! return sum; } |
||
---|---|---|---|
级别: 白丁
|
4# 发表于:2011-07-02 17:39:05 IP:116.66.*.*
application-context配置文件:
<?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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" 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.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" default-lazy-init="true"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/WEB-INF/config/jdbc.properties</value> </list> </property> </bean> <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> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingLocations"> <list> <value>classpath*:/com/jeecms/core/entity/hbm/*.hbm.xml</value> <value>classpath*:/com/jeecms/cms/entity/main/hbm/*.hbm.xml</value> <value>classpath*:/com/jeecms/cms/entity/assist/hbm/*.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect hibernate.show_sql=false hibernate.format_sql=false hibernate.query.substitutions=true 1, false 0 hibernate.jdbc.batch_size=20 hibernate.cache.use_query_cache=true </value> </property> <property name="entityInterceptor"> <ref local="treeInterceptor"/> </property> <property name="cacheProvider"> <ref local="cacheProvider"/> </property> <property name="lobHandler"> <ref bean="lobHandler" /> </property> </bean> <bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"/> <bean id="cacheProvider" class="com.jeecms.common.hibernate3.SpringEhCacheProvider"> <property name="configLocation"> <value>classpath:ehcache-hibernate.xml</value> </property> <property name="diskStoreLocation"> <value>/WEB-INF/cache/hibernate</value> </property> </bean> <bean id="treeInterceptor" class="com.jeecms.common.hibernate3.TreeIntercptor"/> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <mvc:annotation-driven/> <context:annotation-config/> <tx:annotation-driven transaction-manager="transactionManager" /> </beans> |
||
---|---|---|---|
1
共1页