码迷,mamicode.com
首页 > 数据库 > 详细

mybatis 代理方式对数据库进行操作

时间:2015-08-04 17:14:59      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

UserMapper.xml文件

<span style="font-family:Courier New;"><?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">
<!-- 这里的namespace命名空间,等于mapper接口的地址 -->
<mapper namespace="cn.itcast.mapper.UserMapper">
	<select id="findById" parameterType="int" resultType="user">
		select * from user where id=#{id}
	</select>
	<select id="findUserByName" parameterType="java.lang.String" resultType="user">
		select * from user where username like "%${value}%"
	</select>
	<update id="updateUser" parameterType="cn.itcast.domain.User">
		update user set username=#{username},birthday=#{birthday},sex=#{sex},address=#{address} where id=#{id}
	</update>
	<delete id="deleteUser" parameterType="int">
		delete from user where id=#{id}
	</delete>
	<insert id="insertUser" parameterType="cn.itcast.domain.User">
		insert into user(username,birthday,sex,address) value(#{username},#{birthday},#{sex},#{address});
	</insert>
</mapper></span>
举例说明:

<mapper namespace="cn.itcast.mapper.UserMapper">
<select id="findById" parameterType="int" resultType="user">
select * from user where id=#{id}
</select>

namespace:就是UserMapper接口的地址即接口UserMapper的全路径名

id:这里的id的值就是UserMapper接口中定义的方法名,要保持一致

parmeterType:这里的值必须和UserMapper接口中方法的参数名的类型保持一致

resultType:这里的值必须和UserMapper接口中方法的返回值的类型保持一致

Usermapper

package cn.itcast.mapper;

import java.util.List;

import cn.itcast.domain.Customer;
import cn.itcast.domain.User;
import cn.itcast.domain.UserQueryVo;

public interface UserMapper {
	public User findById(int id);
	public List<User> findUserByName(String name);
	public void updateUser(User user);
	public void deleteUser(int id);
	public void insertUser(User user);
	public List<Customer> findAllUsersList(UserQueryVo userQueryVo);
	public  User findUserResultType(int id);
	public int findUserCount();
}

技术分享

版权声明:本文为博主原创文章,未经博主允许不得转载。

mybatis 代理方式对数据库进行操作

标签:

原文地址:http://blog.csdn.net/u014010769/article/details/47278573

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!