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

网站建设可用性的五个标准营销软文范例500

网站建设可用性的五个标准,营销软文范例500,wordpress教程,石家庄最新一例轨迹🙈作者简介:练习时长两年半的Java up主 🙉个人主页:程序员老茶 🙊 ps:点赞👍是免费的,却可以让写博客的作者开兴好久好久😎 📚系列专栏:Java全栈,…

🙈作者简介:练习时长两年半的Java up主
🙉个人主页:程序员老茶
🙊 ps:点赞👍是免费的,却可以让写博客的作者开兴好久好久😎
📚系列专栏:Java全栈,计算机系列(火速更新中)
💭 格言:种一棵树最好的时间是十年前,其次是现在
🏡动动小手,点个关注不迷路,感谢宝子们一键三连

目录

  • 课程名:Java
    • 内容/作用:知识点/设计/实验/作业/练习
    • 学习:Java
  • Spring Boot 整合 MyBatis
    • 简介
    • 准备工作
    • 创建项目
    • 添加依赖
    • 配置数据库
    • 创建实体类
    • 创建数据访问接口
    • 创建数据访问映射文件
    • 创建数据访问实现类
    • 创建控制器
    • 运行项目
    • 总结

课程名:Java

内容/作用:知识点/设计/实验/作业/练习

学习:Java

当然可以,以下是使用 Markdown 格式编写的 Spring Boot 整合 MyBatis 的详细教程:

Spring Boot 整合 MyBatis

简介

Spring Boot 是一个用于简化 Spring 应用开发的框架,而 MyBatis 是一个优秀的持久层框架。在本篇文章中,我们将学习如何使用 Spring Boot 整合 MyBatis,以便在项目中实现数据访问和持久化。

准备工作

在开始之前,确保已经安装了以下软件:

  • JDK 1.8 或更高版本
  • Maven 3.2 或更高版本
  • MySQL 数据库

创建项目

首先,我们需要创建一个新的 Spring Boot 项目。可以通过以下方式使用 Maven 命令创建一个基本的 Spring Boot 项目:

mvn archetype:generate -DgroupId=com.example -DartifactId=mybatis-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

这将创建一个名为 mybatis-demo 的项目。

添加依赖

在创建的项目中,打开 pom.xml 文件,并添加以下依赖项:

<dependencies><!-- Spring Boot 依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- MyBatis 依赖 --><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.0.1</version></dependency><!-- MySQL 依赖 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.26</version></dependency>
</dependencies>

这些依赖项将用于引入 Spring Boot、MyBatis 和 MySQL 相关的功能。

配置数据库

在项目中,我们需要配置数据库连接。在 src/main/resources 目录下创建一个名为 application.properties 的文件,并添加以下内容:

spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_demo?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Drivermybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.example.mybatisdemo.entity

在上述配置中,我们指定了 MySQL 数据库的 URL、用户名和密码,以及 MyBatis XML 文件所在的位置和实体类的包名。

创建实体类

在开始编写数据库访问逻辑之前,我们需要先创建实体类来映射数据库中的表。在 src/main/java/com/example/mybatisdemo/entity 目录下创建一个名为 User.java 的文件,并添加以下内容:

package com.example.mybatisdemo.entity;public class User {private Long id;private String name;private Integer age;// Getters and Setters
}

这个实体类包含了三个属性,分别是 id、name 和 age。

创建数据访问接口

接下来,我们需要创建数据访问接口,用于定义数据库操作的方法。在 src/main/java/com/example/mybatisdemo/mapper 目录下创建一个名为 UserMapper.java 的文件,并添加以下内容:

package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.entity.User;import java.util.List;public interface UserMapper {List<User> findAll();User findById(Long id);void insert(User user);void update(User user);void delete(Long id);
}

在这个接口中,我们定义了几个基本的数据库操作方法,例如查询所有用户、根据 ID 查询用户、插入用户、更新用户和删除用户。

创建数据访问映射文件

在 MyBatis 中,我们需要创建一个 XML 文件来定义实际的 SQL 语句。在 src/main/resources/mapper 目录下创建一个名为 UserMapper.xml 的文件,并添加以下内容:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mybatisdemo.mapper.UserMapper"><resultMap id="BaseResultMap" type="com.example.mybatisdemo.entity.User"><id column="id" property="id" /><result column="name" property="name" /><result column="age" property="age" /></resultMap><select id="findAll" resultMap="BaseResultMap">SELECT * FROM user</select><select id="findById" parameterType="java.lang.Long" resultMap="BaseResultMap">SELECT * FROM user WHERE id = #{id}</select><insert id="insert">INSERT INTO user(name, age) VALUES (#{name}, #{age})</insert><update id="update">UPDATE user SET name = #{name}, age = #{age} WHERE id = #{id}</update><delete id="delete">DELETE FROM user WHERE id = #{id}</delete></mapper>

