亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

詳解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.引入一個(類名)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)建一個(類名)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">
    <!-- 掃描包路徑,如果需要掃描多個包,中間使用半角逗號隔開 -->
    <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 }

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

相關(guān)文章

  • SpringBoot整合Mysql和Redis的詳細(xì)過程

    SpringBoot整合Mysql和Redis的詳細(xì)過程

    這篇文章主要介紹了SpringBoot整合Mysql和Redis的示例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • 從內(nèi)存方面解釋Java中String與StringBuilder的性能差異

    從內(nèi)存方面解釋Java中String與StringBuilder的性能差異

    我們通常會發(fā)現(xiàn)使用StringBuffer或StringBuilder創(chuàng)建出來的字符串在拼接時(shí)回避String要來得快,尤其是StringBuilder,本文就從內(nèi)存方面解釋Java中String與StringBuilder的性能差異,需要的朋友可以參考下
    2016-05-05
  • SpringMVC框架的介紹與使用詳解

    SpringMVC框架的介紹與使用詳解

    SpringMVC?是一種基于?Java?的實(shí)現(xiàn)?MVC?設(shè)計(jì)模型的請求驅(qū)動類型的輕量級?Web?框架,跟Spring,Mybatis框架并稱為ssm,這篇文章主要介紹了SpringMVC框架的介紹與使用,需要的朋友可以參考下
    2022-08-08
  • java IO 文件操作方法總結(jié)

    java IO 文件操作方法總結(jié)

    這篇文章主要介紹了java IO 文件操作方法總結(jié)的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • springboot使用TaskScheduler實(shí)現(xiàn)動態(tài)增刪啟停定時(shí)任務(wù)方式

    springboot使用TaskScheduler實(shí)現(xiàn)動態(tài)增刪啟停定時(shí)任務(wù)方式

    這篇文章主要介紹了springboot使用TaskScheduler實(shí)現(xiàn)動態(tài)增刪啟停定時(shí)任務(wù)方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Java中SimpleDateFormat用法詳解

    Java中SimpleDateFormat用法詳解

    SimpleDateFormat 是一個以國別敏感的方式格式化和分析數(shù)據(jù)的具體類。 它允許格式化 (date -> text)、語法分析 (text -> date)和標(biāo)準(zhǔn)化.這篇文章主要介紹了Java中SimpleDateFormat用法詳解,需要的朋友可以參考下
    2017-03-03
  • 解讀@RequestBody與post請求的關(guān)系

    解讀@RequestBody與post請求的關(guān)系

    這篇文章主要介紹了解讀@RequestBody與post請求的關(guān)系,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 淺析Spring中的循環(huán)依賴問題

    淺析Spring中的循環(huán)依賴問題

    這篇文章主要介紹了淺析Spring中的循環(huán)依賴問題,Spring 是利用了 三級緩存 來解決循環(huán)依賴的,其實(shí)現(xiàn)本質(zhì)是通過提前暴露已經(jīng)實(shí)例化但尚未初始化的 bean 來完成的,需要的朋友可以參考下
    2023-11-11
  • Spring中基于xml的AOP實(shí)現(xiàn)詳解

    Spring中基于xml的AOP實(shí)現(xiàn)詳解

    這篇文章主要介紹了Spring中基于xml的AOP實(shí)現(xiàn)詳解,基于xml與基于注解的AOP本質(zhì)上是非常相似的,都是需要封裝橫切關(guān)注點(diǎn),封裝到切面中,然后把橫切關(guān)注點(diǎn)封裝為一個方法,再把該方法設(shè)置為當(dāng)前的一個通知,再通過切入點(diǎn)表達(dá)式定位到橫切點(diǎn)就可以了,需要的朋友可以參考下
    2023-09-09
  • Java 八道經(jīng)典面試題之鏈表題

    Java 八道經(jīng)典面試題之鏈表題

    本位主要介紹了Java面試中常常遇到的八道經(jīng)典鏈表問題,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的小伙伴們可以學(xué)習(xí)一下
    2021-11-11

最新評論