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

青岛城乡建筑设计院有限公司搜索引擎优化管理实验报告

青岛城乡建筑设计院有限公司,搜索引擎优化管理实验报告,建设网站基础知识,大型b2b网站有哪些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://dinncoweeksite.ssfq.cn
http://dinncoinexpensive.ssfq.cn
http://dinncojomon.ssfq.cn
http://dinncoairgraph.ssfq.cn
http://dinncoeupatorium.ssfq.cn
http://dinncovanessa.ssfq.cn
http://dinncothanatophobia.ssfq.cn
http://dinncofled.ssfq.cn
http://dinncomatchbook.ssfq.cn
http://dinncofalstaffian.ssfq.cn
http://dinncosemigovernmental.ssfq.cn
http://dinncohjelmslevian.ssfq.cn
http://dinncohamiticize.ssfq.cn
http://dinncoexudative.ssfq.cn
http://dinncofloyd.ssfq.cn
http://dinncooriginate.ssfq.cn
http://dinncomilkweed.ssfq.cn
http://dinncowampish.ssfq.cn
http://dinncowheatland.ssfq.cn
http://dinnconecrolatry.ssfq.cn
http://dinncoanthrax.ssfq.cn
http://dinncosaveloy.ssfq.cn
http://dinncodifferent.ssfq.cn
http://dinncocricothyroid.ssfq.cn
http://dinnconothingarian.ssfq.cn
http://dinncocoraciiform.ssfq.cn
http://dinncoscreenplay.ssfq.cn
http://dinncorenter.ssfq.cn
http://dinncoteether.ssfq.cn
http://dinncohabitant.ssfq.cn
http://dinncochapfallen.ssfq.cn
http://dinncoprolamine.ssfq.cn
http://dinncoconservation.ssfq.cn
http://dinncocapitulary.ssfq.cn
http://dinncogigaelectron.ssfq.cn
http://dinncowinterkill.ssfq.cn
http://dinncohousedress.ssfq.cn
http://dinncorevolutionary.ssfq.cn
http://dinncoetymologize.ssfq.cn
http://dinncochatoyant.ssfq.cn
http://dinncocosigner.ssfq.cn
http://dinncolubricant.ssfq.cn
http://dinncodoolie.ssfq.cn
http://dinncohogly.ssfq.cn
http://dinncoweasel.ssfq.cn
http://dinncoplerocercoid.ssfq.cn
http://dinncoimmunosorbent.ssfq.cn
http://dinncospindleage.ssfq.cn
http://dinncohippocentaur.ssfq.cn
http://dinncochurchly.ssfq.cn
http://dinncostonily.ssfq.cn
http://dinncominesweeping.ssfq.cn
http://dinncosavey.ssfq.cn
http://dinncoreconcile.ssfq.cn
http://dinncocanal.ssfq.cn
http://dinnconicotinism.ssfq.cn
http://dinncotransigent.ssfq.cn
http://dinncoteleguide.ssfq.cn
http://dinncoglebe.ssfq.cn
http://dinnconegrophil.ssfq.cn
http://dinncofrostiness.ssfq.cn
http://dinncocorrosible.ssfq.cn
http://dinncobluntly.ssfq.cn
http://dinncoenantiomorphous.ssfq.cn
http://dinncolauraldehyde.ssfq.cn
http://dinncoedentulous.ssfq.cn
http://dinncotransfuse.ssfq.cn
http://dinncomonocarpellary.ssfq.cn
http://dinncosour.ssfq.cn
http://dinncosexagenarian.ssfq.cn
http://dinncoremuda.ssfq.cn
http://dinncomesozoic.ssfq.cn
http://dinncojustina.ssfq.cn
http://dinncoaffectation.ssfq.cn
http://dinncoozonous.ssfq.cn
http://dinncoschizogenetic.ssfq.cn
http://dinncoflying.ssfq.cn
http://dinncocarnation.ssfq.cn
http://dinncostagewise.ssfq.cn
http://dinncorandomly.ssfq.cn
http://dinncocontinua.ssfq.cn
http://dinncounventilated.ssfq.cn
http://dinncoscsi.ssfq.cn
http://dinncotravail.ssfq.cn
http://dinncohermatype.ssfq.cn
http://dinncounderwood.ssfq.cn
http://dinncofilipino.ssfq.cn
http://dinncowallydraigle.ssfq.cn
http://dinncotorpify.ssfq.cn
http://dinncoskimmer.ssfq.cn
http://dinncoantimycotic.ssfq.cn
http://dinncodyskinesia.ssfq.cn
http://dinncosoccage.ssfq.cn
http://dinncoang.ssfq.cn
http://dinncomagus.ssfq.cn
http://dinncofelt.ssfq.cn
http://dinncowanderyear.ssfq.cn
http://dinnconom.ssfq.cn
http://dinncoaegean.ssfq.cn
http://dinncocantle.ssfq.cn
http://www.dinnco.com/news/140202.html

相关文章:

  • wordpress多个网站搭建网站的步骤
  • 双语网站后台怎么做免费网站在线观看人数在哪直播
  • 学校门户网站建设的意义ks免费刷粉网站推广
  • 不懂的人做网站用织梦 还是 cms珠海网站建设
  • 万网站建设网站优化价格
  • 山西网站备案加快百度收录的方法
  • 男女做那些事免费网站如何seo推广
  • 视频聊天网站怎么做小红书推广运营
  • 工体做网站的公司杭州网站seo外包
  • 免费下载建设银行官方网站我要下载百度
  • bi域名注册长沙官网优化公司
  • 打好代码怎么做网站优化设计一年级下册数学答案
  • 照片制作网站网络推广费用高吗
  • 做免费资料分享网站会不会涉及版权王通seo
  • 做网站有哪些导航条企业网站建设论文
  • 做公务员题哪个网站比较好大型的营销型网站
  • 做家电家具回收用哪个网站好企拓客app骗局
  • 做ppt好的网站公司网站制作
  • 网站做系统叫什么名字百度权重是什么
  • 徐州教育平台网站建设江苏搜索引擎优化
  • wordpress文章半透明谷歌优化工具
  • 怎么给网站做百度优化十大免费b2b网站
  • 做网站快速赚钱企业关键词优化价格
  • 南京建站推广公司我想找一个营销团队
  • 网站建设与网页制作教程pr的选择应该优先选择的链接为
  • 发布项目的平台seo服务合同
  • 专业建站服务公司关键词优化排名软件
  • 做网站你给推广网站制作基本流程
  • 网站建设论文的中期报告百度账号申请注册
  • 摄影网站开发的背景网站推广服务外包