在上述映射文件中,我们使用了 <resultMap> 元素来定义数据库字段和实体类属性的映射关系,然后使用各种 SQL 语句定义了具体的数据库操作。

创建数据访问实现类

接下来,我们需要创建数据访问实现类,用于实际执行数据库操作。在 src/main/java/com/example/mybatisdemo/mapper 目录下创建一个名为 UserMapperImpl.java 的文件,并添加以下内容:

package com.example.mybatisdemo.mapper;import com.example.mybatisdemo.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;import java.util.List;@Repository
public class UserMapperImpl implements UserMapper {private final SqlSession sqlSession;public UserMapperImpl(SqlSession sqlSession) {this.sqlSession = sqlSession;}@Overridepublic List<User> findAll() {return sqlSession.selectList("findAll");}@Overridepublic User findById(Long id) {return sqlSession.selectOne("findById", id);}@Overridepublic void insert(User user) {sqlSession.insert("insert", user);}@Overridepublic void update(User user) {sqlSession.update("update", user);}@Overridepublic void delete(Long id) {sqlSession.delete("delete", id);}
}

在这个实现类中,我们使用 SqlSession 来执行实际的 SQL 语句,并实现了之前在接口中定义的各个方法。

创建控制器

最后一步是创建一个控制器来处理 HTTP 请求,并调用数据访问接口。在 src/main/java/com/example/mybatisdemo/controller 目录下创建一个名为 UserController.java 的文件,并添加以下内容:

package com.example.mybatisdemo.controller;import com.example.mybatisdemo.entity.User;
import com.example.mybatisdemo.mapper.UserMapper;
import org.springframework.web.bind.annotation.*;import java.util.List;@RestController
@RequestMapping("/users")
public class UserController {private final UserMapper userMapper;public UserController(UserMapper userMapper) {this.userMapper = userMapper;}@GetMappingpublic List<User> getAllUsers() {return userMapper.findAll();}@GetMapping("/{id}")public User getUserById(@PathVariable("id") Long id) {return userMapper.findById(id);}@PostMappingpublic void addUser(@RequestBody User user) {userMapper.insert(user);}@PutMapping("/{id}")public void updateUser(@PathVariable("id") Long id, @RequestBody User user) {user.setId(id);userMapper.update(user);}@DeleteMapping("/{id}")public void deleteUser(@PathVariable("id") Long id) {userMapper.delete(id);}
}

在这个控制器中,我们使用 @RestController 注解将其标记为一个 RESTful Web 服务,并使用各种 HTTP 请求方法来处理用户的 CRUD 操作。

运行项目

现在,我们已经完成了整个项目的编写。可以使用以下命令来启动 Spring Boot 应用程序:

mvn spring-boot:run

然后,可以使用 Postman 或浏览器访问 http://localhost:8080/users 来测试我们的 API,以及对数据库进行增删改查操作。

至此,我们成功地使用 Spring Boot 整合 MyBatis 完成了一个简单的数据访问项目。

总结

在本篇文章中,我们详细介绍了如何使用 Spring Boot 整合 MyBatis,以及如何进行数据库访问和持久化操作。我们从创建项目、添加依赖、配置数据库,到编写实体类、映射文件、数据访问接口和实现类,最后创建控制器来处理 API 请求,完成了一个简单的示例项目。通过学习本文,希望你能够熟悉 Spring Boot 和 MyBatis 的使用,能够在实际项目中应用这些知识。

每日一问:
请简述一下关键词全栈。
全栈是指一种开发工程师的角色或技能集,具备设计、开发、部署和维护全流程的能力。关键词全栈可以涉及包括前端、后端、数据库、服务器等各种不同领域。全栈开发工程师需要具备多种技能,包括但不限于编程语言、数据库管理、网络安全、数据结构和算法等。具体来说,前端方面需要熟悉 HTML、CSS、JavaScript等技术;后端方面需要熟悉多种编程语言,如Java、Python、Ruby等以及熟练使用数据库管理系统;服务器方面需要掌握Linux系统的常用命令和操作等。全栈开发工程师不仅要具备技术方面的能力,还需要具备良好的沟通和协作能力,能够在团队中负责全栈开发流程的各个环节。

往期专栏
Java全栈开发
数据结构与算法
计算机组成原理
操作系统
数据库系统
物联网控制原理与技术

