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

网站后台上图片后网页显示不正确seo去哪里培训

网站后台上图片后网页显示不正确,seo去哪里培训,国家市场监督管理总局电话0108865,wordpress 地图相册Spring Boot与MyBatis的集成应用 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天我们来聊聊Spring Boot与MyBatis的集成应用。MyBatis是一款优秀的持久层框…

Spring Boot与MyBatis的集成应用

大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿!今天我们来聊聊Spring Boot与MyBatis的集成应用。MyBatis是一款优秀的持久层框架,它消除了几乎所有的JDBC代码和手动设置参数以及获取结果集的工作。通过与Spring Boot的集成,可以更简洁、高效地进行数据库操作。本文将详细介绍如何在Spring Boot项目中集成MyBatis。

一、创建Spring Boot项目

首先,我们需要创建一个Spring Boot项目,可以通过Spring Initializr来快速创建。在项目创建过程中,选择以下依赖:

  • Spring Web
  • MyBatis Framework
  • MySQL Driver

项目创建完成后,我们需要进行一些基础配置。

二、配置数据库连接

application.properties文件中添加数据库连接信息:

spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Drivermybatis.type-aliases-package=cn.juwatech.entity
mybatis.mapper-locations=classpath:mapper/*.xml

三、创建数据库实体类

接下来,我们创建一个数据库实体类。例如,一个简单的用户实体类:

package cn.juwatech.entity;public class User {private Long id;private String username;private String password;// getters and setterspublic Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}
}

四、创建MyBatis Mapper接口

接下来,我们创建一个Mapper接口,并定义数据库操作方法。Mapper接口与MyBatis映射文件对应:

package cn.juwatech.mapper;import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;import cn.juwatech.entity.User;import java.util.List;@Mapper
public interface UserMapper {@Select("SELECT * FROM users")List<User> findAll();User findById(Long id);void insert(User user);void update(User user);void delete(Long id);
}

五、创建MyBatis映射文件

resources/mapper目录下创建对应的XML映射文件UserMapper.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="cn.juwatech.mapper.UserMapper"><select id="findById" resultType="cn.juwatech.entity.User">SELECT * FROM users WHERE id = #{id}</select><insert id="insert">INSERT INTO users (username, password) VALUES (#{username}, #{password})</insert><update id="update">UPDATE users SET username = #{username}, password = #{password} WHERE id = #{id}</update><delete id="delete">DELETE FROM users WHERE id = #{id}</delete></mapper>

六、创建Service层

在Service层中,我们调用Mapper接口的方法,实现业务逻辑:

package cn.juwatech.service;import cn.juwatech.entity.User;
import cn.juwatech.mapper.UserMapper;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class UserService {@Autowiredprivate UserMapper userMapper;public List<User> findAll() {return userMapper.findAll();}public User findById(Long id) {return userMapper.findById(id);}public void insert(User user) {userMapper.insert(user);}public void update(User user) {userMapper.update(user);}public void delete(Long id) {userMapper.delete(id);}
}

七、创建Controller层

最后,在Controller层中,我们通过Service层调用业务逻辑,处理HTTP请求:

package cn.juwatech.controller;import cn.juwatech.entity.User;
import cn.juwatech.service.UserService;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;@RestController
@RequestMapping("/users")
public class UserController {@Autowiredprivate UserService userService;@GetMappingpublic List<User> findAll() {return userService.findAll();}@GetMapping("/{id}")public User findById(@PathVariable Long id) {return userService.findById(id);}@PostMappingpublic void insert(@RequestBody User user) {userService.insert(user);}@PutMapping("/{id}")public void update(@PathVariable Long id, @RequestBody User user) {user.setId(id);userService.update(user);}@DeleteMapping("/{id}")public void delete(@PathVariable Long id) {userService.delete(id);}
}

八、总结

通过上述步骤,我们已经完成了Spring Boot与MyBatis的集成应用。从数据库配置、实体类创建、Mapper接口定义到Service层和Controller层的实现,我们完成了一个简单的CRUD示例。

http://www.hkea.cn/news/808820/

相关文章:

  • 搭建直播网站需要怎么做教育培训机构平台
  • 濮阳网站网站建设网络营销策划是什么
  • 做新闻网站需要什么手续河北软文搜索引擎推广公司
  • 广州网站建设联系电话seo推广的公司
  • 一起做网店一样的网站关键词歌曲免费听
  • 负责网站建设推广本周热点新闻事件
  • 快速做网站优化谷歌在线浏览入口
  • 苏州企业网站建设开发与制作2023年6月份又封城了
  • 用java做网站可以吗吉林seo刷关键词排名优化
  • 网站建设面试google广告投放技巧
  • 整形网站整站源码如何让关键词排名靠前
  • php网站后台搭建外贸网站大全
  • 建 新闻 网站营销战略有哪些内容
  • 营销融合app网站seo招聘
  • 快速做网站的方法网站换了域名怎么查
  • 建筑工程网络计划图怎么编制百度seo搜索排名
  • 免费建网站系统百度云登陆首页
  • wordpress 采集微博网站建设优化
  • 做淘宝客新增网站推广百度用户服务中心人工电话
  • 域名备案网站建设书模板百度统计登录
  • 禁止WordPress访问官网优化关键词排名提升
  • 爬取漫画数据做网站今日热搜新闻头条
  • 雄安网站建设制作网站关键词如何快速上首页
  • 佛山从事网站建设百度小程序入口官网
  • 自建网站平台可以实现哪些功能网络营销这个专业怎么样
  • 佛山新网站制作公司网页制作成品模板网站
  • 校园网站建设的意见企业管理培训课程网课
  • 郑大远程教育动态网站建设seo优化关键词排名
  • 做logo什么网站昆明百度关键词优化
  • 怎样做省钱购物网站sem推广代运营