主頁 > 軟體設計 > SSH框架之Spring+Struts2+Hibernate整合篇

SSH框架之Spring+Struts2+Hibernate整合篇

2020-09-10 18:46:20 軟體設計

回顧 -Hibernate框架        ORM: 物件關系映射.把資料庫表和JavaBean通過映射的組態檔映射起來,        操作JavaBean物件,通過映射的組態檔生成SQL陳述句,自動執行.操作資料庫.     1: 類名.hbm.xml 映射組態檔.    2: hibernate.cfg.xml 核心組態檔.    3: 使用Hibernate提供的API操作.    Struts2框架 : 和客戶端進行互動    1. 在web.xml配置過濾器.    2. struts.xml組態檔.        Spring框架    1. applicationContext.xml配置    2. 核心IOC和AOP    3. 事務管理.    CustomerAction類    在struts.xml配置中配置的    1. Action物件由Struts2框架創建的.        CustomerAction:創建CustomerAction物件,由Struts2框架創建的    --->    Spring的IOC容器中物件,找customerService物件,默認按名稱找的.            2. Action物件也可以由Spring框架類創建        <bean id="customerAction" class="com.baidu.customer.action.CustomerAction" scope="prototype">            <property name="customerService" ref="customerService"/>        </bean>                <action name="customerAction_*" class="customerAction" method="{1}">            <result name="initSave">/jsp/customer/add.jsp</result>        </action>        day67_Spring_05            第1章整合前的準備        1.1整合說明        a.獨立式整合指的是三個框架都使用自己的組態檔,        b.引入式整合指的是hibernate主組態檔中的內容都配置到spring組態檔中        c.在整合程序中,確保每步都運行成功,然后在繼續往下做,        d.整合中使用的案例是客戶的保存和串列查詢操作,        e.后面的三種整合方式都基于1.2中的環境準備,        1.2環境準備        1.2.1第一步:創建java web工程        此處使用Servlet2.5規范,        1.2.2第二步:創建資料庫和表結構        create database crm;        use crm;        /*創建客戶表*/        CREATE TABLE `cst_customer` (          `cust_id` bigint(32) NOT NULL AUTO_INCREMENT COMMENT '客戶編號(主鍵)',          `cust_name` varchar(32) NOT NULL COMMENT '客戶名稱(公司名稱)',          `cust_source` varchar(32) DEFAULT NULL COMMENT '客戶資訊來源',          `cust_industry` varchar(32) DEFAULT NULL COMMENT '客戶所屬行業',          `cust_level` varchar(32) DEFAULT NULL COMMENT '客戶級別',          `cust_address` varchar(128) DEFAULT NULL COMMENT '客戶聯系地址',          `cust_phone` varchar(64) DEFAULT NULL COMMENT '客戶聯系電話',          PRIMARY KEY (`cust_id`)        ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;        1.2.3第三步:撰寫物體類        /**         * 客戶的物體類(資料模型)         */        public class Customer implements Serializable {            private Long custId;            private String custName;            private String custSource;            private String custIndustry;            private String custLevel;            private String custAddress;            private String custPhone;            public Long getCustId() {                return custId;            }            public void setCustId(Long custId) {                this.custId = custId;            }            public String getCustName() {                return custName;            }            public void setCustName(String custName) {                this.custName = custName;            }            public String getCustSource() {                return custSource;            }            public void setCustSource(String custSource) {                this.custSource = custSource;            }            public String getCustIndustry() {                return custIndustry;            }            public void setCustIndustry(String custIndustry) {                this.custIndustry = custIndustry;            }            public String getCustLevel() {                return custLevel;            }            public void setCustLevel(String custLevel) {                this.custLevel = custLevel;            }            public String getCustAddress() {                return custAddress;            }            public void setCustAddress(String custAddress) {                this.custAddress = custAddress;            }            public String getCustPhone() {                return custPhone;            }            public void setCustPhone(String custPhone) {                this.custPhone = custPhone;            }            @Override            public String toString() {                return "Customer [custId=" + custId + ", custName=" + custName + ", custSource=" + custSource                        + ", custIndustry=" + custIndustry + ", custLevel=" + custLevel + ", custAddress=" + custAddress                        + ", custPhone=" + custPhone + "]";            }            }        1.2.4第四步:撰寫業務層介面和實作類        /**         * 客戶的業務層介面         */        public interface ICustomerService {            /**             * 查詢所有客戶             * @return             */            List<Customer> findAllCustomer();                        /**             * @param customer             */            void saveCustomer(Customer customer);        }        /**         * 客戶的業務層實作類         */        public class CustomerServiceImpl implements ICustomerService {            private ICustomerDao customerDao;            public void setCustomerDao(ICustomerDao customerDao) {                this.customerDao = customerDao;            }            @Override            public List<Customer> findAllCustomer() {                return customerDao.findAllCustomer();            }            @Override            public void saveCustomer(Customer customer) {                customerDao.saveCustomer(customer);            }        }        1.2.5第六步:創建持久層介面        /**         * 客戶的持久層介面         */        public interface ICustomerDao {                        /**             * 查詢所有客戶             * @return             */            List<Customer> findAllCustomer();                        /**             * 保存客戶             * @param customer             */            void saveCustomer(Customer customer);        }        注意:做上述操作時,并不需要匯入任何jar包,        第2章基于XML的獨立式整合        2.1保證spring框架在web工程中獨立運行        2.1.1第一步:拷貝spring的ioc,aop和事務控制三組jar包        2.1.2第二步:撰寫spring組態檔并匯入約束        <?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:aop="http://www.springframework.org/schema/aop"                xmlns:tx="http://www.springframework.org/schema/tx"                 xsi:schemaLocation="http://www.springframework.org/schema/beans                         http://www.springframework.org/schema/beans/spring-beans.xsd                        http://www.springframework.org/schema/tx                         http://www.springframework.org/schema/tx/spring-tx.xsd                        http://www.springframework.org/schema/aop                         http://www.springframework.org/schema/aop/spring-aop.xsd">        </beans>        2.1.3第三步:把業務層和持久層配置到檔案中        <!-- 把資源交給spring來管理 -->        <!-- 配置dao -->        <bean id="customerDao" class="com.baidu.dao.impl.CustomerDaoImpl"></bean>                    <!-- 配置service -->        <bean id="customerService" class="com.baidu.service.impl.CustomerServiceImpl">            <!-- 注入dao -->            <property name="customerDao" ref="customerDao"></property>        </bean>        持久層實作類代碼:            此時不要做任何操作,就輸出一句話,目的是測驗spring框架搭建的結果,        /**         * 客戶的持久層實作類         */        public class CustomerDaoImpl implements ICustomerDao {            @Override            public List<Customer> findAllCustomer() {                    System.out.println("查詢了所有用戶");                return null;            }            @Override            public void saveCustomer(Customer customer) {                System.out.println("保存了用戶");            }        }        2.1.4第四步:測驗spring能否獨立運行        /**         * 測驗類,測驗spring框架可以獨立運行         */        public class Spring01Test {            public static void main(String[] args) {                //1.獲取spring容器                ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");                //2.跟Id獲取bean物件                ICustomerService customerService = (ICustomerService) ac.getBean("customerService");                customerService.findAllCustomer();            }        }        2.2保證hibernate框架能夠在web工程中獨立運行        2.2.1第一步:拷貝hibernate必備jar包到工程的lib目錄                 2.2.2第二步:撰寫物體類的映射檔案        <?xml version="1.0" encoding="UTF-8"?>        <!DOCTYPE hibernate-mapping PUBLIC             "-//Hibernate/Hibernate Mapping DTD 3.0//EN"            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">        <hibernate-mapping package="com.baidu.domain">            <class name="Customer" table="cst_customer">                <id name="custId" column="cust_id">                    <generator class="native"></generator>                </id>                <property name="custName" column="cust_name"></property>                <property name="custSource" column="cust_source"></property>                <property name="custIndustry" column="cust_industry"></property>                <property name="custLevel" column="cust_level"></property>                <property name="custAddress" column="cust_address"></property>                <property name="custPhone" column="cust_phone"></property>            </class>        </hibernate-mapping>        2.2.3第三步:撰寫hibernate主組態檔        <?xml version="1.0" encoding="UTF-8"?>        <!DOCTYPE hibernate-configuration PUBLIC            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"            "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">        <hibernate-configuration>            <session-factory>                <!-- 1.連接資料庫的資訊 -->                <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>                <property name="hibernate.connection.url">jdbc:mysql:///crmroperty>                <property name="hibernate.connection.username">root</property>                <property name="hibernate.connection.password">1234</property>                <!-- 2.hibernate的基本配置 -->                <!-- 資料庫的方言-->                <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>                <!-- 是否顯示sql陳述句-->                <property name="hibernate.show_sql">true</property>                <!-- 是否格式化sql陳述句-->                <property name="hibernate.format_sql">false</property>                <!-- 采用何種方式生成資料庫表結構 -->                <property name="hibernate.hbm2ddl.auto">update</property>                <!-- 配置使用c3p0資料源 -->                <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>                <!--把session系結到當前執行緒上的配置-->                <property name="hibernate.current_session_context_class">thread</property>                <!-- 3.映射檔案的位置 -->                <mapping resource="com/baidu/domain/Customer.hbm.xml"/>            </session-factory>        </hibernate-configuration>        2.2.4第四步:撰寫測驗類-測驗保存客戶        /**         * hibernate的測驗類         *         保證hibernate框架可以獨立運行         */        public class Hibernate02Test {            @Test            public void testFindAll(){                //1.讀取組態檔                Configuration cfg = new Configuration();                cfg.configure();                //2.根據組態檔獲取SessionFactory                SessionFactory factory = cfg.buildSessionFactory();                //3.根據SessionFactory獲取一個Session                Session s = factory.getCurrentSession();                //4.開啟事務                Transaction tx = s.beginTransaction();                //5.執行操作                Query query = s.createQuery("from Customer");                List list = query.list();                for(Object o : list){                    System.out.println(o);                }                //6.提交事務                tx.commit();                //7.釋放資源                factory.close();            }                        @Test            public void testSave(){                Customer c = new Customer();                c.setCustName("傳智專修學院");                //1.讀取組態檔                Configuration cfg = new Configuration();                cfg.configure();                //2.根據組態檔獲取SessionFactory                SessionFactory factory = cfg.buildSessionFactory();                //3.根據SessionFactory獲取一個Session                Session s = factory.getCurrentSession();                //4.開啟事務                Transaction tx = s.beginTransaction();                //5.執行操作                s.save(c);                //6.提交事務                tx.commit();                //7.釋放資源                factory.close();            }        }        2.3整合spring和hibernate框架        2.3.1明確        a.Spring和Hibernate的整合就是spring接管SessionFactory的創建        b.Spring針對Hiberante的操作有一個封裝的物件HibernateTemplate        c.和JdbcTemplate一樣,HibernateTemplate也有一個HibernateDaoSupport        d.HibernateTemplate和HibernateDaoSupport都在spring-orm-4.2.4.RELEASE.jar中        e.我們Dao采用繼承HiberanteDaoSupport的方式撰寫,它一樣不能用于注解配置,        2.3.2整合步驟        2.3.2.1第一步:在spring組態檔中配置SessionFactory        <!-- 配置SessionFactory -->        <bean id="sessionFactory"                     class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">        <!-- 使用的是hibernate主組態檔中的內容,我們只需要指定hibernate主組態檔的所在位置 -->            <property name="configLocation" value="https://www.cnblogs.com/haizai/p/classpath:hibernate.cfg.xml"/>        </bean>        2.3.2.2第二步:改造Dao繼承HibernateDaoSupport        /**         * 客戶的持久層實作類         */        public class CustomerDaoImpl extends HibernateDaoSupport implements ICustomerDao {            @Override            public List<Customer> findAllCustomer() {                    return (List<Customer>) getHibernateTemplate().find("from Customer");            }            @Override            public void saveCustomer(Customer customer) {                getHibernateTemplate().save(customer);            }        }        2.3.2.3第三步:在spring組態檔中給Dao注入SessionFactory        <!-- 配置dao -->        <bean id="customerDao" class="com.baidu.dao.impl.CustomerDaoImpl">            <property name="sessionFactory" ref="sessionFactory"></property>        </bean>        2.3.2.4第四步:測驗        /**         * 整合spring和hibernate的測驗類         * spring整合Junit         *     第一步:拷貝jar包         *         spring-junit-4.2.4.jar         *  第二步:使用注解替換運行器(原來junit的main方法)         *      @RunWith(支持spring的main方法)         *      @ContextConfiguration(指定spring的組態檔位置)         */        @RunWith(SpringJUnit4ClassRunner.class)        @ContextConfiguration(locations={"classpath:bean.xml"})        public class SpringHibernate03Test {                        @Autowired            private ICustomerService customerService;            @Test            public void testFindAll(){                List list = customerService.findAllCustomer();                for(Object o : list){                    System.out.println(o);                }            }                        @Test            public void testSave(){                Customer c = new Customer();                c.setCustName("傳智學院test");                        customerService.saveCustomer(c);            }        }        測驗結果:            無論保存還是查詢都運行失敗!            按常理來說,我們沒有配置事務,保存失敗是可以理解的,為什么查詢也會失敗呢?        分析原因:            是由于spring的HibernateTemplate物件在使用Session時,spring創建了Session的代理物件,在這個程序中,spring對hibernate系結Session到當前執行緒的配置不認識了,所以運行失敗,        2.3.2.5第五步:修改把Session系結到當前執行緒上        <!-- 是hibernate把session系結到當前執行緒上的配置         <property name="hibernate.current_session_context_class">thread</property>-->        <!-- 是spring把sesion系結到當前執行緒上的配置 -->        <property name="hibernate.current_session_context_class">            org.springframework.orm.hibernate5.SpringSessionContext        </property>        此時再運行剛才的測驗:                查詢可以使用了,保存不能使用,原因是沒有事務,        2.3.3配置Spring的事務        2.3.3.1第一步:配置事務管理器并注入SessionFactory        <!-- 配置事務管理器 -->        <bean id="transactionManager"                 class="org.springframework.orm.hibernate5.HibernateTransactionManager">            <!-- 注入SessionFactory -->            <property name="sessionFactory" ref="sessionFactory"></property>        </bean>        2.3.3.2第二步:配置事務的通知及通知的屬性        <!-- 配置事務的通知 -->        <tx:advice id="txAdvice" transaction-manager="transactionManager">            <!-- 配置事務的屬性 -->            <tx:attributes>                <tx:method name="*" read-only="false" propagation="REQUIRED"/>                <tx:method name="find*" read-only="true" propagation="SUPPORTS"/>            </tx:attributes>        </tx:advice>        2.3.3.3第三步:配置AOP建立切入點運算式和事務通知的關系        <!-- 配置aop -->        <aop:config>            <!-- 配置通用切入點運算式 -->            <aop:pointcut expression="execution(* com.baidu.service.impl.*.*(..))" id="pt1"/>            <!-- 建立事務通知和切入點運算式的對應關系 -->            <aop:advisor advice-ref="txAdvice" pointcut-ref="pt1"/>        </aop:config>        再次測驗:            此時保存和查詢都可以正常使用了,        2.4保證struts2框架能夠在web工程中獨立運行        2.4.1第一步:拷貝struts2的必備jar包        要把畫紅線的jar包刪掉,因為hibernate中有個高版本的,        2.4.2第二步:在類的類的根路徑下撰寫struts.xml檔案并匯入約束        <?xml version="1.0" encoding="UTF-8"?>        <!DOCTYPE struts PUBLIC            "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"            "http://struts.apache.org/dtds/struts-2.3.dtd">        <struts>            <!-- 開啟開發者模式 -->            <constant name="struts.devMode" value="https://www.cnblogs.com/haizai/p/true"></constant>        </struts>        2.4.3第三步:在web.xml中配置struts2的核心過濾器        <filter>            <filter-name>struts2</filter-name>            <filter-class>                org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter            </filter-class>        </filter>        <filter-mapping>            <filter-name>struts2</filter-name>            <url-pattern>/*</url-pattern>        </filter-mapping>        2.4.4第四步:匯入jsp頁面        2.4.5第五步:修改menu.jsp        <A class=style2             href="https://www.cnblogs.com/haizai/p/${pageContext.request.contextPath}/customer/addUICustomer.action"              target=main>            - 新增客戶        </A>        2.4.6第六步:在struts.xml中配置action        <!--  獲取添加客戶頁面 -->        <action name="addUICustomer"                      method="addUICustomer">            <result name="addUICustomer">/jsp/customer/add.jsp</result>        </action>        2.4.7第七步:撰寫動作類和方法        /**         * 客戶的動作類        */        public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {            private Customer customer = new Customer();            @Override            public Customer getModel() {                return customer;            }                        /**             * 獲取添加客戶頁面             * @return             */            public String addUICustomer(){                return "addUICustomer";            }        }        2.4.8第八步:測驗        運行結果:通過點擊【新增客戶】可以跳轉到客戶添加頁面        2.5整合spring和struts2        2.5.1明確        a.spring整合struts2就是讓spring接管action的創建        b.action是多例的,配置到spring中需要設定scope屬性為多例        2.5.2整合步驟        2.5.2.1第一步:拷貝struts2-spring-plugin-2.3.24.jar到lib目錄        2.5.2.2第二步:在action中使用建構式獲取Service物件        public CustomerAction(){            ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(                                    ServletActionContext.getServletContext());                //由于動作類是多例的,每次都會創建容器,導致資源的浪費,一個應用應該只有一個容器                System.out.println(ac);                customerService = (ICustomerService) ac.getBean("customerService");            }        2.5.2.3第三步:測驗        運行結果:查詢客戶串列測驗通過,保存測驗通過,        2.6優化配置        2.6.1配置spring的監聽器        在上面2.5.2.2小節中有這么一句:            由于動作類是多例的,每次都會創建容器,導致資源的浪費,一個應用應該只有一個容器        問題:            如何解決呢?        答案:            只要讓容器在應用加載時創建,應用卸載時銷毀就可以,        問題:            我們怎么知道應用何時加載了呢?        答案:            ServletContext物件創建了,就表示當前應用已經被服務器加載了,        問題:            我們怎么知道ServletContext物件創建了呢?        答案:            ServletContextListener監聽器可以監聽到ServletContext物件的創建和銷毀,        Spring框架為我們提供了一個監聽器:ContextLoaderListener,        它是ServletContextListener介面的實作類,負責監聽ServletContext物件的創建,為我們創建容器,監聽ServletContext物件的銷毀,銷毀容器,        我們只需要配置上即可,        ContextLoaderListener在spring-web-4.2.4.RELEASE.jar中        所以我們要先匯入這個jar包,        ,在web.xml中配置監聽器:        <listener>            <listener-class>                org.springframework.web.context.ContextLoaderListener            </listener-class>        </listener>        當配置了此監聽器后,就不需要使用Action的建構式了,可以把建構式那段洗掉了,        此監聽器只能讀取WEB-INF目錄中的名稱為applicationContext.xml的組態檔,這顯然限制了我們的配置,        我們可以通過配置全域初始化引數的方式,指定spring組態檔的位置.        2.6.2配置指定spring組態檔的位置        我們把spring組態檔放到此處,需要配置全域初始化引數:        <context-param>            <param-name>contextConfigLocation</param-name>            <param-value>classpath:config/spring/applicationContext.xml</param-value>        </context-param>        2.6.3分檔案撰寫spring配置        我們寫到這里,其實搭建環境已經基本結束了,但是發現spring的組態檔雜亂無章,使我們在找配置的時候,很難一下找到,所以我們采用分組態檔撰寫的方式,        2.6.3.1撰寫主組態檔引入其他組態檔        <?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:aop="http://www.springframework.org/schema/aop"                xmlns:tx="http://www.springframework.org/schema/tx"                 xsi:schemaLocation="http://www.springframework.org/schema/beans                     http://www.springframework.org/schema/beans/spring-beans.xsd                    http://www.springframework.org/schema/tx                     http://www.springframework.org/schema/tx/spring-tx.xsd                    http://www.springframework.org/schema/aop                     http://www.springframework.org/schema/aop/spring-aop.xsd">            <!-- 引入其他spring組態檔 -->            <import resource="applicationContext-customer.xml"/>            <import resource="applicationContext-jdbc.xml"/>            <import resource="applicationContext-tx.xml"/>        </beans>        2.6.3.2撰寫針對需求的組態檔applicationContext-customer.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:aop="http://www.springframework.org/schema/aop"                xmlns:tx="http://www.springframework.org/schema/tx"                 xsi:schemaLocation="http://www.springframework.org/schema/beans                     http://www.springframework.org/schema/beans/spring-beans.xsd                    http://www.springframework.org/schema/tx                     http://www.springframework.org/schema/tx/spring-tx.xsd                    http://www.springframework.org/schema/aop                     http://www.springframework.org/schema/aop/spring-aop.xsd">            <!-- 把資源交給spring來管理 -->            <!-- 配置dao -->            <bean id="customerDao" class="com.baidu.dao.impl.CustomerDaoImpl">                <property name="sessionFactory" ref="sessionFactory"></property>            </bean>                        <!-- 配置service -->            <bean id="customerService"                             class="com.baidu.service.impl.CustomerServiceImpl">                <!-- 注入dao -->                <property name="customerDao" ref="customerDao"></property>            </bean>        </beans>        2.6.3.3撰寫資料庫連接的組態檔applicationContext-jdbc.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:aop="http://www.springframework.org/schema/aop"                xmlns:tx="http://www.springframework.org/schema/tx"                 xsi:schemaLocation="http://www.springframework.org/schema/beans                     http://www.springframework.org/schema/beans/spring-beans.xsd                    http://www.springframework.org/schema/tx                     http://www.springframework.org/schema/tx/spring-tx.xsd                    http://www.springframework.org/schema/aop                     http://www.springframework.org/schema/aop/spring-aop.xsd">                        <!-- 配置SessionFactory -->            <bean id="sessionFactory"                     class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">            <!-- 使用的是hibernate主組態檔中的內容,我們只需要指定hibernate組態檔的位置 -->                <property name="configLocation"                            value="classpath:config/hibernate/hibernate.cfg.xml">/>            </bean>        </beans>        2.6.3.4撰寫事務控制的組態檔applicationContext-tx.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:aop="http://www.springframework.org/schema/aop"                xmlns:tx="http://www.springframework.org/schema/tx"                 xsi:schemaLocation="http://www.springframework.org/schema/beans                     http://www.springframework.org/schema/beans/spring-beans.xsd                    http://www.springframework.org/schema/tx                     http://www.springframework.org/schema/tx/spring-tx.xsd                    http://www.springframework.org/schema/aop                     http://www.springframework.org/schema/aop/spring-aop.xsd">                        <!-- 配置事務管理器 -->            <bean id="transactionManager"                 class="org.springframework.orm.hibernate5.HibernateTransactionManager">                <!-- 注入SessionFactory -->                <property name="sessionFactory" ref="sessionFactory"></property>            </bean>                        <!-- 配置事務的通知 -->            <tx:advice id="txAdvice" transaction-manager="transactionManager">                <!-- 配置事務的屬性 -->                <tx:attributes>                    <tx:method name="*" read-only="false" propagation="REQUIRED"/>                    <tx:method name="find*" read-only="true" propagation="SUPPORTS"/>                </tx:attributes>            </tx:advice>                        <!-- 配置aop -->            <aop:config>                <!-- 配置通用切入點運算式 -->                <aop:pointcut expression="execution(* com.baidu.service.impl.*.*(..))"                                 id="pt1"/>                <!-- 建立事務通知和切入點運算式的對應關系 -->                <aop:advisor advice-ref="txAdvice" pointcut-ref="pt1"/>            </aop:config>        </beans>        2.6.4配置指定struts2組態檔位置        我們的spring和hibernate組態檔都存到了src/config/的對應包中了,只有struts2組態檔還在類的根路徑下,它也可以通過配置的方式指定struts.xml的位置,配置的是過濾器的初始化引數,初始化引數的name和value都是固定寫法,        <filter>            <filter-name>struts2</filter-name>            <filter-class>                org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter            </filter-class>            <init-param>                <param-name>config</param-name>                <param-value>                    struts-default.xml,struts-plugin.xml,config/struts/struts.xml                </param-value>            </init-param>        </filter>        <filter-mapping>            <filter-name>struts2</filter-name>            <url-pattern>/*</url-pattern>        </filter-mapping>        2.6.5分檔案撰寫struts2組態檔        當我們后面做的模塊越來越多,struts2一個組態檔寫起來也會雜亂無章,所以我們也可以把struts2的組態檔分開撰寫,        2.6.5.1撰寫struts2的主組態檔struts.xml        <?xml version="1.0" encoding="UTF-8"?>        <!DOCTYPE struts PUBLIC            "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"            "http://struts.apache.org/dtds/struts-2.3.dtd">        <struts>            <!-- 開啟開發者模式 -->            <constant name="struts.devMode" value="https://www.cnblogs.com/haizai/p/true"></constant>                        <package name="myDefault" extends="struts-default" abstract="true">                <!--  有公共的配置就寫在此處,沒有就空著 -->            </package>            <!--引入其他struts2組態檔 -->            <include file="config/struts/struts-customer.xml"></include>        </struts>        2.6.5.2針對不同模塊撰寫不同的組態檔struts-customer.xml        <?xml version="1.0" encoding="UTF-8"?>        <!DOCTYPE struts PUBLIC            "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"            "http://struts.apache.org/dtds/struts-2.3.dtd">        <struts>            <package name="customer" extends="myDefault" namespace="/customer">                <!--  獲取添加客戶頁面 -->                <action name="addUICustomer"                                                  method="addUICustomer">                    <result name="addUICustomer">/jsp/customer/add.jsp</result>                </action>                                <!--  查詢客戶串列 -->                <action name="findAllCustomer"                                                  method="findAllCustomer">                    <result name="findAllCustomer">/jsp/customer/list.jsp</result>                </action>            </package>        </struts>        2.6.6管理Action的兩種方式        2.6.6.1第一種方式:讓struts2自己來管理        此種方式就是在action標簽的class屬性中提供動作類的全限定類名,        <action name="addUICustomer"                                  method="addUICustomer">            <result name="addUICustomer">/jsp/customer/add.jsp</result>        </action>        2.6.6.2第二種方式:讓spring來管理(實際開發中采用的方式)        此種方式就是在spring組態檔中配置Action,在struts2組態檔action標簽的class屬性里寫bean的id,        spring組態檔:        <!-- 配置Action -->        <bean id="customerAction"                  scope="prototype">            <!-- 注入service -->            <property name="customerService" ref="customerService"></property>        </bean>            struts2組態檔:        <!--  獲取添加客戶頁面 -->        <action name="addUICustomer"  method="addUICustomer">            <result name="addUICustomer">/jsp/customer/add.jsp</result>        </action>        第3章基于XML的引入式整合        3.1明確        引入式整合就是把hibernate.cfg.xml中的配置都挪到spring的組態檔中        3.2配置方式        <!-- 配置SessionFactory -->        <bean id="sessionFactory"                 >                <!-- 1、連接資料庫的資訊 -->                <property name="dataSource" ref="dataSource"></property>                <!-- 2、hibernate的基本配置 -->                <property name="hibernateProperties">                    <props>                        <!-- 資料庫的方言-->                        <prop key="hibernate.dialect">                                org.hibernate.dialect.MySQLDialect                        </prop>                        <!-- 是否顯示sql陳述句-->                        <prop key="hibernate.show_sql">true</prop>                        <!-- 是否格式化sql陳述句-->                        <prop key="hibernate.format_sql">false</prop>                        <!-- 采用何種方式生成資料庫表結構 -->                        <prop key="hibernate.hbm2ddl.auto">update</prop>                        <!-- 是spring把sesion系結到當前執行緒上的配置 -->                        <prop key="hibernate.current_session_context_class">                            org.springframework.orm.hibernate5.SpringSessionContext                        </prop>                    </props>                </property>                <!-- 3、映射檔案的位置                     mappingResources:配置映射檔案的位置,需要寫映射檔案名稱,                                      并且有幾個映射檔案,就要寫幾個<value></value>,                    mappingLocations:配置映射檔案的位置,需要寫映射檔案名稱,可以使用通配符,                    mappingDirectoryLocations:配置映射檔案的位置,直接寫到包的目錄即可,                -->                <property name="mappingLocations">                    <array>                        <value>classpath:com/baidu/domain/*.hbm.xml</value>                    </array>                </property>            </bean>        <!-- 配置資料源 -->        <bean id="dataSource" >            <property name="driverClass" value="https://www.cnblogs.com/haizai/p/com.mysql.jdbc.Driver"></property>            <property name="jdbcUrl" value="https://www.cnblogs.com/haizai/p/jdbc:mysql:///crm"></property>            <property name="user" value="https://www.cnblogs.com/haizai/p/root"></property>            <property name="password" value="https://www.cnblogs.com/haizai/p/1234"></property>        </bean>        第4章基于注解的整合        4.1明確        a.注解整合仍然使用上面的環境,就是把xml的配置全部換成注解        b.spring的注解整合有兩種方式,一種是用xml檔案,一種是純注解,        c.hibernate注解整合是把物體類映射改為JPA注解映射        4.2整合步驟-spring使用xml檔案        4.2.1spring配置使用注解實作        4.2.1.1第一步:匯入spring的必備jar包        之前的環境已經匯入,略,        4.2.1.2第二步:在spring組態檔中匯入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:aop="http://www.springframework.org/schema/aop"                xmlns:tx="http://www.springframework.org/schema/tx"                 xmlns:context="http://www.springframework.org/schema/context"                 xsi:schemaLocation="http://www.springframework.org/schema/beans                         http://www.springframework.org/schema/beans/spring-beans.xsd                        http://www.springframework.org/schema/tx                         http://www.springframework.org/schema/tx/spring-tx.xsd                        http://www.springframework.org/schema/aop                         http://www.springframework.org/schema/aop/spring-aop.xsd                        http://www.springframework.org/schema/context                         http://www.springframework.org/schema/context/spring-context.xsd">        </beans>        4.2.1.3第三步:在spring組態檔中配置要掃描的包        <!-- 配置spring運行要掃描的包 -->        <context:component-scan base-package="com.baidu"></context:component-scan>        4.2.1.4第四步:把action,service和dao都用注解配置        /**         * 客戶的動作類         */        @Controller("customerAction")        @Scope("prototype")        public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {            @Autowired            private ICustomerService customerService;            //action中的方法不變        }        /**         * 客戶的業務層實作類         */        @Service("customerService")        public class CustomerServiceImpl implements ICustomerService {            @Autowired            private ICustomerDao customerDao;            //service中的方法不變        }        /**         * 客戶的持久層實作類         */        @Repository("customerDao")        public class CustomerDaoImpl implements ICustomerDao {            //dao中必須自己定義HibernateTemplate,不能繼承HibernateDaoSupport了            @Autowired            private HibernateTemplate hibernateTemplate;            //dao中的方法不變        }        4.2.1.5第五步:在spring組態檔中配置HiernateTemplate        <!-- 配置HibernateTemplate -->        <bean id="hibernateTemplate"                 class="org.springframework.orm.hibernate5.HibernateTemplate">            <!-- 注入SessionFactory -->            <property name="sessionFactory" ref="sessionFactory"></property>        </bean>        4.2.1.6第六步:在spring組態檔中配置事務管理器        <!-- 配置事務管理器 -->        <bean id="transactionManager"                 class="org.springframework.orm.hibernate5.HibernateTransactionManager">            <!-- 注入SessionFactory -->            <property name="sessionFactory" ref="sessionFactory"></property>        </bean>        4.2.1.7第七步:在spring組態檔中開啟spring對注解事務的支持        <!-- 開啟spring對注解事務的支持 -->        <tx:annotation-driven transaction-manager="transactionManager"/>        4.2.1.8第八步:在客戶的業務層實作類上使用@Transactional注解        /**         * 客戶的業務層實作類         */        @Service("customerService")        @Transactional(readOnly=false,propagation=Propagation.REQUIRED)        public class CustomerServiceImpl implements ICustomerService {                        @Autowired            private ICustomerDao customerDao;            @Override            @Transactional(readOnly=true,propagation=Propagation.SUPPORTS)            public List<Customer> findAllCustomer() {                return customerDao.findAllCustomer();            }            @Override            public void saveCustomer(Customer customer) {                customerDao.saveCustomer(customer);            }        }        4.2.2hibernate映射使用注解配置實作        4.2.2.1物體類映射注解配置        /**         * 客戶的物體類         *  JPA規范:java 持久化規范         *  注解全都是JPA規范的,         *  導包都需要匯入javax.persistence包下的         *         */        @Entity        @Table(name="cst_customer")        public class Customer implements Serializable {                        @Id            @GeneratedValue(strategy=GenerationType.IDENTITY)            @Column(name="cust_id")            private Long custId;            @Column(name="cust_name")            private String custName;            @Column(name="cust_source")            private String custSource;            @Column(name="cust_industry")            private String custIndustry;            @Column(name="cust_level")            private String custLevel;            @Column(name="cust_address")            private String custAddress;            @Column(name="cust_phone")            private String custPhone;            public Long getCustId() {                return custId;            }            public void setCustId(Long custId) {                this.custId = custId;            }            public String getCustName() {                return custName;            }            public void setCustName(String custName) {                this.custName = custName;            }            public String getCustSource() {                return custSource;            }            public void setCustSource(String custSource) {                this.custSource = custSource;            }            public String getCustIndustry() {                return custIndustry;            }            public void setCustIndustry(String custIndustry) {                this.custIndustry = custIndustry;            }            public String getCustLevel() {                return custLevel;            }            public void setCustLevel(String custLevel) {                this.custLevel = custLevel;            }            public String getCustAddress() {                return custAddress;            }            public void setCustAddress(String custAddress) {                this.custAddress = custAddress;            }            public String getCustPhone() {                return custPhone;            }            public void setCustPhone(String custPhone) {                this.custPhone = custPhone;            }            @Override            public String toString() {                return "Customer [custId=" + custId + ", custName=" + custName + ", custSource=" + custSource                        + ", custIndustry=" + custIndustry + ", custLevel=" + custLevel + ", custAddress=" + custAddress                        + ", custPhone=" + custPhone + "]";            }            }        4.2.2.2spring中SessionFactory配置修改        <!-- 配置SessionFactory -->        <bean id="sessionFactory"                 class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">            <!-- 1、連接資料庫的 -->            <property name="dataSource" ref="dataSource"></property>            <!-- 2、hibernate基本配置的 -->            <property name="hibernateProperties">                <props>                    <!-- 資料庫的方言-->                    <prop key="hibernate.dialect">                        org.hibernate.dialect.MySQLDialect                    </prop>                    <!-- 是否顯示sql陳述句-->                    <prop key="hibernate.show_sql">true</prop>                    <!-- 是否格式化sql陳述句-->                    <prop key="hibernate.format_sql">false</prop>                    <!-- 采用何種方式生成資料庫表結構 -->                    <prop key="hibernate.hbm2ddl.auto">update</prop>                    <!-- 是spring把sesion系結到當前執行緒上的配置 -->                    <prop key="hibernate.current_session_context_class">                        org.springframework.orm.hibernate5.SpringSessionContext                    </prop>                </props>            </property>            <!-- 3、指定掃描映射注解的包-->            <property name="packagesToScan">                <array>                    <value>com.baidu.domain</value>                </array>            </property>        </bean>        4.2.3struts2配置使用注解實作        4.2.3.1匯入struts2注解的jar包        4.2.3.2使用注解配置Action        /**         * 客戶的動作類         */        @Controller("customerAction")        @Scope("prototype")        //-------以下都是struts2的注解-----------        @ParentPackage("struts-default")//指定當前包的父包        @Namespace("/customer")//指定名稱空間,訪問當前action的所有方法都需要有名稱空間        public class CustomerAction extends ActionSupport implements ModelDriven<Customer> {            private Customer customer = new Customer();                        @Autowired            private ICustomerService customerService;                            @Override            public Customer getModel() {                return customer;            }                        /**             * 查詢所有客戶             * @return             */            private List<Customer> customers;            //用于配置動作名稱            @Action(value="https://www.cnblogs.com/haizai/p/findAllCustomer",results={                    @Result(name="findAllCustomer",                            type="dispatcher",                            location="/jsp/customer/list.jsp")            })            public String findAllCustomer(){                customers = customerService.findAllCustomer();                return "findAllCustomer";            }                        /**             * 獲取添加客戶頁面             * @return             */            @Action(value="addUICustomer",results={                    @Result(name="addUICustomer",                            location="/jsp/customer/add.jsp")            })            public String addUICustomer(){                return "addUICustomer";            }                        /**             * 添加客戶             * @return             */            @Action(value="addCustomer",results={                    @Result(name="addCustomer",                            type="redirect",                            location="/jsp/success.jsp")            })            public String addCustomer(){                customerService.saveCustomer(customer);                return "addCustomer";            }                        public List<Customer> getCustomers() {                return customers;            }            public void setCustomers(List<Customer> customers) {                this.customers = customers;            }Spring整合Struts2的底層實作原理,由Spring來創建action物件 (原理在包struts2-spring-plugin-2.3.24.jar中)        package com.baidu.customer.action;        import com.baidu.customer.domain.Customer;        import com.baidu.customer.service.CustomerService;        import com.opensymphony.xwork2.ActionSupport;        import com.opensymphony.xwork2.ModelDriven;        /**         * 客戶模塊         * @author Administrator         */        public class CustomerAction extends ActionSupport implements ModelDriven<Customer>{                        private Customer customer = new Customer();            public Customer getModel() {                return customer;            }                        /**             * 跳轉到新增頁面             * @return             * @throws Exception             */            public String initSave() throws Exception {                return "initSave";            }            這種方式是ation物件由struts2創建的            // 物件工廠,通過name自動裝配物件  customerService(底層通過jar包用常量覆寫struts2的默認配置,開啟spring的物件工廠,當瀏覽器訪問的時候            ,訪問到action以后再創建CustomerService物件時,用名稱name在SpringIOC容器里面找,找到以后回傳到Action的set方法的CustomerService里面,給CustomerService賦一個實作類物件值)            private CustomerService customerService;            public void setCustomerService(CustomerService customerService) {                this.customerService = customerService;            }            public String save() throws Exception {                System.out.println("WEB層:保存客戶...");                customerService.save(customer);                return NONE;            }        }

 

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/3097.html

標籤:領域驅動設計

上一篇:.NET 開源作業流: Slickflow流程引擎高級開發(六) -- WebTest 引擎介面模擬測驗工具集

下一篇:運用四色建模法進行領域分析

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more