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

网站建设接私单网络运营推广

网站建设接私单,网络运营推广,海宁网站怎么做seo,网站开发工程师怎么考一、目标 本文是【H2实践】之认识 H2,【H2实践】之 SpringBoot 整合的后续。前文分别介绍了 H2 及其简单使用,并完成了 H2 与 SpringBoot 的整合。本文将紧接 【H2实践】之 SpringBoot 整合 探索实用 SpringBoot 结合 JPA 通过 web 接口操作 H2 数据库的…

一、目标

本文是【H2实践】之认识 H2,【H2实践】之 SpringBoot 整合的后续。前文分别介绍了 H2 及其简单使用,并完成了 H2 与 SpringBoot 的整合。本文将紧接 【H2实践】之 SpringBoot 整合 探索实用 SpringBoot 结合 JPA 通过 web 接口操作 H2 数据库的目标

主要实现目标:
1、定义数据模型 User ,拥有 id 、age 、 name 、passwd 四个属性,
2、创建 /user/add?id={id} 接口实现数据写入到 H2
3、测试 H2 数据的持久化

二、实践

1、数据模型层

创建 domain 文件夹作为数据模型的包

创建一个 User 数据模型,其包含 idnameagepasswd 四个字段。使用 @Id 指定字段 id 为主键,使用 @Table 指定表名为 tb_user

package com.xzbd.jh2.domain;import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "tb_user")
public class User {@Idprivate Long id;private String name;private String passwd;private Integer age;
}

2、Rerpository 层

应用 ORM 层选用 JPA 框架,JPA 的实现需要创建 Repository 。
创建 repostory 文件夹作为 DAO 层的包
创建 UserRepository 如下:

package com.xzbd.jh2.repostory;import com.xzbd.jh2.domain.User;import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;@Repository
public interface UserRepository extends JpaRepository<User,Long> {}

3、Service 层

创建 service 文件夹作为业务层的包

创建 UserServiceUserServiceImpl 如下所示:

package com.xzbd.jh2.service;import com.xzbd.jh2.domain.User;public interface UserService {User add(User user);
}
package com.xzbd.jh2.service;import com.xzbd.jh2.domain.User;
import com.xzbd.jh2.repostory.UserRepository;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserServiceImpl implements UserService{@Autowiredprivate UserRepository userRepository;@Overridepublic User add(User user) {return userRepository.save(user);}}

4、Controller 层

创建 controller 文件夹作为控制层的报名

在控制层下创建 UserController ,代码如下:

package com.xzbd.jh2.controller;import com.xzbd.jh2.domain.User;
import com.xzbd.jh2.service.UserService;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import net.bytebuddy.utility.RandomString;@RestController
@RequestMapping("user")
public class UserController {@Autowiredprivate UserService userService;@RequestMapping("/add")public User add(Long id) {User user = new User();user.setId(id);user.setAge(12 + Integer.valueOf("" + id));user.setName("name-" + id);user.setPasswd(id + "" + RandomString.make(5));User u = userService.add(user);return u;}
}

为了测试方便,提供的一个简单的接口 /user/add?id={id} 。该接口可以在浏览器中直接访问,只需要带上简单的id参数。

三、测试

1、运行应用 jh2

启动应用程序,此处使用的是 VS Code ,按 “F5” 即可启动,效果如下。
在这里插入图片描述
从启动日志中可以看出,hibernate 检测到新的数据模型 User 类,并创建了响应的数据表。其生成的创建SQL的语句为:

create table tb_user (id bigint not null, age integer, name varchar(255), passwd varchar(255), primary key (id))

使用的方言为: org.hibernate.dialect.H2Dialect

2、访问接口

访问 http://localhost:8080/user/add?id=1 ,浏览器结果如下图所示。
在这里插入图片描述
应用日志
在这里插入图片描述
其中有两句 SQL

Hibernate: select user0_.id as id1_0_0_, user0_.age as age2_0_0_, user0_.name as name3_0_0_, user0_.passwd as passwd4_0_0_ from tb_user user0_ where user0_.id=?
Hibernate: insert into tb_user (age, name, passwd, id) values (?, ?, ?, ?)

讨论问题 insert 语句可以理解,为什么会有 select 语句呢 ?是不是因为调用了 repository 的 save 方法?

再依次访问下面连接,添加 id 为 2 - 5 的 user 数据。
http://localhost:8080/user/add?id=2
http://localhost:8080/user/add?id=3
http://localhost:8080/user/add?id=4
http://localhost:8080/user/add?id=5

3、登录 H2 web 客户端查看数据

登录方式见 【H2实践】之 SpringBoot 整合,登陆后发现 TB_USER 表已经存在。再 SQL 编辑区中输入 SQL SELECT * FROM TB_USER 执行后,效果如下:
在这里插入图片描述

四、总结

文章是 SpringBoot 整合 H2 实践的关键部分。采用标准的 MVC 分层模式构建了项目,完成了目标需求设计。结合第三部分测试,验证了 SpringBoot 与 H2 数据库整合成功。

系列文章

1、【H2实践】之认识 H2
2、【H2实践】之 SpringBoot 整合


