兩個wordpress公用用戶東莞做網(wǎng)站seo
最近終于有時間寫點代碼相關(guān)的文章了,工作真的太忙了,果然又要測試又要開發(fā)的人最🐂🐴。
1.查詢數(shù)據(jù)庫有數(shù)據(jù),但是代碼中寫select語句的時候查出為null
@Select("SELECT * FROM xx_manager order by id limit 1")@Results({@Result(property = "id", column = "id"),@Result(property = "versionName", column = "version_name"),@Result(property = "os", column = "os"),@Result(property = "versionId", column = "version_id"),@Result(property = "releaseBuild", column = "release_build")})public xxDO selectLatest();
改動點:需要加result映射字段
2.在set多個字段的時候,使用AND不生效
@Update("UPDATE `xx_manager` SET time=#{time} ,release_build=#{releaseBuild} WHERE version_id=#{versionId}")public int update(@Param("versionId") Long versionId, @Param("time") String time,@Param("releaseBuild") Long releaseBuild);
改動點:需要把AND改成 ,
3.模糊查詢
@Select("SELECT * FROM xx_manager where version_name like concat('%',#{versionName},'%') order by release_build desc")@Results({@Result(property = "id", column = "id"),@Result(property = "versionName", column = "version_name"),@Result(property = "os", column = "os"),@Result(property = "versionId", column = "version_id"),@Result(property = "releaseBuild", column = "release_build")})public List<xxDO> queryVersionByName(String versionName);
4.@Mapper常用的用法
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;import com.xwj.entity.UserEntity;public interface UserMapper {/*** 查詢*/@Select("SELECT id, last_name lastName, email, age FROM xwj_user WHERE id = #{id} and last_name like '%${lastName}%' ")UserEntity findById(@Param("id") String id, @Param("lastName") String name);/*** 新增*/@Insert("INSERT INTO user(id, last_name, age) VALUES(#{id}, #{lastName}, #{age})")int addUser(@Param("id") String id, @Param("lastName") String name, @Param("age") Integer age);/*** 更新*/@Update("UPDATE user SET last_name = #{lastName} WHERE id = ${id}")int updateUser(@Param("id") String id, @Param("lastName") String name);/*** 刪除*/@Delete("DELETE FROM user WHERE id = ${id}")int deleteUser(@Param("id") String id);