Java addition, deletion and modification

Additions, deletions and changes generally do not return a value, the query is generally list <User>, according to the id query is to return the User object,

insert into table (field name 1, field name 2 ...) values ​​(value 1, value 2 ...);  

delete from table表 

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

// Paged query
PageInfo <User> findByPage (String companyId, int pageNum, int PageSize);

// Query all departments
List <User> findAll (String companyId);

//保存
void save(User user);

//更新
void update(User user);

// Delete
void delete (String id);

// Query
User findById (String id) by id

 

If you write a SQL statement in 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" property="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>

<!-Query all based on enterprise
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">
delete from pe_user where user_id = #{id}
</delete>

<!--保存-->
<insert id="save">
insert into 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, telephone, degree, remark, order_no)
values (#{id}, #{deptId}, #{email}, #{userName}, #{password}, #{state}, #{companyId},
#{companyName}, #{deptName}, #{managerId}, #{joinDate}, #{salary}, #{birthday},
#{gender}, #{station}, #{telephone}, #{degree}, #{remark}, #{orderNo})
</insert>

<!--更新-->
<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},
birthday = #{birthday},
gender = #{gender},
station = #{station},
telephone = #{telephone},
degree = #{degree},
remark = #{remark},
order_no = #{orderNo}
where user_id = #{id}
</update>
</mapper>

Guess you like

Origin www.cnblogs.com/binbinpeng/p/12714514.html