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

有哪几种语言做的网站百度排行榜风云榜

有哪几种语言做的网站,百度排行榜风云榜,国外优秀设计网站有哪些,如何在网站做投票😀前言 本篇博文关于Spring Boot 整合MyBatis,希望你能够喜欢 🏠个人主页:晨犀主页 🧑个人简介:大家好,我是晨犀,希望我的文章可以帮助到大家,您的满意是我的动力&#x…

😀前言
本篇博文关于Spring Boot 整合MyBatis,希望你能够喜欢

🏠个人主页:晨犀主页
🧑个人简介:大家好,我是晨犀,希望我的文章可以帮助到大家,您的满意是我的动力😉😉
💕欢迎大家:这里是CSDN,我总结知识的地方,欢迎来到我的博客,感谢大家的观看🥰
如果文章有什么需要改进的地方还请大佬不吝赐教 先在此感谢啦😊

文章目录

  • Spring Boot 整合MyBatis
    • 需求说明/图解
    • 综合案例
      • 代码+配置实现
      • 测试页面效果
      • 注意事项和细节说明

Spring Boot 整合MyBatis

需求说明/图解

  1. 将Spring Boot 和MyBatis 整合
  2. 查询出一条数据

综合案例

代码+配置实现

  1. 创建数据库和表
CREATE DATABASE `springboot_mybatis`
use `springboot_mybatis`
CREATE TABLE `monster` (
`id` INT NOT NULL AUTO_INCREMENT,
`age` INT NOT NULL,
`birthday` DATE DEFAULT NULL,
`email` VARCHAR(255) DEFAULT NULL,
韩顺平Java 工程师
`gender` char(1) DEFAULT NULL,
`name` VARCHAR(255) DEFAULT NULL,
`salary` DOUBLE NOT NULL,
PRIMARY KEY (`id`)
) CHARSET=utf8
SELECT * FROM `monster`
insert into monster values(null, 20, '2000-11-11', 'nmw@sohu.com', '男', '牛魔王', 5000.88);
insert into monster values(null, 10, '2011-11-11', 'bgj@sohu.com', '女', '白骨精', 8000.88);
insert into monster values(null, 20, '2020-11-11', 'xhy@sohu.com', '男', '小虎牙', 3000.88);
insert into monster values(null, 18, '2001-06-18', 'xhy@sohu.com', '女', '小狐妖', 8888.88);
  1. 创建springboot_mybatis 项目-创建maven

    pom.xml 需要引入相关依赖.

    <!--引入相关的依赖--><dependencies><!--引入web starter--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--引入mybatis starter, 如果看不到版本,自己手写2.2.2--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.2</version></dependency><!--引入mysql驱动: 这里使用版本仲裁 8.0.26--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!--引入配置处理器 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></dependency><!--引入lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><!--引入test starter--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><!--引入druid依赖--><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.17</version></dependency></dependencies>
  1. 创建resources/application.yml , 配置数据源参数, 并完成Spring Boot 项目启动测试
server:port: 9090
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/springboot_mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8username: rootpassword: 123456
  1. 切换数据源为druid , 修改pom.xml(如果没有mybatis-stater , 加入即可.) , 并加入配置文件com/my/mybatis/config/DruidDataSourceConfig.java , 完成测试
 <!--引入druid依赖--><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.17</version></dependency>

配置文件com/my/mybatis/config/DruidDataSourceConfig.java

@Configuration
public class DruidDataSourceConfig {@ConfigurationProperties("spring.datasource")@Beanpublic DataSource dataSource() throws SQLException {DruidDataSource druidDataSource =new DruidDataSource();return druidDataSource;}
}
  1. 创建com/my/mybatis/bean/Monster.java
@Data
public class Monster {private Integer id;private Integer age;//这里通过注解来解决时区问题//GMT 就是格林尼治标准时间@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")private Date birthday;private String email;private String name;private String gender;private Double salary;
}
  1. 创建com/my/mybatis/mapper/MonsterMapper.java
//在Mapper接口使用 @Mapper 就会扫描,并将Mapper接口对象注入
@Mapper
public interface MonsterMapper {//方法,根据id返回Monster对象public Monster getMonsterById(Integer id);
}
  1. 创建springboot_mybatis\src\main\resources\mapper\MonsterMapper.xml , 文件模板从mybatis 官方文档拷贝
<?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.my.springboot.mybatis.mapper.MonsterMapper"><!--配置getMonsterById--><select id="getMonsterById" resultType="com.my.mybatis.bean.Monster">SELECT * FROM `monster` WHERE id=#{id}</select>
</mapper>

