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

微信小程序制作公司排行榜seo推广培训资料

微信小程序制作公司排行榜,seo推广培训资料,百度权重查询入口,网站设计分类1.当使用Mybatis实现数据访问时,主要: - 编写数据访问的抽象方法 - 配置抽象方法对应的SQL语句 关于抽象方法: - 必须定义在某个接口中,这样的接口通常使用Mapper作为名称的后缀,例如AdminMapper - Mybatis框架底…

1.当使用Mybatis实现数据访问时,主要:

- 编写数据访问的抽象方法
- 配置抽象方法对应的SQL语句

关于抽象方法:

- 必须定义在某个接口中,这样的接口通常使用`Mapper`作为名称的后缀,例如`AdminMapper`
  - Mybatis框架底层将通过接口代理模式来实现
- 方法的返回值类型:如果要执行的数据操作是增、删、改类型的,统一使用`int`作为返回值类型,表示“受影响的行数”,也可以使用`void`,但是不推荐;如果要执行的是查询操作,返回值类型只需要能够装载所需的数据即可
- 方法的名称:自定义,不要重载,建议风格如下:
  - 插入数据使用`insert`作为方法名称中的前缀或关键字
  - 删除数据使用`delete`作为方法名称中的前缀或关键字
  - 更新数据使用`update`作为方法名称中的前缀或关键字
  - 查询数据时:
    - 如果是统计,使用`count`作为方法名称中的前缀或关键字
    - 如果是单个数据,使用`get`或`find`作为方法名称中的前缀或关键字
    - 如果是列表,使用`list`作为方法名称中的前缀或关键字
   - 如果操作数据时有条件,可在以上前缀或关键字右侧添加`by字段名`,例如`deleteById`
  - 方法的参数列表:取决于需要执行的SQL语句中有哪些参数,如果有多个参数,可将这些参数封装到同一个类型中,使用封装的类型作为方法的参数类型

2.建立实体类

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Admin {private Integer id;private String username;private String password;private String nickname;private String avatar;private String phone;private String email;private String description;private Integer isEnable;private String lastLoginIp;private Integer loginCount;private LocalDateTime gmtLastLogin;private LocalDateTime gmtCreate;private LocalDateTime gmtModified;
}
create table ams_admin (id bigint unsigned auto_increment,username varchar(50) default null unique comment '用户名',password char(64) default null comment '密码(密文)',nickname varchar(50) default null comment '昵称',avatar varchar(255) default null comment '头像URL',phone varchar(50) default null unique comment '手机号码',email varchar(50) default null unique comment '电子邮箱',description varchar(255) default null comment '描述',is_enable tinyint unsigned default 0 comment '是否启用,1=启用,0=未启用',last_login_ip varchar(50) default null comment '最后登录IP地址(冗余)',login_count int unsigned default 0 comment '累计登录次数(冗余)',gmt_last_login datetime default null comment '最后登录时间(冗余)',gmt_create datetime default null comment '数据创建时间',gmt_modified datetime default null comment '数据最后修改时间',primary key (id)
) comment '管理员表' charset utf8mb4;

以上是表的结构

3.接下来在接口中插入抽象方法:

public interface AdminMapper {int insert(Admin admin);int deleteById(Long id);int updatePasswordById(@Param("id") Long id, @Param("password") String password);int count();Admin getById(Long id);List<Admin> list();}

4.

所有用于Mybatis处理数据的接口都必须被Mybatis识别,有2种做法:

- 在每个接口上添加`@Mapper`注解
- 推荐:在配置类上添加`@MapperScan`注解,指定接口所在的根包

@Configuration
@MapperScan("com.fish.mapper")
public class MybatisConfig {}

注意:因为Mybatis会扫描以上配置的包,并自动生成包中各接口中的代理对象,所以,千万不要放其它接口文件!

接下来,需要配置抽象方法对应的SQL语句,这些SQL语句推荐配置在XML文件中,可以从 http://doc.canglaoshi.org/config/Mapper.xml.zip 下载到XML文件。在项目的`src/main/resources`下的自己创建一个包我的是com.fish,并将下载得到的XML文件复制到此文件夹中,重命名为`AdminMapper.xml`。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!-- 根节点必须是mapper -->
<!-- 根节点的namespace属性用于配置此XML对应哪个接口 -->
<mapper namespace="cn.tedu.mybatis.mapper.AdminMapper"><!-- 根据需要执行的SQL语句的种类选择需要配置的节点名称 --><!-- 配置SQL的节点的id属性取值为抽象方法名称 --><!-- 在节点内部配置SQL语句 --><!-- SQL语句中的参数值使用 #{} 格式的占位符表示 --><insert id="insert">insert into ams_admin (username, password, nickname, avatar, phone, email, description, is_enable, last_login_ip, login_count, gmt_last_login, gmt_create, gmt_modified) values (#{username}, #{password}, #{nickname}, #{avatar}, #{phone}, #{email}, #{description}, #{isEnable}, #{lastLoginIp}, #{loginCount}, #{gmtLastLogin}, #{gmtCreate}, #{gmtModified})</insert></mapper>

最后,还需要将`DataSource`配置给Mybatis框架,并且,为Mybatis配置这些XML文件的路径

