dw做网站小技巧软文案例500字
最近终于有时间写点代码相关的文章了,工作真的太忙了,果然又要测试又要开发的人最🐂🐴。
1.查询数据库有数据,但是代码中写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);