当前位置: 首页 > news >正文

网站方案制作的培训百度seo排名如何提升

网站方案制作的培训,百度seo排名如何提升,铁岭做网站哪家好,巫山网站制作目录 一,查询 - select 1.1 全列查询 1.2 指定列查询 1.3 赋值问题 方法一:起别名 方法二:结果映射 方法三:添加配置 二,新增 - Insert 2.1 使用对象插入 2.2 获取主键 三,删除 - Delete 四&am…

目录

一,查询 - @select

1.1 全列查询

1.2 指定列查询

1.3 赋值问题

方法一:起别名

方法二:结果映射

方法三:添加配置

二,新增 - @Insert

2.1 使用对象插入

2.2 获取主键

三,删除 - @Delete

四,修改 - @Update 

补:MyBatis 的配置


一,查询 - @select

1.1 全列查询

@Mapper
public interface UserInfoMapper {@Select("select * from userInfo")public UserInfo queryAll();
}

1.2 指定列查询

@Mapper
public interface UserInfoMapper {//注意:MyBatis中方法名不允许重复!!!!//当只有一个参数时,sql参数与方法参数可以不同@Select("select * from userInfo where id = #{id}")public UserInfo queryUserInfoById(Integer id);//当需要对参数进行重命名时需要使用@Param注释//如果不使用@Param,那么sql参数与方法参数必须相同//注:如果使用阿里云创建的springboot项目,必须使用@Param注解@Select("select * from userInfo where id = #{id} and username = #{username}")public UserInfo queryUserInfo(@Param("id") Integer i, @Param("username") String name);
}

 注:加了@Param注解后,sql语句中的参数名只能与@Param()的参数名匹配!!!

1.3 赋值问题

可以发现,在赋值时,deleteFlag,createTime,updateTime 并没有被赋值,这是为什么?原因分析:

  • 当⾃动映射查询结果时,MyBatis 会获取结果中返回的列名并在 Java 类中查找相同名字的属性(忽略⼤⼩写)。 这意味着如果发现了 ID 列和 id 属性,MyBatis 会将列 ID 的值赋给 id 属性
  • 所以没有赋值的原因就是MySQL中的字段名与Java对象中的属性名不相同

 

方法一:起别名

    @Select("select id, username, password, age, gender, phone," +"delete_flag as deleteFlag, create_time as createTime, update_time as updateTime from userInfo " +"where id = #{id} and username = #{username}")public UserInfo queryUserInfo(@Param("id") Integer i, @Param("username") String name);

方法二:结果映射

    @Select("select * from userInfo where id = #{id}")@Results(id = "resultMap",value = {@Result(column = "delete_flag", property = "deleteFlag"),@Result(column = "create_time", property = "createTime"),@Result(column = "update_time", property = "updateTime")})public UserInfo queryUserInfo(@Param("id") Integer i, @Param("username") String name);@Select("select * from userInfo where id = #{id}")@ResultMap(value = "resultMap")//使用过@Results注解后,其他方法可以直接使用@ResultMap注解获得相同效果public UserInfo queryUserInfoById(Integer id);

方法三:添加配置

mybatis:configuration:map-underscore-to-camel-case: true #驼峰自动转换

二,新增 - @Insert

2.1 使用对象插入

使用多个参数插入数据与上述查询的使用方法一样,这里不过多赘述,这里讲一下如何使用对象插入数据:

@Mapper
public interface UserInfoMapper {//这里演示一下使用对象插入@Insert("insert into userInfo (username, password, age, gender, phone) " +"values (#{username}, #{password}, #{age}, #{gender}, #{phone})")public Integer insert(UserInfo userInfo);//使用@Param注解@Insert("insert into userInfo (username, password, age, gender, phone) " +"values (#{userInfo.username}, #{userInfo.password}, #{userInfo.age}, #{userInfo.gender}, #{userInfo.phone})")public Integer insertByParam(@Param("userInfo") UserInfo userInfo);//这里的返回值是成功修改了几行数据,也可以返回void
}

2.2 获取主键

在有些情景中,我们需要获取到新插入数据的 id,如果想要拿到自增 id,需要在Mapper接口方法上添加一个@Option注解:

    @Options(useGeneratedKeys = true, keyProperty = "id")@Insert("insert into userInfo (username, password, age, gender, phone) " +"values (#{username}, #{password}, #{age}, #{gender}, #{phone})")public Integer insert(UserInfo userInfo);
  • useGeneratedKeys = true:表示告诉MyBatis使用JDBC的getGeneratedKeys方法来检索数据库内部生成的主键(如果数据库支持的话)
  • keyProperty = ''id'':这个属性指定了userInfo对象中的 id 属性接收数据库生成的主键

三,删除 - @Delete

    @Delete("delete from userInfo where id = #{id}")public Integer deleteById(Integer id);

四,修改 - @Update 

    @Update("update userInfo set username = #{username} where id = #{id}")public Integer updateById(@Param("username") String username, @Param("id") Integer id);

补:MyBatis 的配置

mybatis:configuration: # 配置打印 MyBatis⽇志map-underscore-to-camel-case: true #驼峰自动转换log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句mapper-locations: classpath:mapper/**Mapper.xml #使用xml操作数据库时会用到

http://www.hkea.cn/news/980039/

相关文章:

  • 中企高呈建设网站在百度怎么创建自己的网站
  • 女的和女的做那个视频网站怎么在网上做网络营销
  • 网站开发需要什么软件百度怎样发布作品
  • 专门做宠物食品的网站市场调研怎么做
  • 兰州网站建设q.479185700棒成年s8视频加密线路
  • 付费网站推广seo关键词排名优化怎么收费
  • 网站由那些组成google网页搜索
  • 对一个网站做性能测试谷歌paypal官网入口
  • 北京住房投资建设中心网站首页快速排名怎么做
  • 中国网站制作 第一个佛山网站优化
  • thinkphp做的教育网站微商引流推广
  • 做特卖网站手机版电商最好卖的十大产品
  • 怎样做网站平叿trinseo公司
  • 北京大兴最专业的网站建设公司如何推广一个项目
  • 网页设计最牛的网站建设宁波网站优化公司哪家好
  • 建设通查询如何做网站推广及优化
  • 城乡建设网站首页百度seo收录软件
  • 永久免费建个人网站培训网站建设
  • 如何使用jq做弹幕网站好用的磁力搜索引擎
  • 南充营销型网站建设高端品牌网站建设
  • 制作小程序和网站的公司搜狗收录提交入口网址
  • 手机站电影基础建站如何提升和优化
  • 江苏 网站备案百度贴吧官网app下载
  • 网站制作三站湖南网站seo公司
  • 简单做任务赚钱网站企业管理培训课程报名
  • 零点研究咨询集团官方网站建设相似图片在线查找
  • 网站开发需要什么软件关键词app
  • 360全景网站建设做了5天游戏推广被抓了
  • 政府网站建设经验典型材料河源今日头条新闻最新
  • 为什么要进行网站备案佛山市人民政府门户网站