<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 297,  comments - 1618,  trackbacks - 0

    基于注解的Spring MVC+Hiberntae簡單入門

    /阿蜜果

    日期/2012-11-28

    1、概述

    本文旨在搭建Spring MVC+Hibernate開發框架,通過一個簡單的demo講解Spring MVC的相關配置文件,以及通過注解方式實現簡單功能。

    開發框架:Spring + Spring MVC+HibernateSpring所用的版本為3.0.5)。

    數據庫:MySQL(數據庫名稱testdemo工程所用的表名為user_info)。

    2、開發框架搭建

    2.1 創建工程

             EclipseJava EE版本或MyEclipse中創建一個Dynamic Web Project。并創建如下包:

    1com.dao:系統的DAO

    2com.model:表的實體類(使用Hibernate),在該工程中不配置.hbm.xml映射文件,采取注解的方式;

    3com.service:業務邏輯接口類和實現類;

    4com.webSpring MVCControllor類;

    5com.configSpringSpring MVC的配置文件。

    創建成功后包結構如下所示:
       springmvctest
            src 
            ----com
                ----amigo
                    ----dao
                    ----model
                    ----service
                    ----web
             ----config
             WebContent
             ----META-INF
             ----WEB-INF
                 ----lib
                 ----classes

    2.2 引入相關包

             需要將SpringSpring MVCHibernateMySQL驅動、log4jc3p0數據源等的相關包引入。lib目錄下的jar包如下:
          antlr-2.7.6.jar
          aopalliance.jar
          asm-attrs.jar
          asm.jar
          c3p0-0.9.0.jar
          cglib-2.1.3.jar
          commons-beanutils-1.8.0.jar
          commons-beanutils-bean-collections-1.8.0.jar
          commons-betwixt-0.8.jar
          commons-collections-2.1.1.jar
          commons-digester-2.1.jar
          commons-discovery-0.2.jar
          commons-httpclient.jar
          commons-logging.jar
          dom4j-1.6.1.jar
          ehcache-1.2.3.jar
          ejb3-persistence.jar
          hibernate-annotations.jar
          hibernate-commons-annotations.jar
          hibernate-entitymanager.jar
          hibernate-validator.jar
          hibernate3.jar
          jaas.jar
          javassist.jar
          jaxen-1.1-beta-7.jar
          jaxrpc.jar
          jboss-archive-browsing.jar
          jdbc2_0-stdext.jar
          jta.jar
          log4j-1.2.11.jar
          mysql-connector-java-5.0.4-bin.jar
          org.springframework.aop-3.0.5.RELEASE.jar
          org.springframework.asm-3.0.5.RELEASE.jar
          org.springframework.aspects-3.0.5.RELEASE.jar
          org.springframework.beans-3.0.5.RELEASE.jar
          org.springframework.context-3.0.5.RELEASE.jar
          org.springframework.context.support-3.0.5.RELEASE.jar
          org.springframework.core-3.0.5.RELEASE.jar
          org.springframework.expression-3.0.5.RELEASE.jar
          org.springframework.instrument-3.0.5.RELEASE.jar
          org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
          org.springframework.jdbc-3.0.5.RELEASE.jar
          org.springframework.jms-3.0.5.RELEASE.jar
          org.springframework.orm-3.0.5.RELEASE.jar
          org.springframework.oxm-3.0.5.RELEASE.jar
          org.springframework.test-3.0.5.RELEASE.jar
          org.springframework.transaction-3.0.5.RELEASE.jar
          org.springframework.web-3.0.5.RELEASE.jar
          org.springframework.web.servlet-3.0.5.RELEASE.jar
          saaj.jar
          wsdl4j.jar
          xerces-2.6.2.jar
          xml-apis.jar

    2.3 配置文件

    2.3.1 配置web.xml

             web.xml中需要配置Spring的配置文件(applicationContext.xml)和Spring MVC配置文件(spring-mvc.xml),配置指定所有.do的請求都由SpringDispatcherServlet類進行處理。

    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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>springmvctest</display-name>
     
    <welcome-file-list>
        
    <welcome-file>index.html</welcome-file>
        
    <welcome-file>index.htm</welcome-file>
        
    <welcome-file>index.jsp</welcome-file>
     
    </welcome-file-list>
     
    <context-param>
            
    <param-name>contextConfigLocation</param-name>
            
    <param-value>classpath:config/applicationContext.xml</param-value>
        
    </context-param>
        
    <listener>
            
    <listener-class>    org.springframework.web.context.ContextLoaderListener
            
    </listener-class>
        
    </listener>
        
    <servlet>
            
    <servlet-name>spring-mvc</servlet-name>
            
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            
    <init-param>
                
    <param-name>contextConfigLocation</param-name>
                
    <param-value>classpath:config/spring-mvc.xml</param-value>
            
    </init-param>
            
    <load-on-startup>1</load-on-startup>
        
    </servlet>
        
    <servlet-mapping>
            
    <servlet-name>spring-mvc</servlet-name>
            
    <url-pattern>*.do</url-pattern>
        
    </servlet-mapping>
        
    <filter>
            
    <filter-name>encodingFilter</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>
            
    <init-param>
                
    <param-name>forceEncoding</param-name>
                
    <param-value>true</param-value>
            
    </init-param>
        
    </filter>
        
    <filter-mapping>
            
    <filter-name>encodingFilter</filter-name>
            
    <url-pattern>/*</url-pattern>
        </filter-mapping>
    </web-app>

     

    2.3.2 配置spring的配置文件

     

             Spring的配置文件applicationContext.xml文件中主要配置對Hibernate的事務的管理,該配置文件的參考配置如下:

    <?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"
    xmlns:aop
    ="http://www.springframework.org/schema/aop"
    xmlns:task
    ="http://www.springframework.org/schema/task"
        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
        http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/task   
    http://www.springframework.org/schema/task/spring-task-3.0.xsd"> 
        <context:annotation-config />

        
    <!-- 掃描annotation類,過濾Service,Repository -->
        
    <context:component-scan base-package="com.amigo" >
        
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
            
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />
        
    </context:component-scan>

        
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
            
    <property name="driverClass">
               
    <value>com.mysql.jdbc.Driver</value>
            
    </property>
            
    <property name="jdbcUrl">
    <value>jdbc:mysql://localhost/test</value> 
            </property>
            
    <property name="user">
                
    <value>root</value>
            
    </property>
            
    <property name="password">
                
    <value>123456</value>
            
    </property>
            
    <property name="maxPoolSize">
                
    <value>80</value>
            
    </property>
            
    <property name="minPoolSize">
                
    <value>1</value>
            
    </property>
            
    <property name="initialPoolSize">
                
    <value>1</value>
            
    </property>
            
    <property name="maxIdleTime">
                
    <value>20</value>
            
    </property>
        
    </bean>
        
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            
    <property name="dataSource" ref="dataSource"/>
            
    <property name="packagesToScan" value="com.amigo.model*" ></property>
            
    <property name="hibernateProperties">
                
    <props>
                    
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    
    <prop key="show_sql">true</prop>
                    
    <prop key="hibernate.jdbc.batch_size">20</prop>
                
    </props>
            
    </property>
        
    </bean>

        
    <!-- 不破壞數據庫,注冊SessionFactory -->
        
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            
    <property name="sessionFactory" ref="sessionFactory"></property>
        
    </bean>
        
    <bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
            
    <property name="transactionManager" ref="transactionManager"></property>
            
    <property name="transactionAttributes">
                
    <props>
                    
    <prop key="save*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="update*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="find*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="get*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="execute*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="load*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="merge*">PROPAGATION_REQUIRED</prop>
                    
    <prop key="add*">PROPAGATION_REQUIRED</prop>
                
    </props>
            
    </property>
        
    </bean>
        
    <bean
    class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
            
    <property name="beanNames">
                
    <list>
                    
    <value>*Service</value>
                
    </list>
            
    </property>
            
    <property name="interceptorNames">
                
    <list>
             
    <value>transactionInterceptor</value>
                
    </list>
            
    </property>
        
    </bean> 
    </beans>



    2.3.3 配置Spring MVC配置文件

     

    Spring MVC的配置文件spring-mvc.xml中主要是Controller的配置信息,該文件的參考配置如下:

    <?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"
    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/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">
        
    <context:annotation-config />
        
    <!--使Spring支持自動檢測組件,如注解的Controller -->
        
    <context:component-scan base-package="com.amigo.web"/>

        
    <bean id="viewResolver"      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix
    ="/WEB-INF"
              p:suffix
    =".jsp" />
        
        
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
        
    <!-- 啟動 Spring MVC 的注解功能,完成請求和注解 POJO 的映射 -->
        
    <bean     class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            
    <property name="messageConverters">
                
    <list>
                    
    <bean class="org.springframework.http.converter.StringHttpMessageConverter"> 
                    
    </bean>
                
    </list>
            
    </property>
        
    </bean>
    </beans>

     

    2.4 創建數據庫和表

    創建test數據庫和user_info表的SQL語句如下(為了簡便,user_info只有一個USER_NAME字段):

    CREATE DATABASE test;
    USER test;
    CREATE TABLE user_info (
     
    USER_NAME varchar(32NOT NULL,
     
    PRIMARY KEY (USER_NAME)
    ) ENGINE
    =InnoDB DEFAULT CHARSET=utf8;



    3、實例代碼

    3.1 DAO

    BaseHibernateDao類的代碼如下所示:

    package com.amigo.dao;

    import javax.annotation.Resource;

    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.springframework.dao.DataAccessException;
    import org.springframework.dao.DataAccessResourceFailureException;
    import org.springframework.dao.support.DaoSupport;
    import org.springframework.orm.hibernate3.HibernateTemplate;
    import org.springframework.orm.hibernate3.SessionFactoryUtils;

    public class BaseHibernateDao extends DaoSupport{
        
    private SessionFactory sessionFactory;
        
    private HibernateTemplate hibernateTemplate;
        
    public SessionFactory getSessionFactory() {
            
    return sessionFactory;
        }


        @Resource(name
    ="sessionFactory")
        
    public void setSessionFactory(SessionFactory sessionFactory) {
            
    this.sessionFactory = sessionFactory;
            
    this.hibernateTemplate=createHibernateTemplate(sessionFactory);
        }


        
    public Session getSession() {
            
    if (this.sessionFactory == null{
                
    throw new HibernateException("Session Create Fail,SessionFactory is null!");
            }

            
    return this.sessionFactory.getCurrentSession();
        }


        
    protected HibernateTemplate createHibernateTemplate(
                SessionFactory sessionFactory) 
    {
            
    return new HibernateTemplate(sessionFactory);
        }


        @Override
        
    protected void checkDaoConfig() throws IllegalArgumentException {
            
    if (this.hibernateTemplate == null{
                
    throw new IllegalArgumentException("'sessionFactory' or 'hibernateTemplate' is required");
            }

        }

        
        
    protected final Session getSession(boolean allowCreate)
                
    throws DataAccessResourceFailureException, IllegalStateException {
            
    return (!allowCreate ? SessionFactoryUtils.getSession(
                    getSessionFactory(), 
    false) : SessionFactoryUtils.getSession(
                    getSessionFactory(),

         
    this.hibernateTemplate.getEntityInterceptor(),    this.hibernateTemplate.getJdbcExceptionTranslator()));
        }


        
    protected final DataAccessException convertHibernateAccessException(
                HibernateException ex) 
    {
            
    return this.hibernateTemplate.convertHibernateAccessException(ex);
        }


        
    protected final void releaseSession(Session session) {
            SessionFactoryUtils.releaseSession(session, getSessionFactory());
            
    if(null!=session)session=null;
        }


        
    public final void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
            
    this.hibernateTemplate = hibernateTemplate;
        }


        
    public final HibernateTemplate getHibernateTemplate() {
            
    return this.hibernateTemplate;
        }

    }

    USER_INFO表的DaoUserInfoDao類的代碼如下所示:

    package com.amigo.dao;
    import org.springframework.stereotype.Repository;

    @Repository
    public class UserInfoDao extends BaseHibernateDao {
    }

     

    3.2 業務邏輯層

    接口類IHelloService的代碼如下:

    package com.amigo.service;
    public interface IHelloService {
        
    public int addUser(String userName) throws Exception;;
    }

    實現類HelloService類的代碼如下:

    package com.amigo.service;
    import javax.annotation.Resource;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.stereotype.Repository;
    import org.springframework.stereotype.Service;

    import com.amigo.dao.UserInfoDao;
    import com.amigo.model.UserInfo;

    @Service(
    "helloService")
    @Repository
    public class HelloService implements IHelloService {
        
    private static final Log log = LogFactory.getLog(HelloService.class);
        
    private UserInfoDao userDao;

        
    public UserInfoDao getUserDao() {
            
    return userDao;
        }


        @Resource
        
    public void setUserDao(UserInfoDao userDao) {
            
    this.userDao = userDao;
        }


        @Override
        
    public int addUser(String userName) throws Exception {
            log.info(
    "----------------addUser---------------");
            UserInfo userInfo 
    = new UserInfo();
            userInfo.setUserName(userName);
            userDao.getSession().save(userInfo);
            
    return 1;
        }

    }



    3.3 控制層

       控制類HelloControllor類接收userName參數,并調用相應的Service類將用戶名保存到USER_INFO表中,該類的代碼如下:

    package com.amigo.web;

    import javax.annotation.Resource;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    import com.amigo.service.IHelloService;

    @Controller
    @RequestMapping(
    "/test")
    public class HelloControllor {
        
    private static final Log log = LogFactory.getLog(HelloControllor.class);

        
    private IHelloService helloService;

        
    public IHelloService getHelloService() {
            
    return helloService;
        }


        @Resource
        
    public void setHelloService(IHelloService helloService) {
            
    this.helloService = helloService;
        }


        @RequestMapping(
    "/hello.do")
        
    public @ResponseBody 
            String sayHello(HttpServletRequest request, HttpServletResponse response) 
    throws Exception {
            request.setCharacterEncoding(
    "UTF-8");
            String userName 
    = request.getParameter("userName");
            log.info(
    "userName=" + userName);
            
    int resultCode = helloService.addUser(userName);
            String rspInfo 
    = "你好!" + userName + ",操作結果碼=" + resultCode;
            response.setHeader(
    "Content-type","text/html;charset=UTF-8"); 
            response.getOutputStream().write(rspInfo.getBytes(
    "UTF-8"));
            
    return "";
        }

    }

    @Controller注解標識一個控制器,@RequestMapping注解標記一個訪問的路徑;如果@RequestMapping注解在類級別上,則表示一相對路徑,在方法級別上,則標記訪問路徑;

    4、測試

    測試時可以通過訪問http://localhost:8080/springmvctest/test/hello.do?userName=amigo777,通過userName參數將用戶名添加到USER_INFO表中。

    從實例代碼可以看出,POJODAO層、Service層和Controller層都是采用注解的方式將servicedao注入的,減少了配置量,方便了開發工作。

    5、參考文檔

    1)《基于注解的Spring MVC簡單入門》:http://www.oschina.net/question/84460_9608

    posted on 2012-11-28 11:07 阿蜜果 閱讀(52588) 評論(12)  編輯  收藏 所屬分類: Java


    FeedBack:
    # re: 基于注解的Spring MVC+Hiberntae簡單入門
    2012-11-30 08:35 | 21
    Ext.namespace('ext.ptc.part.commpartview') //定義包名

    ext.ptc.part.commpartview.setConfigure = function(){ //定義類名稱
    this.checkboxGroup = new Ext.form.CheckboxGroup({
    layout : 'column',
    style : 'padding-left:15px;',
    items : [{
    xtype : 'compositefield',
    items : [{
    xtype :'checkbox',
    id : 'collapsible',
    name :'isCollapsible',
    inputValue : 'TRUE',
    boxLabel :'是否折疊'
    }]
    },{
    xtype : 'compositefield',
    items : [{
    xtype :'checkbox',
    id : 'endItem',
    name :'isEndItem',
    inputValue : 'TRUE',
    boxLabel :'是否頂層部件'
    }]
    }]

    });

    this.panel = new Ext.form.FormPanel({
    width : 500,
    height : 300,
    border : false,
    style :'padding: 10px 20px 2px 40px;',
    border : false,
    paramsAsHash : true,
    id :'panelConfig',
    baseParams : { oid : urlOid },
    api :{
    load : partToolsController.geItemConfigInfo,
    submit : partToolsController.saveItemConfigInfo
    },
    listeners : {
    'render' : function() {
    this.getForm().load({
    success : function(form, action) {
    if(action.result.data.isDynamic == 'TRUE'){
    document.getElementById('dynamic').checked = true;
    }

    },

    failure : function(form, action) {
    alert('load is failure!')
    }
    });
    }
    },
    items : [this.checkboxGroup ,{

    buttons : [{
    text :'保存',
    border :false,
    handler : function(){
    Ext.getCmp('panelConfig').getForm().submit({
    clientValidation: false,
    success: function(form, action) {
    //表單提交成功則
    var partURL = action.result.partURL;
    var exception = action.result.exception;
    //alert(partURL);
    if(!Ext.isEmpty(partURL)){
    location.href = partURL;
    }
    }
    });
    }
    }]
    }
    ]
    });


    //定義構造函數
    ext.ptc.part.commpartview.setConfigure.superclass.constructor.call(this,{

    region : 'center',
    renderTo : Ext.getBody(),
    autoHeight : true,
    border : false,
    items : [this.simple],
    scope : this,
    items :[this.panel],
    listeners : {
    'render' : function(){
    }
    }
    });

    };

    Ext.extend(ext.ptc.part.commpartview.setConfigure ,Ext.Panel,{ //定義繼承的父類
    //這里定義類的方法


    });





    //1、調用示例1
    var mainContent = Ext.getCmp('centerContent');
    mainContent.removeAll();
    mainContent.add(new ext.ptc.part.commpartview.setConfigure());
    mainContent.doLayout();

    //2、調用示例2(完整js文件)
    Ext.ns('ext.ptc.viewmain');
    Ext.onReady(function() {
    this.northMenuItem = new ext.ptc.part.commpartview.setConfigure();
    new Ext.Viewport({
    xtype : 'panel',
    layout : 'border',
    autoWidth : true,
    border : true,
    cls : 'wcshell',
    id : "mainpage",
    defaults : {
    split : true
    },
    items : [this.northMenuItem]
    });

    });



    //DirectStore
    var madstore = new Ext.data.DirectStore(
    {
    paramsAsHash : true,
    baseParams : {
    fileJson : '',
    replaceOrLeave : '',
    partTemplate : Ext.getCmp('id_usag_model').getValue()
    },
    api : {
    read : createUsageLinkController.getUsageLinkFromFile
    },
    reader : new Ext.data.JsonReader({
    fields : [ 'removeFlag', 'uploadPartNumber',
    'uploadPartNumberHref', 'description', 'quantity',
    'unit', 'lineNumber', 'isMustNeed', 'salePartType',
    'isPlanningPart', 'status', 'version', 'occName',
    'isLabelPart', 'quotePrice', 'packingABC',
    'template', 'hintkMsg', 'isSyncOK']
    }),
    listeners : {
    scope : this,
    load : function(p, records, options) {

    }
    }
    });  回復  更多評論
      
    # re: 基于注解的Spring MVC+Hiberntae簡單入門
    2012-11-30 09:50 | 王鵬飛
    spring mvc 研究中  回復  更多評論
      
    # re: 基于注解的Spring MVC+Hiberntae簡單入門
    2012-11-30 15:35 | 212
    filejson = Ext.getCmp('old_usage').getJsonValues();//上載文件
    var usagBomitems = Ext.getCmp('id_usag_BOMitemsPartjson').getStore().getJsonValues();//可編輯表格
    Ext.getCmp('id_usag_BOMitemsPartjson').getStore().api.read = createUsageLinkController.getUsageLinkFromFile;
    Ext.getCmp('id_usag_BOMitemsPartjson').getStore().load(
    {
    params : {
    fileJson : filejson,
    usagBomitems : usagBomitems
    },
    add : false //是否在后面加,true時,在表格后面直接加入數據,false清空數據再加入
    });



    org.json.JSONArray jsonArray = new org.json.JSONArray(usagBomitems); //將表格數據轉換為JSONArray
    JSONObject json = (JSONObject) jsonArray.get(i);//可理解表格的一行數據
    json.getString("isLabelPart")//獲取列的值
      回復  更多評論
      
    # re: 基于注解的Spring MVC+Hiberntae簡單入門
    2012-11-30 16:38 | 22
    客制化的jsp如果沒有包含OOTB的begin.jsp文件,需要在jsp中加入以下代碼以保證session不會丟失:
    <jsp:useBean id="wtcontext" class="wt.httpgw.WTContextBean" scope="request">
    <jsp:setProperty name="wtcontext" property="request" value="<%=request%>"/>
    </jsp:useBean>
    如果已包含begin.jsp文件,則不能加入上述代碼
    同時需要注意:如果有引用其他jsp文件,則只需要在一個文件中加上述代碼,不能重復添加。

    說明:
    2010年PDM升級出現了性能問題,查看jsp異常問題,發現jsp文件沒有保存windchill context session,會給系統帶來很大的性能壓力,也可能是造成系統后臺持續context錯誤的原因。
      回復  更多評論
      
    # re: 基于注解的Spring MVC+Hiberntae簡單入門[未登錄]
    2012-11-30 17:32 | 1
    //js中直接調用后臺
    partRelatedDocController.savePartDocRef(partoid,docoid,
    function(result, e){//回調函數
    if ("Success" == result) {
    window.opener.Ext.getCmp('addDocsRefenceStoreID').getStore().reload();
    window.close();
    } else {
    }

    })
    //后臺方法
    @ExtDirectMethod(group = "part")
    public String savePartDocRef(String partOid, String docOid)
    throws WTRuntimeException, WTException {
    String message = "Success";
    //
    //其它業務邏輯代碼
    //
    return message;
    }  回復  更多評論
      
    # re: 基于注解的Spring MVC+Hiberntae簡單入門[未登錄]
    2012-11-30 17:59 | 1
    //Json字符串轉換為后臺Bean
    private static ObjectMapper mapper = new ObjectMapper();
    UploadPartBean[] beans = mapper.readValue(dateJson,UploadPartBean[].class);
      回復  更多評論
      
    # re: 基于注解的Spring MVC+Hiberntae簡單入門
    2013-03-11 22:01 | 游客
    model層呢?  回復  更多評論
      
    # re: 基于注解的Spring MVC+Hibernate簡單入門
    2013-10-24 16:29 | 輕松熊
    您好,能貼一下你這里面用到的jar包么  回復  更多評論
      
    # re: 基于注解的Spring MVC+Hibernate簡單入門
    2014-03-30 11:02 | 最代碼
    最代碼網站上也分享了類似的代碼,可以參考下:
    整合Spring MVC,mybatis,hibernate,freemarker框架實現的自定義注解Validator驗證機制實現對敏感詞過濾的代碼分享,地址:http://www.zuidaima.com/share/1755786415246336.htm
      回復  更多評論
      
    # re: 基于注解的Spring MVC+Hibernate簡單入門
    2014-04-19 22:36 | 最代碼
    # re: 基于注解的Spring MVC+Hibernate簡單入門
    2015-10-10 11:37 | 我是你爹
    @212 你個傻逼 貼一段代碼干嘛!!!
      回復  更多評論
      
    # re: 基于注解的Spring MVC+Hibernate簡單入門[未登錄]
    2016-03-26 23:41 | h
    kk
      回復  更多評論
      
    <2012年11月>
    28293031123
    45678910
    11121314151617
    18192021222324
    2526272829301
    2345678

          生活將我們磨圓,是為了讓我們滾得更遠——“圓”來如此。
          我的作品:
          玩轉Axure RP  (2015年12月出版)
          

          Power Designer系統分析與建模實戰  (2015年7月出版)
          
         Struts2+Hibernate3+Spring2   (2010年5月出版)
         

    留言簿(263)

    隨筆分類

    隨筆檔案

    文章分類

    相冊

    關注blog

    積分與排名

    • 積分 - 2294306
    • 排名 - 3

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产综合成人亚洲区| 最近中文字幕完整版免费高清| 亚洲精品乱码久久久久久按摩 | 亚洲综合色区在线观看| 日韩免费高清大片在线| 亚洲国产精品成人午夜在线观看| 亚洲日韩在线观看| 99爱在线精品免费观看| 日韩在线视频线视频免费网站| 亚洲性天天干天天摸| 国产伦精品一区二区三区免费迷 | 免费在线观看h片| 牛牛在线精品观看免费正| 99亚洲精品高清一二区| 亚洲色偷拍区另类无码专区| 一色屋成人免费精品网站| 国产在线精品一区免费香蕉| 亚洲乱妇熟女爽到高潮的片| 亚洲VA中文字幕不卡无码| 国产又粗又猛又爽又黄的免费视频 | 最近2019中文免费字幕在线观看| 亚洲中文字幕久久精品无码A | 国内精品99亚洲免费高清| 在线永久免费的视频草莓| 一个人看的www免费高清| 亚洲国产日韩综合久久精品| 国产亚洲精AA在线观看SEE| 国产一区在线观看免费| 丁香花免费完整高清观看| 久久免费福利视频| 一个人看的免费视频www在线高清动漫 | 午夜无码A级毛片免费视频| 牛牛在线精品观看免费正| 亚洲精品无码久久久久A片苍井空| 好看的亚洲黄色经典| 亚洲无码精品浪潮| 又爽又黄无遮挡高清免费视频| 欧洲乱码伦视频免费| 99re视频精品全部免费| 青柠影视在线观看免费高清| 久青草国产免费观看|