Javaの追加、削除、変更

追加、削除、変更は通常値を返しません。クエリは通常リスト<User>です。idクエリによると、Userオブジェクトを返します。

テーブルに挿入(フィールド名1、フィールド名2 ...)値(値1、値2 ...);  

テーブルから削除 

update table table set field name = 'value to be changed' where where ...

//
ページングクエリPageInfo <User> findByPage(String companyId、int pageNum、int PageSize);

//すべての部門を照会します
List <User> findAll(String companyId);

//保存
void save(User user);

//更新
void update(User user);

//
void delete(String id);を削除します

//
ユーザーのfindById(String id)をIDでクエリします

 

SQLステートメントをXMLで記述する場合:

<?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 =" cn.itcast.dao.system.UserDao ">
<resultMap id =" BaseResultMap "type =" cn.itcast.domain.system.User ">
<id column =" user_id "property =" id "/>
<result column =" dept_id "property =" deptId "/>
<result column =" email "property =" email "/>
<result column =" user_name "property =" userName "/ >
<result column = "password" property = "password" />
<result column = "state"property = "state" />
<result column = "company_id" property = "companyId" />
<result column = "company_name" property = "companyName" />
<result column = "dept_name" property = "deptName" />
<result column = "manager_id" property = "managerId" />
<result column = "join_date" property = "joinDate" />
<result column = "salary" property = "salary" />
<result column = "birthday"プロパティ= "birthday" />
<result column = "gender" property = "gender" />
<result column = "station" property = "station" />
<result column = "telephone" property = "telephone" />
<result column = "degree" property = "degree"
/>
<result column = "remark" property = "remark" />
< result column = "order_no" property = "orderNo" /> </ resultMap>

<!-企業
IDごとにすべてを照会-> <select id = "findAll" resultMap = "BaseResultMap">
select * from pe_user where company_id =#{companyId}
</ select>

<!-根拠id查询->
<select id = "findById" resultMap = "BaseResultMap">
select * from pe_user where user_id =#{id}
</ select>

<!-根拠id删除->
<delete id = "delete">
pe_userから削除しますuser_id =#{id}
</ delete>

<!-保存->
<insert id = "save">
pe_userに挿入(user_id、dept_id、email、user_name、password、state、company_id、
company_name、dept_name、manager_id、join_date、salary、birthday、
gender、station、電話、学位、備考、order_no)の
値(#{id}、#{deptId}、#{email}、#{userName}、#{password}、#{state}、#{companyId}、
#{companyName}、 #{deptName}、#{managerId}、#{joinDate}、#{salary}、#{birthday}、
#{gender}、#{station}、#{telephone}、#{degree}、#{remark}、 #{orderNo})
</挿入>

<!-更新->
<update id = "update">
update pe_user
set dept_id =#{deptId}、
email =#{email}、
user_name =#{userName}、
password =#{password}、
state =# {state}、
company_id =#{companyId}、
company_name =#{companyName}、
dept_name =#{deptName}、
manager_id =#{managerId}、
join_date =#{joinDate}、
salary =#{salary}、
誕生日=#{誕生日}、
性別=#{gender}、
駅=#{station}、
電話=#{telephone}、
程度=#{degree
}、
remark =#{remark} order_no =#{orderNo}
where user_id =#{id }
</ update>
</ mapper>

おすすめ

転載: www.cnblogs.com/binbinpeng/p/12714514.html