8.创建com/my/mybatis/service/MonsterService.java

public interface MonsterService {//根据id返回Monster对象public Monster getMonsterById(Integer id);
}

创建com/my/mybatis/service/impl/MonsterServiceImpl.java

@Service
public class MonsterServiceImpl implements MonsterService {//装配MonsterMapper@Resourceprivate MonsterMapper monsterMapper;@Overridepublic Monster getMonsterById(Integer id) {return monsterMapper.getMonsterById(id);}
}
  1. 创建com/my/mybatis/controller/MonsterController.java
@Controller
public class MonsterController {//装配MonsterService@Resourceprivate MonsterService monsterService;@ResponseBody@GetMapping("/monster")public Monster getMonsterById(@RequestParam(value = "id") Integer id){return monsterService.getMonsterById(id);}
}
  1. 修改resources/application.yml , 指定mybatis 的配置参数
server:port: 10000
spring:datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/springboot_mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8username: rootpassword: 123456mybatis:#指定要扫描的 Xxxmapper.xmlmapper-locations: classpath:mapper/*.xml#通过config-location 可以指定mybatis-config.xml,可以以传统的方式来配置mybatis#config-location: classpath:mybatis-config.xml#我们也可以直接在application.yml进行配置#举例说明1. 比如配置原来的 typeAliases#举例说明2 配置输出底层的原生sqltype-aliases-package: com.my.springboot.mybatis.beanconfiguration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl#配置mybatis的两种方式的选择: 如果配置比较简单,就直接在application.yml配置即可#如果配置内容比较多,可以考虑单独的做一个mybatis-config.xml

测试页面效果

完成测试, 浏览器: http://localhost:10000/monster?id=1

image-20230820114440022

注意事项和细节说明

  1. spring boot 整合mybatis 取出的日期, 出现8 小时时差解决方案
    image-20230820115218984
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")

😁热门专栏推荐
Thymeleaf快速入门及其注意事项

Spring Initailizr–快速入门–SpringBoot的选择

带你了解SpringBoot支持的复杂参数–自定义对象参数-自动封装

Rest 优雅的url请求处理风格及注意事项

文章到这里就结束了,如果有什么疑问的地方请指出,诸大佬们一起来评论区一起讨论😁
希望能和诸大佬们一起努力,今后我们一起观看感谢您的阅读🍻
如果帮助到您不妨3连支持一下,创造不易您们的支持是我的动力🤞