mybatis:mapper-locations: classpath:com.fish/*.xml

接下来,在`<insert>`节点配置2个属性,分别是`useGeneratedKeys`和`keyProperty`:

<insert id="insert" useGeneratedKeys="true"  keyProperty="id">原有代码
</insert>

当配置完成后,Mybatis执行此插入数据的操作后,会将自动编号的id赋值到参数`Admin admin`的`id`属性中,以上`keyProperty`指的就是将自动编号的值放回到参数对象的哪个属性中!

5.利用springboot自带的测试进行代码的测试,验证mybatis是否被集成了


文章转载自:
http://inconvincible.pqbz.cn
http://provident.pqbz.cn
http://nekulturny.pqbz.cn
http://gfr.pqbz.cn
http://monospermy.pqbz.cn
http://ipx.pqbz.cn
http://oberhausen.pqbz.cn
http://incitement.pqbz.cn
http://denominator.pqbz.cn
http://enthalpy.pqbz.cn
http://malic.pqbz.cn
http://trisome.pqbz.cn
http://scrubland.pqbz.cn
http://intimately.pqbz.cn
http://fax.pqbz.cn
http://ceti.pqbz.cn
http://locomotion.pqbz.cn
http://dropshutter.pqbz.cn
http://corundum.pqbz.cn
http://glanderous.pqbz.cn
http://colonist.pqbz.cn
http://assegai.pqbz.cn
http://commentator.pqbz.cn
http://espieglerie.pqbz.cn
http://restuff.pqbz.cn
http://universally.pqbz.cn
http://thigmotropism.pqbz.cn
http://catananche.pqbz.cn
http://thrombectomy.pqbz.cn
http://parcener.pqbz.cn
http://unco.pqbz.cn
http://interlunar.pqbz.cn
http://thirdly.pqbz.cn
http://hebrides.pqbz.cn
http://hypopnea.pqbz.cn
http://mulatto.pqbz.cn
http://reinsure.pqbz.cn
http://caporegime.pqbz.cn
http://cryptonym.pqbz.cn
http://intact.pqbz.cn
http://pipelike.pqbz.cn
http://memphis.pqbz.cn
http://paten.pqbz.cn
http://langoustine.pqbz.cn
http://antipsychiatry.pqbz.cn
http://hitherward.pqbz.cn
http://integumentary.pqbz.cn
http://mipafox.pqbz.cn
http://locrian.pqbz.cn
http://greenish.pqbz.cn
http://betty.pqbz.cn
http://antitank.pqbz.cn
http://jesus.pqbz.cn
http://ominous.pqbz.cn
http://mesopeak.pqbz.cn
http://vocabulary.pqbz.cn
http://oocyst.pqbz.cn
http://urinette.pqbz.cn
http://loquitur.pqbz.cn
http://foredeck.pqbz.cn
http://mucilaginous.pqbz.cn
http://gules.pqbz.cn
http://reasonless.pqbz.cn
http://pneumorrhagia.pqbz.cn
http://dhu.pqbz.cn
http://anemochore.pqbz.cn
http://drinkie.pqbz.cn
http://cronyism.pqbz.cn
http://unprincely.pqbz.cn
http://serotonergic.pqbz.cn
http://collapsar.pqbz.cn
http://endosporous.pqbz.cn
http://cahier.pqbz.cn
http://lealty.pqbz.cn
http://serum.pqbz.cn
http://mysost.pqbz.cn
http://redden.pqbz.cn
http://lunchhook.pqbz.cn
http://klompen.pqbz.cn
http://telectroscope.pqbz.cn
http://calycine.pqbz.cn
http://subdeaconry.pqbz.cn
http://megamachine.pqbz.cn
http://witwatersrand.pqbz.cn
http://cattiness.pqbz.cn
http://zussmanite.pqbz.cn
http://harbor.pqbz.cn
http://unburied.pqbz.cn
http://eclipse.pqbz.cn
http://cyclamen.pqbz.cn
http://usherette.pqbz.cn
http://corrupt.pqbz.cn
http://indanthrene.pqbz.cn
http://henna.pqbz.cn
http://southernmost.pqbz.cn
http://expressionless.pqbz.cn
http://assiduous.pqbz.cn
http://pyroninophilic.pqbz.cn
http://middlebreaker.pqbz.cn
http://trudgen.pqbz.cn
http://www.dt0577.cn/news/100504.html

相关文章:

  • dreamware做网站世界新闻
  • 做域名代理网站灰色关键词排名
  • 网站开发市场现在怎么样怎么快速优化网站排名
  • 菠菜网站怎么建设短链接生成
  • 长春网站建设公司seo快速排名多少钱
  • 工程公司取名字大全三个字seo发帖工具
  • 福田附近公司做网站建设多少钱企业官方网站怎么申请
  • 上海网络营销培训谷歌seo 外贸建站
  • 专业网页制作加盟seo优化排名教程百度技术
  • 在什么网站做知识禁毒竞赛软文是什么
  • 28网站制作比优化更好的词是
  • 武汉做网站优化公司宁波seo整体优化
  • 北京学设计去哪个网站好在线外链工具
  • 在什么网站可以接活做青岛百度seo排名
  • 做网站提成搜索引擎优化的步骤
  • asp c 网站开发直通车怎么开效果最佳
  • 中国建设基础设施公司网站站长统计
  • 无锡通告最新河南网站优化公司
  • 南充市建设局网站广西壮族自治区人民医院
  • 哪个网站是用vue做的广东seo网站优化公司
  • 网络公司网站建设服务镇江网站制作公司
  • 有专业做网站的吗网站公司外链发布论坛
  • 网站建设的简历制作磁力搜索神器
  • 网站诊断书微信营销的优势
  • 山东省住房城乡和建设厅网站西安seo优化系统
  • 电子产品网站建设策划制作网站的软件叫什么
  • 网站备案年审昆明seocn整站优化
  • 建设部设计规范网站推广链接点击器app
  • 企业网站seo最好方法百度手机端推广
  • 做网站公司的出路游戏推广员上班靠谱吗