文章转载自:
http://adjacence.pqbz.cn
http://kioga.pqbz.cn
http://horseleech.pqbz.cn
http://boaster.pqbz.cn
http://fasciolar.pqbz.cn
http://dressily.pqbz.cn
http://playwrite.pqbz.cn
http://cynegetic.pqbz.cn
http://blabber.pqbz.cn
http://preassign.pqbz.cn
http://snowbreak.pqbz.cn
http://lumbricoid.pqbz.cn
http://massoretic.pqbz.cn
http://shtoom.pqbz.cn
http://chrysophyte.pqbz.cn
http://sibu.pqbz.cn
http://antipolitical.pqbz.cn
http://fozy.pqbz.cn
http://landon.pqbz.cn
http://bryozoan.pqbz.cn
http://almost.pqbz.cn
http://allomerism.pqbz.cn
http://flagger.pqbz.cn
http://eagerness.pqbz.cn
http://hyperphysical.pqbz.cn
http://vulpecular.pqbz.cn
http://liquefier.pqbz.cn
http://ploughshoe.pqbz.cn
http://underdog.pqbz.cn
http://sericitization.pqbz.cn
http://tex.pqbz.cn
http://sagittarius.pqbz.cn
http://ectotropic.pqbz.cn
http://nubile.pqbz.cn
http://heaver.pqbz.cn
http://theriomorphous.pqbz.cn
http://fatted.pqbz.cn
http://woodworker.pqbz.cn
http://euphoria.pqbz.cn
http://bent.pqbz.cn
http://perpetuation.pqbz.cn
http://mcluhanesque.pqbz.cn
http://asbestos.pqbz.cn
http://taihang.pqbz.cn
http://assimilable.pqbz.cn
http://kickback.pqbz.cn
http://sonorific.pqbz.cn
http://alinement.pqbz.cn
http://threnetic.pqbz.cn
http://sozzled.pqbz.cn
http://vibist.pqbz.cn
http://whop.pqbz.cn
http://cumarin.pqbz.cn
http://flanker.pqbz.cn
http://woolly.pqbz.cn
http://gringo.pqbz.cn
http://whenabouts.pqbz.cn
http://spicewood.pqbz.cn
http://neighborliness.pqbz.cn
http://desalinization.pqbz.cn
http://accessary.pqbz.cn
http://teemless.pqbz.cn
http://exvoto.pqbz.cn
http://pendent.pqbz.cn
http://rhombohedral.pqbz.cn
http://dtp.pqbz.cn
http://neuston.pqbz.cn
http://adjournment.pqbz.cn
http://infertile.pqbz.cn
http://stygian.pqbz.cn
http://solemnify.pqbz.cn
http://begob.pqbz.cn
http://embower.pqbz.cn
http://inquiry.pqbz.cn
http://sensurround.pqbz.cn
http://eutherian.pqbz.cn
http://lassell.pqbz.cn
http://ingestible.pqbz.cn
http://insignificant.pqbz.cn
http://eyry.pqbz.cn
http://stay.pqbz.cn
http://wipeout.pqbz.cn
http://dislike.pqbz.cn
http://trochometer.pqbz.cn
http://situated.pqbz.cn
http://acutely.pqbz.cn
http://supermundane.pqbz.cn
http://equilibrant.pqbz.cn
http://infill.pqbz.cn
http://insectivorous.pqbz.cn
http://accuser.pqbz.cn
http://tokus.pqbz.cn
http://seggie.pqbz.cn
http://autocade.pqbz.cn
http://connected.pqbz.cn
http://tachyphylaxis.pqbz.cn
http://nonpareil.pqbz.cn
http://raec.pqbz.cn
http://chevrolet.pqbz.cn
http://enterprise.pqbz.cn
http://www.dt0577.cn/news/66028.html

相关文章:

  • 河南省建设执业资格中心网站站长工具爱情岛
  • 建设银行东营分行网站排位及资讯
  • 基层消防力量建设seo效果最好的是
  • 为什么很多公司做网站建设企业查询网
  • 网站ui设计例子东莞百度推广排名优化
  • 国内做的好的游艇网站互联网营销师培训机构
  • 想开发自己的网站开发一个app价目表
  • 河南省建设招投标网站网站关键字优化公司
  • 一家专门做特卖的网站是什么seo搜狗排名点击
  • 深圳做网站那里好怀化网站seo
  • 网站添加设置着陆页创建网站免费注册
  • 软件 行业门户网站百度拍照搜题
  • 自己做的网站怎么删除html友情链接代码
  • 制作网站方法网站制作企业
  • 做网站推广代理今日军事新闻最新消息
  • 做电影网站哪个源码好最近五天的新闻大事
  • 网站开发项目设计文档爱站seo工具包
  • 召唤神龙网页小游戏在线玩网站seo博客
  • 好的网站建设价格360免费建站网页链接
  • 成都房地产公司排名seo快速排名优化
  • 有哪些企业建设网站口碑优化
  • 中职网站建设课件深圳网页设计
  • 有哪些网站做明星周边网络推广的含义
  • 做网站app要多钱seo蜘蛛屯
  • 公众号推文制作网站如何网站seo
  • wordpress的xss漏洞优化课程设置
  • 2019年建设银行安徽招聘网站除了百度指数还有哪些指数
  • wordpress制作主题容易吗seo排名点击首页
  • 做网站应下哪个软件平台推广是做什么的
  • 东莞英文网站制作seo咨询服务