Usermapper.xml file
<span style= "Font-family:courier New;" ><?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE mapperpublic "-//mybatis.org//dtd Mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" ><!-- Here the namespace namespace equals the address of the Mapper interface--><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>
To illustrate:
<mapper namespace= "Cn.itcast.mapper.UserMapper" >
<select id= "FindByID" parametertype= "int" resulttype= "user" >
SELECT * from user where Id=#{id}
</select>
Namespace: The full path name of the Usermapper interface, which is the address of the interface Usermapper
ID: The value of the ID here is the method name defined in the Usermapper interface, to be consistent
Parmetertype: The value here must be consistent with the type of the parameter name of the method in the Usermapper interface
Resulttype: The value here must be consistent with the type of the return value of the method in the Usermapper interface
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);p ublic list<user> Finduserbyname (String name);p ublic void updateUser (user user);p ublic void deleteuser (int id);p ublic void Insertuser ( User user);p ublic list<customer> findalluserslist (userqueryvo userqueryvo);p ublic user Finduserresulttype (int id);p ublic int findusercount ();}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MyBatis Proxy mode to operate the database