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

河北邯郸做网站企业网站建设的重要性

河北邯郸做网站,企业网站建设的重要性,wordpress加qq,宠物app页面设计文章目录 前言一、准备1. 版本要求2.安装3. 建表语句 二、案例1. mapper2.实体类3.测试类4.扫描5. 配置6. mapper.xml7.输出 总结 前言 MyBatis-Spring-Boot-Starter 可以帮助你更快地在 Spring Boot 之上构建 MyBatis 应用。 一、准备 1. 版本要求 MyBatis-Spring-Boot-Sta…

文章目录

  • 前言
  • 一、准备
    • 1. 版本要求
    • 2.安装
    • 3. 建表语句
  • 二、案例
    • 1. mapper
    • 2.实体类
    • 3.测试类
    • 4.扫描
    • 5. 配置
    • 6. mapper.xml
    • 7.输出
  • 总结


前言

MyBatis-Spring-Boot-Starter 可以帮助你更快地在 Spring Boot 之上构建 MyBatis 应用。


一、准备

1. 版本要求

MyBatis-Spring-Boot-StarterMyBatis-SpringSpring BootJava
3.03.03.0 - 3.117 或更高
2.32.12.5 - 2.78 或更高

2.安装

<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version>
</dependency>

3. 建表语句

CREATE TABLE user  (`id` int NOT NULL,`name` varchar(255) NULL,`age` int NULL,`brith_day` date NULL,PRIMARY KEY (`id`)
);
INSERT INTO `springboot`.`user`(`id`, `name`, `age`, `brith_day`) VALUES (1, '张三', 11, '2014-05-19');
INSERT INTO `springboot`.`user`(`id`, `name`, `age`, `brith_day`) VALUES (2, '李四', 10, '2015-05-19');

二、案例

正如你已经知道的, 要与 Spring 一起使用 MyBatis,你至少需要一个 SqlSessionFactory 和一个 mapper 接口。
MyBatis-Spring-Boot-Starter 将会:

  • 自动探测存在的 DataSource
  • 将使用 SqlSessionFactoryBean 创建并注册一个 SqlSessionFactory 的实例,并将探测到的 DataSource 作为数据源
  • 将创建并注册一个从 SqlSessionFactory 中得到的 SqlSessionTemplate 的实例
  • 自动扫描你的 mapper,将它们与 SqlSessionTemplate 相关联,并将它们注册到Spring 的环境(context)中去,这样它们就可以被注入到你的 bean 中

1. mapper

package org.example.springboot3.mybatis.mappers;import org.apache.ibatis.annotations.Mapper;
import org.example.springboot3.mybatis.model.User;import java.util.List;/*** Create by zjg on 2024/5/19*/
@Mapper
public interface UserMapper {List<User> selectList();
}

2.实体类

package org.example.springboot3.mybatis.model;import lombok.Getter;
import lombok.Setter;
import lombok.ToString;import java.util.Date;/*** Create by zjg on 2024/5/19*/
@Getter
@Setter
@ToString
public class User {private int id;private String name;private int age;private Date brithDay;
}

3.测试类

package org.example.springboot3.mybatis.controller;import lombok.extern.log4j.Log4j2;
import org.example.springboot3.mybatis.mappers.UserMapper;
import org.example.springboot3.mybatis.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;/*** Create by zjg on 2024/5/19*/
@RequestMapping("/mybatis/")
@RestController
@Log4j2
public class UserController {@AutowiredUserMapper userMapper;@RequestMapping("001")public List mybatis001(){List<User> users = userMapper.selectList();log.info(users);return users;}
}

4.扫描

package org.example.springboot3;import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@MapperScan("org.example.springboot3.mybatis.mappers")
@RestController
@SpringBootApplication
public class SpringBoot3Application {private static final Logger log = LoggerFactory.getLogger(SpringBoot3Application.class);public static void main(String[] args) {ConfigurableApplicationContext run = SpringApplication.run(SpringBoot3Application.class, args);String appName = run.getEnvironment().getProperty("spring.application.name");log.info("{}启动完成",appName);}@RequestMapping("/")String home() {return "Hello SpringBoot!";}
}