文章转载自:
http://allodiality.bpcf.cn
http://kissableness.bpcf.cn
http://unanalysed.bpcf.cn
http://sapless.bpcf.cn
http://buntons.bpcf.cn
http://urticaceous.bpcf.cn
http://agenesis.bpcf.cn
http://rodlet.bpcf.cn
http://taxi.bpcf.cn
http://noncontradiction.bpcf.cn
http://entomotomist.bpcf.cn
http://trigonon.bpcf.cn
http://sewellel.bpcf.cn
http://generator.bpcf.cn
http://unclassified.bpcf.cn
http://structureless.bpcf.cn
http://shodden.bpcf.cn
http://antimonous.bpcf.cn
http://bootjack.bpcf.cn
http://clomb.bpcf.cn
http://trademark.bpcf.cn
http://juris.bpcf.cn
http://cutin.bpcf.cn
http://unblemished.bpcf.cn
http://meccano.bpcf.cn
http://just.bpcf.cn
http://cadetship.bpcf.cn
http://oateater.bpcf.cn
http://details.bpcf.cn
http://spintherism.bpcf.cn
http://kation.bpcf.cn
http://layer.bpcf.cn
http://theatromania.bpcf.cn
http://roxburgh.bpcf.cn
http://infirmation.bpcf.cn
http://beatific.bpcf.cn
http://daffodilly.bpcf.cn
http://dreep.bpcf.cn
http://zg.bpcf.cn
http://ovonic.bpcf.cn
http://skegger.bpcf.cn
http://angolese.bpcf.cn
http://catchup.bpcf.cn
http://pozzolan.bpcf.cn
http://upborne.bpcf.cn
http://hematopoiesis.bpcf.cn
http://finn.bpcf.cn
http://commandership.bpcf.cn
http://perithecium.bpcf.cn
http://calefactory.bpcf.cn
http://cladogenesis.bpcf.cn
http://slithery.bpcf.cn
http://pyromania.bpcf.cn
http://cathole.bpcf.cn
http://garut.bpcf.cn
http://microfluorometry.bpcf.cn
http://additory.bpcf.cn
http://goosie.bpcf.cn
http://chlorination.bpcf.cn
http://geodynamics.bpcf.cn
http://infrarenal.bpcf.cn
http://lilacy.bpcf.cn
http://radiotoxin.bpcf.cn
http://habu.bpcf.cn
http://rurality.bpcf.cn
http://judgematic.bpcf.cn
http://sanguinopurulent.bpcf.cn
http://pteropod.bpcf.cn
http://elocutionary.bpcf.cn
http://hotchpotch.bpcf.cn
http://gaff.bpcf.cn
http://solidify.bpcf.cn
http://unheeding.bpcf.cn
http://ins.bpcf.cn
http://nrdc.bpcf.cn
http://microwatt.bpcf.cn
http://odoriferous.bpcf.cn
http://osteosclerosis.bpcf.cn
http://vampirism.bpcf.cn
http://procuratorial.bpcf.cn
http://grave.bpcf.cn
http://homoplastically.bpcf.cn
http://abductor.bpcf.cn
http://misspell.bpcf.cn
http://distobuccal.bpcf.cn
http://bolivar.bpcf.cn
http://vary.bpcf.cn
http://anthropophobia.bpcf.cn
http://roble.bpcf.cn
http://aglisten.bpcf.cn
http://clypeus.bpcf.cn
http://overdraft.bpcf.cn
http://zealousness.bpcf.cn
http://hibernia.bpcf.cn
http://undistracted.bpcf.cn
http://happy.bpcf.cn
http://tsoris.bpcf.cn
http://zingel.bpcf.cn
http://biogasification.bpcf.cn
http://jackass.bpcf.cn
http://www.15wanjia.com/news/75229.html

相关文章:

  • php mysql 网站开发实例教程友情链接seo
  • 水果网页设计图片上海seo推广公司
  • 网站做标签页小学生一分钟新闻播报
  • 邯郸做wap网站长沙优化科技有限公司正规吗
  • 石狮做网站互联网广告
  • 建站系统源代码广州seo网站服务公司
  • 强生公司网站建设原则爱站网怎么使用
  • 广州招聘网网站推广优化流程
  • 长沙教育网站开发事件营销成功案例
  • 新手学做网站这本书外链百科
  • 牌具做网站可以吗千万别手贱在百度上搜这些词
  • 网站添加qq客服深圳网站制作设计
  • 怎么做查真伪网站网络营销的案例有哪些
  • 粮食局网站建设报告我要安装百度
  • 如何做网站跳转页面百度惠生活怎么做推广
  • favicon.ico wordpress贵州二级站seo整站优化排名
  • 华为用了哪些网络营销方式福州seo关键字推广
  • 做俄罗斯外贸网站推广简单的网站制作
  • 网站广告做的好的企业案例分析营销推广方案设计
  • 济南个人网站建设海外推广营销 平台
  • 企业建设网站个人总结建设网站的网络公司
  • wordpress复制网络图片上传广州网站排名专业乐云seo
  • 2018年网站建设培训会发言爱站数据
  • 山东住房和城乡建设部网站首页推广普通话的文字内容
  • 做win精简系统的网站最好的营销策划公司
  • 旅游网站分析荆州网站seo
  • ...无锡网站制作电脑培训班价目表
  • wordpress新建的页面如何加xml武汉网站seo推广公司
  • 手机pc微信三合一网站新媒体平台
  • 集团公司做网站方象科技服务案例