-
避免重復(fù)秒殺,(訂單表使用商品ID和用戶手機(jī)號(hào)碼作為聯(lián)合主鍵;插入訂單表數(shù)據(jù)時(shí)使用ignore,在主鍵沖突的時(shí)候,返回0,即不插入數(shù)據(jù)。)
查看全部 -
3.?????? 配置sqlSessionFactory對(duì)象 會(huì)話工廠
<!--3.配置sqlSessionFactory對(duì)象-->
??? <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
?????? ?<!--注入數(shù)據(jù)庫(kù)連接池-->
??????? <property name="dataSource" value="dataSource"/>
??????? <!--配置mybatis全局配置文件:mybatis-config.xml-->
??????? <property name="configLocation" value="classpath:mybatis-config.xml"/>
??????? <!--掃描entity包,使用別名-->
??????? <property name="typeAliasesPackage" value="org.seckill.entity"/>
??????? <!--掃描sql配置文件:mapper需要的xml文件-->
??????? <property name="mapperLocations" value="classpath:mapper/*.xml"/>
??? </bean>
查看全部 -
2. ?配置數(shù)據(jù)庫(kù)連接池
<!--2.數(shù)據(jù)庫(kù)連接池-->
??? <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
??????? <!--配置連接池基本屬性-->
??????? <property name="driverClass" value="${driver}"/>
??????? <property name="jdbcUrl" value="${url}"/>
??????? <property name="user" value="${username}"/>
??????? <property name="password" value="${password}"/>
??????? <!--c3p0連接池的私有屬性-->
??????? <property name="maxPoolSize" value="30"/>
??????? <property name="minPoolSize" value="10"/>
??????? <!--關(guān)閉鏈接后不自動(dòng)commit-->
??????? <property name="autoCommitOnClose"value="false"/>
??????? <!--獲取鏈接超時(shí)時(shí)間-->
??????? <property name="checkoutTimeout" value="1000"/>
??????? <!--當(dāng)獲取連接失敗時(shí)重試次數(shù)-->
??????? <property name="acquireRetryAttempts" value="2"/>
??? </bean>
查看全部 -
1. ?配置數(shù)據(jù)庫(kù)相關(guān)參數(shù)
查看全部 -
1)? 更少的編碼:只寫接口,不寫實(shí)現(xiàn)。接口能說明參數(shù),行為,結(jié)果集。
2)? 更少的配置:
別名(原來是包名+類名 ?mybatis只需要寫原生的類名)
自動(dòng)掃描配置文件:XML文件
Mapper自動(dòng)實(shí)現(xiàn)DAO接口,并自動(dòng)注入spring容器
3)? 足夠的靈活性:自己定制SQL,自由傳參,結(jié)果集自動(dòng)賦值
XML提供SQL?? + ??DAO接口提供Mapper
查看全部 -
通過MyBatis實(shí)現(xiàn)實(shí)現(xiàn)SuccessKilledDao接口
MyBatis核心的點(diǎn)在于可以自由控制SQL
?
后續(xù)MyBatis如何整合SPRING以及如何編寫單元測(cè)試
查看全部 -
【mapper-SeckillDao.xml】
Resource –> new -> directory創(chuàng)建一個(gè)目錄放置mybatis的sql的映射”mapper”
在mapper下創(chuàng)建映射關(guān)系。Mapper->new->file創(chuàng)建SeckillDao.xml(命名規(guī)范:DAO的名字.xml).? 為DAO方法的接口提供sql語(yǔ)句
實(shí)現(xiàn)SeckillDao.xml
reduceNumber減庫(kù)存
queryById根據(jù)id查詢秒殺對(duì)象
queryALL根據(jù)偏移量查詢秒殺商品列表
查看全部 -
【mybatis-config.xml】
Resource –> new -> file 創(chuàng)建一個(gè)mybatis全局的配置文件”mybatis-config.xml”
從官方文檔找到mybatis的全局配置 XML的一個(gè)標(biāo)簽約束
<configuration>?
<settings>
查看全部 -
[SuccessKilledDao]
InsertSuccssKilled 插入購(gòu)買明細(xì),可過濾重復(fù)
queryByIdWithSeckill根據(jù)id查詢SuccessKilled并攜帶秒殺產(chǎn)品對(duì)象實(shí)體
查看全部 -
實(shí)現(xiàn)DAO的接口
[SeckillDao]
reduceNumber減庫(kù)存
queryById根據(jù)id查詢秒殺對(duì)象
queryALL根據(jù)偏移量查詢秒殺商品列表
查看全部 -
mvn archetype:create -DgroupId=org.seckill -DartifactId=seckill -DarchetypeArtifactId=maven-archetype-webapp
-DgroupId=org.seckill -DartifactId=seckill:標(biāo)注項(xiàng)目的坐標(biāo)
org.seckill:項(xiàng)目名
-DarchetypeArtifactId=maven-archetype-webapp:使用webapp原型去創(chuàng)建項(xiàng)目
使用以上命令項(xiàng)目創(chuàng)建失敗
mvn archetype:generate -DarchetypeCatalog=internal -DgroupId=com.seckill -DartifactId=seckill -DarchetypeArtifactId=maven-archetype-webapp
使用以上命令項(xiàng)目創(chuàng)建成功
查看全部 -
mvn archetype:generate -DgroupId=org.seckill -DartifactId=seckill -DarchetypeArtifactId=maven-archetype-webapp
創(chuàng)建成功
查看全部 -
myBatis整合Spring目標(biāo)
查看全部 -
初始的自增id設(shè)為1000
AUTO_INCREMENT=1000
查看全部 -
MySql有多重存儲(chǔ)引擎供我們使用,但是可以支持事務(wù)的存儲(chǔ)引擎只有InnoDB
查看全部
舉報(bào)