Spring_day02_5(Spring 使用半注解半XML形式改写Mybatis项目)

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;
	}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值