1. 程式人生 > 程式設計 >C語言 實現輸入任意多個整數

C語言 實現輸入任意多個整數

技術標籤:筆記springmybatis

整合步驟:
核心內容:
讓spring產生dao介面的代理實現類,並交由sping容器管理
1.在spring的配置檔案中配置mybatis 的資訊,產生SqlSession物件
2.配置mapper層介面包
3.配置自動掃描mapper包以及其子包
4.通過spring的依賴注入將mapper介面注入到service層中

<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.1.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.1.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.9</version>
        </dependency>
    </dependencies>

2.配置spring的xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context.xsd
">
    
    <context:property-placeholder location="classpath:jdbc.properties"/>

    
    
    <bean id="druidDataSource"  class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.url}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="druidDataSource"/>
        <property name="typeAliasesPackage" value="com.itheima.domain"/>
    </bean>
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.itheima.dao"/>
        
    </bean>

    <bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl">
        <property name="accountDao" ref="accountDao"/>
    </bean>

</beans>

/**
 * 儲存訂單
 * @param account 訂單實體類
 */
void save(Account account);

/**
 * 刪除訂單
 * @param id 訂單id
 */
void delete(Integer id);

/**
 * 修改訂單
 * @param account 訂單實體類
 */
void update(Account account);

/**
 * 查詢所有訂單
 * @return list集合
 */
List<Account> findAll();

/**
 * 根據id查詢訂單
 * @param id 訂單的id
 * @return 訂單
 */
Account findById(Integer id);

   ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
    AccountService accountService = applicationContext.getBean("accountService", AccountService.class);
    List<Account> accounts = accountService.findAll();
    for (Account account : accounts) {
        System.out.println(account);
    }