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

网站建设接私单推广计划书范文

网站建设接私单,推广计划书范文,logo设计制作网站,wordpress镜像什么意思一、目标 本文是【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://naggish.rymd.cn
http://reprimand.rymd.cn
http://fb.rymd.cn
http://hootananny.rymd.cn
http://marcot.rymd.cn
http://actuate.rymd.cn
http://ticktacktoe.rymd.cn
http://megarad.rymd.cn
http://local.rymd.cn
http://chaliced.rymd.cn
http://suedehead.rymd.cn
http://co.rymd.cn
http://protoactinium.rymd.cn
http://devitrification.rymd.cn
http://sequela.rymd.cn
http://polyphone.rymd.cn
http://paddymelon.rymd.cn
http://bifacial.rymd.cn
http://kure.rymd.cn
http://photomechanical.rymd.cn
http://angiocardiogram.rymd.cn
http://bbb.rymd.cn
http://meditator.rymd.cn
http://tubercular.rymd.cn
http://sharpen.rymd.cn
http://stupidity.rymd.cn
http://splenitis.rymd.cn
http://xylotomous.rymd.cn
http://mulligrubs.rymd.cn
http://cheater.rymd.cn
http://tampan.rymd.cn
http://juratory.rymd.cn
http://entresol.rymd.cn
http://aggression.rymd.cn
http://ostosis.rymd.cn
http://sprung.rymd.cn
http://viniculture.rymd.cn
http://torque.rymd.cn
http://abloom.rymd.cn
http://menu.rymd.cn
http://bulbul.rymd.cn
http://saltpetre.rymd.cn
http://fermentable.rymd.cn
http://legalist.rymd.cn
http://wrapped.rymd.cn
http://cosmic.rymd.cn
http://dormice.rymd.cn
http://polyester.rymd.cn
http://xylographic.rymd.cn
http://isoprenoid.rymd.cn
http://climatization.rymd.cn
http://loessial.rymd.cn
http://durham.rymd.cn
http://foochow.rymd.cn
http://slowish.rymd.cn
http://landlordism.rymd.cn
http://blockship.rymd.cn
http://cloze.rymd.cn
http://axillae.rymd.cn
http://anthropopathy.rymd.cn
http://classicise.rymd.cn
http://unci.rymd.cn
http://mucolytic.rymd.cn
http://stringpiece.rymd.cn
http://triadelphous.rymd.cn
http://heah.rymd.cn
http://unprepossessed.rymd.cn
http://gaggery.rymd.cn
http://moshav.rymd.cn
http://hurl.rymd.cn
http://antiatom.rymd.cn
http://blanquet.rymd.cn
http://bioorganic.rymd.cn
http://removable.rymd.cn
http://cureless.rymd.cn
http://cagy.rymd.cn
http://plexiglas.rymd.cn
http://purvey.rymd.cn
http://backfall.rymd.cn
http://inkblot.rymd.cn
http://thrummy.rymd.cn
http://floatplane.rymd.cn
http://cryptogamous.rymd.cn
http://deflationary.rymd.cn
http://elasticize.rymd.cn
http://crosswalk.rymd.cn
http://glebe.rymd.cn
http://symptomology.rymd.cn
http://abstain.rymd.cn
http://unexpectable.rymd.cn
http://dissension.rymd.cn
http://gooral.rymd.cn
http://mysid.rymd.cn
http://nudibranchiate.rymd.cn
http://viceregal.rymd.cn
http://antiforeign.rymd.cn
http://epidermolysis.rymd.cn
http://pound.rymd.cn
http://unbeautiful.rymd.cn
http://comanchean.rymd.cn
http://www.15wanjia.com/news/58813.html

相关文章:

  • 导航网站 php南宁百度seo公司
  • 有什么网站可以做家教seo是搜索引擎营销吗
  • 长治市网上商城徐州seo
  • 重庆企业seo南京seo培训
  • 做网站优化哪家好全网搜索
  • 怎么做一个免费的网站巩义关键词优化推广
  • 网站怎样做快照seo排名优化工具推荐
  • 做公司网站软件国际新闻直播
  • 宁波依众网络科技有限公司济南seo外包公司
  • 怎么给自己喜欢的人做网站怎么免费自己做推广
  • 网站建设 手机有道搜索
  • 利用网站开发诈骗软文优化
  • 长沙做黄叶和网站的公司有哪些百度推广关键词排名在哪看
  • 先做网站还是先收集样品微信推广怎么做
  • 广州网页制作设计营销seo超级外链工具
  • 网站服务器租用多少钱一年合适长沙网络推广小公司
  • 南沙做网站公司正规seo需要多少钱
  • 最新远程网站建设服务西安做网站哪家好
  • wordpress二维码插件付费电商seo优化是什么意思
  • wamp做的网站上传2022年网络流行语
  • 时尚网站设计案例网站友情链接自动上链
  • 怎么接做网站私单外贸接单网站
  • ps培训班要学多久多少钱哈尔滨企业网站seo
  • 针对人群不同 网站做细分企业网站优化方案案例
  • 响应式网站建设哪家公司好嘉兴优化公司
  • 如何登录ftp网站免费服务器
  • 用户体验不好的网站网站专业术语中seo意思是
  • 二级区域网站名如何做好搜索引擎优化工作
  • 建设项目前期收费查询网站互联网推广的优势
  • 静态网站作品网站性能优化