<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations"
value="classpath:com/tiantian/ckeditor/mybatis/mappers/*Mapper.xml" />
<property name="typeAliasesPackage" value="com.tiantian.ckeditor.model" />
</bean>
<property name="typeAliases"> <array> <value>com.tiantian.mybatis.model.Blog</value> <value>com.tiantian.mybatis.model.Comment</value> </array> </property>
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.tiantian.mybatis"/>
<context:property-placeholder location="classpath:config/jdbc.properties"/>
<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}" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:com/tiantian/mybatis/mapper/*.xml"/>
<property name="typeAliasesPackage" value="com.tiantian.mybatis.model" />
</bean>
<bean id="blogMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface"
value="com.tiantian.mybatis.mapper.BlogMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tiantian.mybatis.mapper.BlogMapper">
<!-- 新增记录 -->
<insert id="insertBlog" parameterType="Blog" useGeneratedKeys="true" keyProperty="id">
insert into t_blog(title,content,owner) values(#{title},#{content},#{owner})
</insert>
<!-- 查询单条记录 -->
<select id="selectBlog" parameterType="int" resultMap="BlogResult">
select * from t_blog where id = #{id}
</select>
<!-- 修改记录 -->
<update id="updateBlog" parameterType="Blog">
update t_blog set title = #{title},content = #{content},owner = #{owner} where id = #{id}
</update>
<!-- 查询所有记录 -->
<select id="selectAll" resultType="Blog">
select * from t_blog
</select>
<!-- 删除记录 -->
<delete id="deleteBlog" parameterType="int">
delete from t_blog where id = #{id}
</delete>
</mapper>
package com.tiantian.mybatis.mapper;
import java.util.List;
import com.tiantian.mybatis.model.Blog;
publicinterface BlogMapper {
public Blog selectBlog(int id);
publicvoid insertBlog(Blog blog);
publicvoid updateBlog(Blog blog);
publicvoid deleteBlog(int id);
public List<Blog> selectAll();
}
package com.tiantian.mybatis.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.tiantian.mybatis.mapper.BlogMapper;
import com.tiantian.mybatis.model.Blog;
import com.tiantian.mybatis.service.BlogService;
@Service
publicclass BlogServiceImpl implements BlogService {
private BlogMapper blogMapper;
publicvoid deleteBlog(int id) {
blogMapper.deleteBlog(id);
}
public Blog find(int id) {
returnblogMapper.selectBlog(id);
}
public List<Blog> find() {
returnblogMapper.selectAll();
}
publicvoid insertBlog(Blog blog) {
blogMapper.insertBlog(blog);
}
publicvoid updateBlog(Blog blog) {
blogMapper.updateBlog(blog);
}
public BlogMapper getBlogMapper() {
returnblogMapper;
}
@Resource
publicvoid setBlogMapper(BlogMapper blogMapper) {
this.blogMapper = blogMapper;
}
}
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.tiantian.mybatis.mapper" /> </bean>
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.tiantian.mybatis" />
<context:property-placeholder location="classpath:config/jdbc.properties" />
<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}" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:com/tiantian/mybatis/mapper/*.xml" />
<property name="typeAliasesPackage" value="com.tiantian.mybatis.model" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.tiantian.mybatis.mapper" />
</bean>
</beans>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.tiantian.mybatis.mapper" /> <property name="markerInterface" value="com.tiantian.mybatis.mapper.SuperMapper"/> </bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.tiantian.mybatis.mapper" /> <property name="annotationClass" value="com.tiantian.mybatis.annotation.MybatisMapper"/> </bean>
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:mybatis="http://www.mybatis.org/schema/mybatis"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.mybatis.org/schema/mybatis
http://www.mybatis.org/schema/mybatis/mybatis-spring.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.tiantian.mybatis" />
<context:property-placeholder location="classpath:config/jdbc.properties" />
<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}" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:com/tiantian/mybatis/mapper/*.xml" />
<property name="typeAliasesPackage" value="com.tiantian.mybatis.model" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.tiantian.mybatis.mapper" />
<property name="markerInterface" value="com.tiantian.mybatis.mapper.SuperMapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</beans>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean>
package com.tiantian.mybatis.dao;
import java.util.List;
import javax.annotation.Resource;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;
import com.tiantian.mybatis.model.Blog;
@Repository
publicclass BlogDaoImpl implements BlogDao {
private SqlSessionTemplate sqlSessionTemplate;
publicvoid deleteBlog(int id) {
sqlSessionTemplate.delete("com.tiantian.mybatis.mapper.BlogMapper.deleteBlog", id);
}
public Blog find(int id) {
returnsqlSessionTemplate.selectOne("com.tiantian.mybatis.mapper.BlogMapper.selectBlog", id);
}
public List<Blog> find() {
returnthis.sqlSessionTemplate.selectList("com.tiantian.mybatis.mapper.BlogMapper.selectAll");
}
publicvoid insertBlog(Blog blog) {
this.sqlSessionTemplate.insert("com.tiantian.mybatis.mapper.BlogMapper.insertBlog", blog);
}
publicvoid updateBlog(Blog blog) {
this.sqlSessionTemplate.update("com.tiantian.mybatis.mapper.BlogMapper.updateBlog", blog);
}
public SqlSessionTemplate getSqlSessionTemplate() {
returnsqlSessionTemplate;
}
@Resource
publicvoid setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
this.sqlSessionTemplate = sqlSessionTemplate;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有