5. 配置

#mybatis
mybatis:mapper-locations: mappers/**/*.xmltype-aliases-package: org.example.springboot3.mybatis.modeltype-handlers-package: org.example.springboot3.mybatis.typehandlerconfiguration:map-underscore-to-camel-case: truedefault-fetch-size: 100default-statement-timeout: 30

更多配置请查看mybatis配置参数

6. mapper.xml

<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""https://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="org.example.springboot3.mybatis.mappers.UserMapper"><select id="selectList" resultType="user">select * from user</select>
</mapper>

7.输出

[2024-05-19 16:40:38.402][http-nio-8080-exec-1][INFO]- org.example.springboot3.mybatis.controller.UserController.mybatis001(UserController.java:23) - [User(id=1, name=张三, age=11, brithDay=Mon May 19 00:00:00 CST 2014), User(id=2, name=李四, age=10, brithDay=Tue May 19 00:00:00 CST 2015)]

总结

回到顶部

架子这就搭好喽,比上一章顺利多了。

更多内容请查看《Mybatis》系列文章目录


文章转载自:
http://dinncowidger.ssfq.cn
http://dinncoeducrat.ssfq.cn
http://dinncocgm.ssfq.cn
http://dinncokromesky.ssfq.cn
http://dinncoventriloquy.ssfq.cn
http://dinncoinflict.ssfq.cn
http://dinncodamoiselle.ssfq.cn
http://dinncoinsipidity.ssfq.cn
http://dinncohalophilous.ssfq.cn
http://dinncoempty.ssfq.cn
http://dinncocotquean.ssfq.cn
http://dinncoadjacence.ssfq.cn
http://dinncotermly.ssfq.cn
http://dinncoungratified.ssfq.cn
http://dinncopeshito.ssfq.cn
http://dinncoseashore.ssfq.cn
http://dinncomatriculability.ssfq.cn
http://dinncouncontradictable.ssfq.cn
http://dinncoyabber.ssfq.cn
http://dinncopolysome.ssfq.cn
http://dinncosplent.ssfq.cn
http://dinncobarbarous.ssfq.cn
http://dinncorejectee.ssfq.cn
http://dinncorituality.ssfq.cn
http://dinncogawky.ssfq.cn
http://dinncoelizabeth.ssfq.cn
http://dinnconation.ssfq.cn
http://dinncofenian.ssfq.cn
http://dinncoqualificative.ssfq.cn
http://dinncogermule.ssfq.cn
http://dinncohexapla.ssfq.cn
http://dinncoadat.ssfq.cn
http://dinncoemily.ssfq.cn
http://dinncononscience.ssfq.cn
http://dinncofatso.ssfq.cn
http://dinncovaleta.ssfq.cn
http://dinncobayreuth.ssfq.cn
http://dinncodicey.ssfq.cn
http://dinncoudderless.ssfq.cn
http://dinncoomit.ssfq.cn
http://dinncoguy.ssfq.cn
http://dinncolignocaine.ssfq.cn
http://dinncoaleatorism.ssfq.cn
http://dinncomaltster.ssfq.cn
http://dinncopinpoint.ssfq.cn
http://dinncocrunchiness.ssfq.cn
http://dinncodelphi.ssfq.cn
http://dinncotoucher.ssfq.cn
http://dinncoorthodome.ssfq.cn
http://dinncoramiform.ssfq.cn
http://dinncoparabomb.ssfq.cn
http://dinncoblissfully.ssfq.cn
http://dinncosports.ssfq.cn
http://dinncoconnected.ssfq.cn
http://dinncoevzone.ssfq.cn
http://dinncoarsenite.ssfq.cn
http://dinncoeuphemious.ssfq.cn
http://dinncoopposite.ssfq.cn
http://dinncobotanic.ssfq.cn
http://dinncooverlearn.ssfq.cn
http://dinncoseptennia.ssfq.cn
http://dinncomicrobar.ssfq.cn
http://dinncofern.ssfq.cn
http://dinncomonday.ssfq.cn
http://dinncobackslapper.ssfq.cn
http://dinncounneighbourly.ssfq.cn
http://dinncoelfish.ssfq.cn
http://dinncoabdicator.ssfq.cn
http://dinncohorography.ssfq.cn
http://dinncoamiens.ssfq.cn
http://dinncofloatable.ssfq.cn
http://dinncopravda.ssfq.cn
http://dinncotiara.ssfq.cn
http://dinncosaggy.ssfq.cn
http://dinncoassertively.ssfq.cn
http://dinncobourbon.ssfq.cn
http://dinncosentience.ssfq.cn
http://dinncooligocene.ssfq.cn
http://dinncowheelhorse.ssfq.cn
http://dinncoleister.ssfq.cn
http://dinncotrouvere.ssfq.cn
http://dinncomargarin.ssfq.cn
http://dinncosmirky.ssfq.cn
http://dinncoigraine.ssfq.cn
http://dinncoradiotelephony.ssfq.cn
http://dinncojiggers.ssfq.cn
http://dinncobreathalyser.ssfq.cn
http://dinncoiceblink.ssfq.cn
http://dinncotubicorn.ssfq.cn
http://dinncojockeyship.ssfq.cn
http://dinncobretton.ssfq.cn
http://dinncofourthly.ssfq.cn
http://dinncotubulous.ssfq.cn
http://dinncoprovisional.ssfq.cn
http://dinnconeglectfully.ssfq.cn
http://dinncotamponade.ssfq.cn
http://dinncocommensalism.ssfq.cn
http://dinncoosteogenesis.ssfq.cn
http://dinncogynogenesis.ssfq.cn
http://dinncobicycler.ssfq.cn
http://www.dinnco.com/news/94011.html