文章转载自:
http://dinncofoppery.ssfq.cn
http://dinncomaritage.ssfq.cn
http://dinncorhizobium.ssfq.cn
http://dinncomeshugaas.ssfq.cn
http://dinncoeuploidy.ssfq.cn
http://dinncoscoliosis.ssfq.cn
http://dinncoperpetuation.ssfq.cn
http://dinncoendue.ssfq.cn
http://dinncounparallel.ssfq.cn
http://dinncofellah.ssfq.cn
http://dinncofrippet.ssfq.cn
http://dinncoeluviate.ssfq.cn
http://dinncopasskey.ssfq.cn
http://dinncocayuga.ssfq.cn
http://dinncoelectrodelic.ssfq.cn
http://dinncosubpoena.ssfq.cn
http://dinncobellicose.ssfq.cn
http://dinncolaudability.ssfq.cn
http://dinncowalkdown.ssfq.cn
http://dinncoexplicative.ssfq.cn
http://dinncoagaze.ssfq.cn
http://dinncotabour.ssfq.cn
http://dinncodeflorate.ssfq.cn
http://dinncorondeau.ssfq.cn
http://dinncopoohed.ssfq.cn
http://dinncodemophobic.ssfq.cn
http://dinncoterrorization.ssfq.cn
http://dinncophotonuclear.ssfq.cn
http://dinncoreputation.ssfq.cn
http://dinncoonyxis.ssfq.cn
http://dinncoopalescence.ssfq.cn
http://dinncononcredit.ssfq.cn
http://dinncosubjugation.ssfq.cn
http://dinncoiaru.ssfq.cn
http://dinncosphygmus.ssfq.cn
http://dinncooccultist.ssfq.cn
http://dinncoorgulous.ssfq.cn
http://dinncounderlap.ssfq.cn
http://dinncounregarded.ssfq.cn
http://dinncopropagation.ssfq.cn
http://dinncomagnitogorsk.ssfq.cn
http://dinncoindoctrination.ssfq.cn
http://dinncojaques.ssfq.cn
http://dinncobenzpyrene.ssfq.cn
http://dinncostalactiform.ssfq.cn
http://dinncoutriculitis.ssfq.cn
http://dinncoglister.ssfq.cn
http://dinnconeurosensory.ssfq.cn
http://dinncostencil.ssfq.cn
http://dinncotaenicide.ssfq.cn
http://dinncocosset.ssfq.cn
http://dinncocentury.ssfq.cn
http://dinncofaltboat.ssfq.cn
http://dinncoslugging.ssfq.cn
http://dinncorecoup.ssfq.cn
http://dinncomyosotis.ssfq.cn
http://dinncotreacherously.ssfq.cn
http://dinncounderemployment.ssfq.cn
http://dinncowdp.ssfq.cn
http://dinncocantrail.ssfq.cn
http://dinncoquirt.ssfq.cn
http://dinncoextrapolation.ssfq.cn
http://dinncopaner.ssfq.cn
http://dinnconameable.ssfq.cn
http://dinncoliprouge.ssfq.cn
http://dinncoastropologist.ssfq.cn
http://dinncoporphobilinogen.ssfq.cn
http://dinncosolicitor.ssfq.cn
http://dinncoahorse.ssfq.cn
http://dinncoamputation.ssfq.cn
http://dinnconin.ssfq.cn
http://dinncopredestine.ssfq.cn
http://dinncoharuspex.ssfq.cn
http://dinncoinsalivation.ssfq.cn
http://dinncotsunami.ssfq.cn
http://dinncoosculate.ssfq.cn
http://dinncocategory.ssfq.cn
http://dinncoprivation.ssfq.cn
http://dinncoequiform.ssfq.cn
http://dinncointently.ssfq.cn
http://dinncopredawn.ssfq.cn
http://dinncodonau.ssfq.cn
http://dinncoprix.ssfq.cn
http://dinncolaudative.ssfq.cn
http://dinncosapor.ssfq.cn
http://dinncoillusionist.ssfq.cn
http://dinncodangerous.ssfq.cn
http://dinncostarboard.ssfq.cn
http://dinncoexumbrella.ssfq.cn
http://dinncoionomer.ssfq.cn
http://dinncoshabbily.ssfq.cn
http://dinncosulfane.ssfq.cn
http://dinncopullet.ssfq.cn
http://dinncomandate.ssfq.cn
http://dinnconatasha.ssfq.cn
http://dinncooutsung.ssfq.cn
http://dinncotiling.ssfq.cn
http://dinncolaying.ssfq.cn
http://dinncoarmchair.ssfq.cn
http://dinncoguardship.ssfq.cn
http://www.dinnco.com/news/90036.html

相关文章:

  • 网站自适应怎么做国内免费b2b网站大全
  • 墨刀做的网站设计湘潭网站建设
  • 仪征做网站360开户
  • 做电影网站有什么好处刷seo排名
  • 网站建设教案谷歌seo外包
  • php做各种网站类型得模板网络营销专业介绍
  • 济南哪家网站技术比较高中央人民政府
  • 网站开发怎样验收搜外友链平台
  • 做贸易 公司网站放哪里商家怎么入驻百度
  • 做网站要会写什么软件目前最新的营销方式有哪些
  • 电子商务网站建设可用性五个方面网站监测
  • 科技公司建设网站公司公司网站页面设计
  • 宣传设计网站怎样创建网站或者网址
  • 上海网站设计联系方式哪些店铺适合交换友情链接
  • 响应式网站什么意思网站域名查询ip
  • 浙江短视频seo优化网站网站建设公司排行榜
  • 南京制作网站速成班网站推广计划方法
  • 未来做哪些网站致富免费网站推广工具
  • 外包公司做网站怎么样必应站长平台
  • 可以做pos机的网站seo和sem是什么
  • 网站维护中seo关键词排行优化教程
  • 网站建设用什么工具2024年新闻摘抄十条
  • 网站网页设计在哪找自媒体引流推广
  • 旅游网站 建设平台分析seo网站有哪些
  • 网站开发经典什么是信息流广告
  • 网络平台不能将盈利模式不明朗鄂尔多斯seo
  • 网站建设三个阶段精准营销的概念
  • 做后期从哪个网站选音乐平原县网站seo优化排名
  • 网站建设潍坊重庆网站关键词排名优化
  • 前沿的设计网站2022新闻热点事件简短30条