最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

詳解spring+springmvc+mybatis整合注解

 更新時(shí)間:2017年04月27日 08:19:14   作者:White_Black007  
本篇文章主要介紹了詳解spring+springmvc+mybatis整合注解,詳細(xì)的介紹了ssm框架的使用,具有一定的參考價(jià)值,有興趣的可以了解一下

每天記錄一點(diǎn)點(diǎn),慢慢的成長,今天我們學(xué)習(xí)了ssm,這是我自己總結(jié)的筆記,大神勿噴!謝謝,主要代碼??! !

spring&springmvc&mybatis整合(注解)

1.jar包

2.引入web.xml文件

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <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>
  </servlet>

  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.action</url-pattern>
</servlet-mapping>

3.創(chuàng)建實(shí)體類

4.引入一個(gè)(類名)dao.xml

<update id="update" parameterType="accounting" >
    update accounting set money=#{money} where name=#{name}
  </update>
  <select id="findMoneyByName" parameterType="string" resultType="accounting">
    select * from accounting where name=#{name}
</select>

5.創(chuàng)建一個(gè)(類名)dao

public void update(Accounting a);
public Accounting findMoneyByName(String name);

6.寫service

public void remit(String from,String to,double money);

7.寫serviceimpl

@Service
public class AccountServiceImpl implements AccountService {
  @Autowired
  private AccountDao ad;
  @Override
  public void remit(String from, String to, double money) {
    Accounting fromAccount=ad.findMoneyByName(from);
    fromAccount.setMoney(fromAccount.getMoney()-money);
    ad.update(fromAccount);
    Accounting toAccount=ad.findMoneyByName(to);
    toAccount.setMoney(toAccount.getMoney()+money);
    ad.update(toAccount);
  }

}

8.引入applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:context="http://www.springframework.org/schema/context"
  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-3.2.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

  <!-- 加載db.properties文件中的內(nèi)容,db.properties文件中key命名要有一定的特殊規(guī)則 -->
  <context:property-placeholder location="classpath:db.properties" />
  <!-- 配置數(shù)據(jù)源 ,dbcp -->

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="${jdbc.driver}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="maxActive" value="30" />
    <property name="maxIdle" value="5" />
  </bean>
  <!-- sqlSessionFactory -->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 數(shù)據(jù)庫連接池 -->
    <property name="dataSource" ref="dataSource" />
    <!-- 加載mybatis的全局配置文件 -->
    <property name="configLocation" value="classpath:sqlMapConfig.xml" />
  </bean>


  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
  </bean>
  <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
      <tx:method name="*" propagation="REQUIRED"/>
    </tx:attributes>
  </tx:advice>
  <aop:config>
    <aop:advisor advice-ref="txAdvice" pointcut="execution(* service..*.*(..))"/>
  </aop:config>


  <!-- mapper掃描器 -->
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <!-- 掃描包路徑,如果需要掃描多個(gè)包,中間使用半角逗號(hào)隔開 -->
    <property name="basePackage" value="dao"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  </bean>

</beans>

9.引入db.properties文件和log4j.properties文件

10.引入springmvc.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:context="http://www.springframework.org/schema/context"
  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-3.2.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
  <mvc:annotation-driven></mvc:annotation-driven>
  <context:component-scan base-package="action"></context:component-scan>
  <context:component-scan base-package="service"></context:component-scan>
</beans>

11.jsp頁面編寫

//index.jsp:
 <form action="account_execute.action" method="post">
  匯款人:<input type="text" name="from"/>
  收款人:<input type="text" name="to"/>
  錢數(shù):<input type="text" name="money"/>
  <input type="submit"/>
 </form>
//message.jsp
${message }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • java實(shí)現(xiàn)的冒泡排序算法示例

    java實(shí)現(xiàn)的冒泡排序算法示例

    這篇文章主要介紹了java實(shí)現(xiàn)的冒泡排序算法,結(jié)合實(shí)例形式分析了冒泡排序算法的具體操作步驟與實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2017-01-01
  • idea撤銷git?commit操作詳解

    idea撤銷git?commit操作詳解

    這篇文章主要為大家介紹了idea撤銷git?commit操作詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • 基于Java語言MD5加密Base64轉(zhuǎn)換方法

    基于Java語言MD5加密Base64轉(zhuǎn)換方法

    這篇文章主要為大家詳細(xì)介紹了基于Java語言的MD5加密Base64轉(zhuǎn)換方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • 深入淺出講解Java中的枚舉類

    深入淺出講解Java中的枚舉類

    這篇文章主要介紹了深入淺出講解Java中的枚舉類,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-09-09
  • 詳解Springboot2.3集成Spring security 框架(原生集成)

    詳解Springboot2.3集成Spring security 框架(原生集成)

    這篇文章主要介紹了詳解Springboot2.3集成Spring security 框架(原生集成),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Java代碼實(shí)現(xiàn)酒店管理系統(tǒng)

    Java代碼實(shí)現(xiàn)酒店管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Java代碼實(shí)現(xiàn)酒店管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • java運(yùn)行錯(cuò)誤A JNI error的解決方案

    java運(yùn)行錯(cuò)誤A JNI error的解決方案

    這篇文章主要介紹了java運(yùn)行錯(cuò)誤A JNI error的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • Java 轉(zhuǎn)型(向上或向下轉(zhuǎn)型)詳解及簡(jiǎn)單實(shí)例

    Java 轉(zhuǎn)型(向上或向下轉(zhuǎn)型)詳解及簡(jiǎn)單實(shí)例

    這篇文章主要介紹了Java 轉(zhuǎn)型(向上或向下轉(zhuǎn)型)詳解及簡(jiǎn)單實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • Springboot服務(wù)實(shí)現(xiàn)執(zhí)行SQL腳本文件

    Springboot服務(wù)實(shí)現(xiàn)執(zhí)行SQL腳本文件

    這篇文章主要介紹了Springboot服務(wù)實(shí)現(xiàn)執(zhí)行SQL腳本文件方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • java實(shí)現(xiàn)分布式鎖的常用三種方式

    java實(shí)現(xiàn)分布式鎖的常用三種方式

    本文主要介紹了java實(shí)現(xiàn)分布式鎖,一般有這3種方式,基于數(shù)據(jù)庫實(shí)現(xiàn)的分布式鎖、基于Redis實(shí)現(xiàn)的分布式鎖和基于Zookeeper實(shí)現(xiàn)的分布式鎖,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-08-08

最新評(píng)論

合阳县| 武平县| 汪清县| 比如县| 彰化县| 福鼎市| 太白县| 吉木乃县| 尉氏县| 赫章县| 芒康县| 安丘市| 辉县市| 霍邱县| 修文县| 绥棱县| 保靖县| 耒阳市| 无极县| 日喀则市| 米林县| 神池县| 曲麻莱县| 汶川县| 甘谷县| 富阳市| 南充市| 巍山| 江门市| 新营市| 台安县| 宜丰县| 乐业县| 江油市| 思南县| 黔西县| 鹤山市| 遂昌县| 古丈县| 加查县| 会同县|