二.配置service层

1.配置spring-service.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: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/context https://www.springframework.org/schema/context/spring-context.xsd">
    <context:component-scan base-package="com.why.service"/>
    <!--BookServiceImpl注入到IOC容器中-->
    <bean class="com.why.service.BookServiceIml" name="serviceIml">
        <property name="bookMapper" ref="bookMapper"/>
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 注入数据库连接池 -->
        <property name="dataSource" ref="dataSource" />
    </bean>

</beans>

2.对应的业务类

package com.why.service;

import com.why.bean.Books;

import java.util.List;

/**
 * @program: SSM
 * @description:
 * @author: @why
 * @create: 2020-09-02 21:27
 **/
public interface Service {
    public List<Books> getBookMsg();
}

 

package com.why.service;

import com.why.bean.Books;
import com.why.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @program: SSM
 * @description:
 * @author: @why
 * @create: 2020-09-02 21:28
 **/
//@org.springframework.stereotype.Service
public class BookServiceIml implements  Service {
//    @Autowired
     private BookMapper bookMapper;
    //
    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }
    @Override
    public List<Books> getBookMsg() {
        return bookMapper.getBookMsg();
    }
}

 

posted @ 2020-09-03 13:48  why666  阅读(227)  评论(0编辑  收藏  举报