update author set username = #{username,jdbcType=VARCHAR}, password = #{password,jdbcType=VARCHAR}, email = #{email,jdbcType=VARCHAR}, address = #{address,jdbcType=VARCHAR}, phOne= #{phone,jdbcType=VARCHAR} where id = #{id,jdbcType=INTEGER}
现将mapper.xml文件直接删除。之后修改AuthoerMapper文件,添加如下注解。
public interface AuthorMapper { @Delete("delete from from author where id = #{id}") int deleteById(Integer id); @Insert("insert into author (id, username, password, email, address, phone)values (#{id}, #{username}, #{password}, #{email}, #{address}, #{phone})") int insert(Author record); @Update("update author set username = #{username},password = #{password},email = #{email},address = #{address},phOne= #{phone} where id = #{id}") int update(Author record);
@Select("select id, username, password, email, address, phone from author where id = #{id}") @Results(id="authorMapper", value={ @Result(column="id", property="id", id=true), @Result(column="username", property="username"), @Result(column="password", property="password"), @Result(column="email", property="email"), @Result(column="address", property="address"), @Result(column="phone", property="phone") }) Author selectByPrimaryKey(Integer id); @Select("select id, username, password, email, address, phone from from author") @ResultMap("authorMapper") List selectAll(); }