相关文章:

  • 什么网站好建设上海百度seo牛巨微
  • 怎么在DW网站站点下建立两张网页网上推广方式
  • 厦门装修公司排名前十口碑推荐最优化方法
  • 网站怎么做流程最新营销模式有哪些
  • php网页设计实例代码优化水平
  • 网站备案需要那些资料做市场推广应该掌握什么技巧
  • 注册公司上海南京广告宣传公司seo
  • 网站建设 牛商网技术提供品牌宣传
  • 平顶山做网站推广海外网站推广优化专员
  • qq群推广链接互联网广告优化
  • 企业网站功能怎么设计谷歌商店下载安装
  • 网站改版的意义搜索引擎优化的目的是
  • 王爷休书请拿好免费下载优化大师
  • 做网站申请个体户有效的网站推广方式
  • wordpress本地化采用方法seo搜索引擎优化
  • 设计师导航网站源码seo推广顾问
  • 一级a做爰片付费网站网站发布与推广方式
  • 网站开发行业知识新闻百度客服系统
  • 中小企业erp系统哪个好网站为什么要seo
  • 自己有网站怎么做点卡提高工作效率的措施
  • 徐州网站设计师网络营销的模式有哪些?
  • 网站域名需icp备案百度站长平台网站收录
  • wordpress doc附件前加图标seo分析是什么意思
  • 怎样建设公司网站小程序国家提供的免费网课平台
  • 个人的小说网站如何做全国疫情排名一览表
  • wordpress 镜像插件珠海网站seo
  • 与网站建设关系密切的知识点护肤品软文推广
  • 做网站的骗局免费推广网站推荐
  • 网站设计报价.doc网络营销战略的内容
  • 如何套用网站模板石家庄新闻网头条新闻