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

微商可以做网站推广吗青岛建设工程信息网官网

微商可以做网站推广吗,青岛建设工程信息网官网,企业天眼查,中山移动网站建设多少钱文章目录 前言一、准备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://www.15wanjia.com/news/161648.html

相关文章:

  • 做路牌的网站网站开发中 登录不上了
  • 陕西有色建设有限公司官方网站视频特效制作软件
  • 网站做要钱沈阳网站建设建设公司哪家好
  • dede网站打不开html5的网站
  • 郑州专业建网站购物网站销售管理
  • 新建网站如何调试网站首页布局的设计
  • 本溪做网站网站域名空间
  • 网站建设推广实训总结qq群推广平台
  • 百度小说app下载外贸网站建设优化推广
  • 视频直播网站开发与制作免费网络推广的方法
  • 安徽理工大学新校区建设网站佛山市网络推广
  • 分销渠道南宁网站优化
  • 衡水网站建设浩森宇特临沂网站制作加速企业发展
  • 一个网站添加多个网址营销网站建设前期准备
  • 一个空间怎么做两个网站 跳转中小企业网站建设市场
  • 网站触屏版wordpress 用户密码加密
  • 网站推广平台怎么做网站友情链接要加什么
  • 番禺做网站的重庆网络公司网站建设
  • 成都营销类网站设计千库网登录入口
  • 建筑工程网站建设方案网站建设三网合一是什么
  • 超级网站模板下载网上做网站
  • 建站有哪些需求大学生简历模板
  • 温州哪里有网站优化wordpress写书typecho主题
  • 天津做网站制作内容分发网络CDN可以建设网站吗
  • 古典风格网站模版个人网站和企业网站
  • 360网站挂马检测html如何做网站
  • 哈尔滨网站优化咨询asp是网站开发吗
  • 重庆潼南网站建设报价智慧团建系统官方网站登录
  • 杭州滨江区建设局网站网站怎么做域名解析
  • yes风淘宝网站wordpress果酱