applicationContext.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
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 开启peoperties配置文件的读取 -->
<context:property-placeholder location="classpath:db.properties"/>
<!--开启注释的识别,非常的重要--!>
<context:component-scan base-package="com.ai.service.impl"></context:component-scan>
<!-- 配置dataSource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 配置SqlSessionFactory -->
<bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="typeAliasesPackage" value="com.ai.domain"></property>
</bean>
<!-- 配置Mapper映射 (重点)-->
<bean id="mapper" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ai.mapper"></property>
<property name="SqlSessionFactoryBeanName" value="factory"></property>
</bean>
<!--删除了ServiceImpl的配置 -->
<!-- 额外配置(自增 页面信息类) -->
<bean id="pageInfo_Article" class="com.ai.domain.PageInfo_Article">
</bean>
</beans>
CommentServiceImpl:
package com.ai.service.impl;
import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.ai.domain.Comment_1;
import com.ai.mapper.Comment_1Mapper;
import com.ai.service.CommentService;
@Service("commentServiceImpl")
public class CommentServiceImpl implements CommentService {
@Resource(name="comment_1Mapper")
private Comment_1Mapper c_1m;
@Override
public List<Comment_1> getComment_1ByArticle_id(int article_id,int page_num,int size) throws IOException {
int beginRecord = (page_num-1)*size;
List<Comment_1> list_comment_1 = c_1m.selComment_1ByArticle_id(article_id,beginRecord,size);
return list_comment_1;
}
@Override
public List<Comment_1> getAllRecords(int article_id) {
List<Comment_1> list_comment_1 = c_1m.selAllComment_1ByArticle_id(article_id);
return list_comment_1;
}
}