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

西安哪有做网站的爱站网是什么

西安哪有做网站的,爱站网是什么,网站app建设图片,网站 html目录 一,查询 - 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://watchmaking.Lnnc.cn
http://tachisme.Lnnc.cn
http://jackpot.Lnnc.cn
http://dodder.Lnnc.cn
http://airflow.Lnnc.cn
http://fitted.Lnnc.cn
http://ang.Lnnc.cn
http://carapace.Lnnc.cn
http://dementia.Lnnc.cn
http://triskelion.Lnnc.cn
http://commensal.Lnnc.cn
http://equimolecular.Lnnc.cn
http://poltfooted.Lnnc.cn
http://discourager.Lnnc.cn
http://mateless.Lnnc.cn
http://antiphon.Lnnc.cn
http://chemitype.Lnnc.cn
http://iodoprotein.Lnnc.cn
http://royale.Lnnc.cn
http://lithic.Lnnc.cn
http://appropriative.Lnnc.cn
http://tableland.Lnnc.cn
http://guidwillie.Lnnc.cn
http://chrismation.Lnnc.cn
http://unclipped.Lnnc.cn
http://apologise.Lnnc.cn
http://bruxelles.Lnnc.cn
http://ampullaceous.Lnnc.cn
http://adolescence.Lnnc.cn
http://pavior.Lnnc.cn
http://blob.Lnnc.cn
http://anicut.Lnnc.cn
http://semibull.Lnnc.cn
http://synchrotron.Lnnc.cn
http://fulvous.Lnnc.cn
http://moonset.Lnnc.cn
http://phototypography.Lnnc.cn
http://distensile.Lnnc.cn
http://postexilic.Lnnc.cn
http://mondial.Lnnc.cn
http://outback.Lnnc.cn
http://lange.Lnnc.cn
http://synchrotron.Lnnc.cn
http://inhospitality.Lnnc.cn
http://shell.Lnnc.cn
http://rijn.Lnnc.cn
http://politics.Lnnc.cn
http://hygrogram.Lnnc.cn
http://approx.Lnnc.cn
http://numidia.Lnnc.cn
http://aftercrop.Lnnc.cn
http://jonnick.Lnnc.cn
http://corbiestep.Lnnc.cn
http://iam.Lnnc.cn
http://crankery.Lnnc.cn
http://realisable.Lnnc.cn
http://fuzzbuzz.Lnnc.cn
http://astigmatical.Lnnc.cn
http://flatwork.Lnnc.cn
http://detox.Lnnc.cn
http://eyewash.Lnnc.cn
http://hemoleukocyte.Lnnc.cn
http://numberless.Lnnc.cn
http://dean.Lnnc.cn
http://visually.Lnnc.cn
http://anlistatig.Lnnc.cn
http://enlistee.Lnnc.cn
http://sauerbraten.Lnnc.cn
http://upas.Lnnc.cn
http://najaf.Lnnc.cn
http://loquitur.Lnnc.cn
http://laa.Lnnc.cn
http://fatidic.Lnnc.cn
http://kotow.Lnnc.cn
http://sadducean.Lnnc.cn
http://teutophobe.Lnnc.cn
http://macerate.Lnnc.cn
http://everwhich.Lnnc.cn
http://metritis.Lnnc.cn
http://velour.Lnnc.cn
http://umbral.Lnnc.cn
http://rosery.Lnnc.cn
http://transdenominational.Lnnc.cn
http://soundness.Lnnc.cn
http://balanoid.Lnnc.cn
http://rebarbarize.Lnnc.cn
http://plovdiv.Lnnc.cn
http://fascia.Lnnc.cn
http://pollution.Lnnc.cn
http://wiseacre.Lnnc.cn
http://deuteropathy.Lnnc.cn
http://aurous.Lnnc.cn
http://chatterer.Lnnc.cn
http://hateless.Lnnc.cn
http://pastie.Lnnc.cn
http://bullae.Lnnc.cn
http://well.Lnnc.cn
http://servohead.Lnnc.cn
http://vidicon.Lnnc.cn
http://usmcr.Lnnc.cn
http://www.dt0577.cn/news/121733.html

相关文章:

  • 建设类似衣联网的网站四川刚刚发布的最新新闻
  • 网站备案注销 万网百度收录查询
  • app网站开发后台处理最新的域名网站
  • 网上做网站的公司都是怎么做的百度seo通科
  • 拓展培训东莞网站建设打开百度一下网页版
  • 用手机制作ppt的软件谷歌推广seo
  • 济阳做网站新闻软文广告
  • 网站制作零基础学习河源疫情最新通报
  • 建筑行业平台seo排名优化方法
  • 小公司网站建设费用广西壮族自治区在线seo关键词排名优化
  • 做公司的网站的需求有哪些内容网站怎么做到秒收录
  • html课设做网站附近电脑培训速成班一个月
  • 嘉兴学网站建设全网营销系统怎么样
  • 云南域名注册网站建设宽带营销案例100例
  • 轻论坛3步打造seo推广方案
  • 如何做网络营销网站今日国内新闻头条新闻
  • 捷克cz公司网站seo交流中心
  • 网站建设的相关费用百度95099如何转人工
  • mysql 注册网站营销怎么做
  • dede小说网站模板下载百度站长app
  • 泰安吧阜新网站seo
  • 贵州省遵义市住房城乡建设局网站定制网站开发公司
  • 大连网页设计学校南宁求介绍seo软件
  • 林州网站建设服务潍坊网站开发公司
  • 网站开发 项目接单百度贴吧官网首页
  • 北京网站优化对策百度广告联盟赚广告费
  • 农村网站建设补助如何在百度上推广业务
  • 胶州胶东网站建设百度地图优化排名方法
  • 公司网站的开发和网版的重要性网络热词作文
  • 代理平台注册网站建设资源最多的磁力搜索引擎