mybatis3简单入门 - 1

1.Mybatis入门 Mybatis入门+jdbc了解+数据库连接池(共享单车)+lombok(简化java开发) 阅读详情
  1. 使用到的mysql语句;
  2. mybatis 日志配置;
  3. mybatis CRUD简单操作

1. 使用到的mysql语句

本次我们使用的是mysql数据库进行mybatis简单的crud操作,对于mysql的操作,我们自然可以使用Navicat进行图形化的操作,这里给出我用到的语句;

Mysql 数据类型:支持多种类型,大致可以分为三类:数值、日期/时间和字符串(字符)类型。具体可以参考:

Mysql数据类型:菜鸟教程-Mysql数据类型

--建库
CREATE DATABASE test;
--建表
CREATE TABLE IF NOT EXISTS student(
   stu_id INT AUTO_INCREMENT,
   stu_name VARCHAR(20) NOT NULL,
   stu_age int,
   stu_score double,
   PRIMARY KEY ( stu_id )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
--可能会遇到的语句
--修改字段属性
ALTER TABLE student CHANGE stu_name VARCHAR(30);
--增加字段名称
ALTER TABLE student ADD COLUMN class_id int(4);
--字段重命名
ALTER TABLE student CHANGE score stu_score DOUBLE NOT NULL;

注解:

AUTO_INCREMENT : 每一个表只能由一个AUTO_INCREMENT列, 告知Mysql本列每当增加一行时,自动增量。从而该列可以作为主键值。如果一列被指定为AUTO_INCREMENT,如果我们使用INSERT语句插入了一个新值(唯一的),那么下一次增量就在这个值的基础上进行递增;

常见的Mysql引擎: mysql的引擎在我们对表进行操作时,都是通过mysql的引擎来完成的,常见的mysql引擎:

InnoDB: 事务处理引擎,不支持全文本搜索;

MyISAM:性能较高的引擎,支持全文本搜索,但是不支持事物;

MEMORY: 功能等同于MyISAM,但是由于数据库存储在内存(不是磁盘中)速度较快;


2. Mybatis 日志配置

2.1 首先我们回顾下java主流的日志框架:本文采用:common-logging + log4j

Java 日志框架:细说JAVA主流的日志工具库

2.2 Mybatis 的内置日志工厂提供日志功能,内置日志工厂将日志交给以下其中一种工具作代理:

  • SLF4J
  • Apache Commons Logging
  • Log4j 2
  • Log4j
  • JDK logging

MyBatis 内置日志工厂基于运行时自省机制选择合适的日志工具。它会使用第一个查找得到的工具(按上文列举的顺序查找)。如果一个都未找到,日志功能就会被禁用。

如果想使用其它日志工具,你可以通过在 MyBatis 配置文件 mybatis-config.xml 里面添加一项 setting 来选择别的日志工具。

<configuration>
  <settings>
    ...
    <setting name="logImpl" value="LOG4J"/>
    ...
  </settings>
</configuration>

logImpl 可选的值有:SLF4J、LOG4J、LOG4J2、JDK_LOGGING、COMMONS_LOGGING、STDOUT_LOGGING、NO_LOGGING

2.3 根据自己的mapper.xml映射文件中的命名空间值来配置mybatis日志

mapper.xml

<mapper namespace="com.mybatis3.dao.mapper">
  <select id="selectStudent" resultType="com.mybatis3.model.Student">
    select * from student where id = #{id}
  </select>
</mapper>

log4j.properties文件:

# 全局日志配置
log4j.rootLogger=ERROR, stdout

# MyBatis 日志配置...
log4j.logger.com.mybatis3.dao.mapper=TRACE

# 控制台输出...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n


3. Mybatis简单的CRUD操作


3.1 数据库表结构:


3.2 项目结构:

项目代码展示:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.qian</groupId>
  <artifactId>mybatis</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mybatis</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
	    <groupId>junit</groupId>
	    <artifactId>junit</artifactId>
	    <version>4.12</version>
	    <scope>test</scope>
	</dependency>
	
	<dependency>
	    <groupId>org.mybatis</groupId>
	    <artifactId>mybatis</artifactId>
	    <version>3.4.6</version>
	</dependency>
	
	<dependency>
	    <groupId>mysql</groupId>
	    <artifactId>mysql-connector-java</artifactId>
	    <version>8.0.11</version>
	</dependency>
	
	<!-- <dependency>
      	<groupId>org.slf4j</groupId>
      	<artifactId>slf4j-api</artifactId>
      	<version>1.7.5</version>
    </dependency>

    <dependency>
	      <groupId>org.slf4j</groupId>
	      <artifactId>slf4j-log4j12</artifactId>
	      <version>1.7.12</version>
    </dependency> -->
	<dependency>
	  <groupId>commons-logging</groupId>
	  <artifactId>commons-logging</artifactId>
	  <version>1.2</version>
	</dependency>
    <dependency>
	      <groupId>log4j</groupId>
	      <artifactId>log4j</artifactId>
	      <version>1.2.17</version>
	</dependency>
  </dependencies>
</project>

model层

Student就是一个简单的JAVA BEAN对象,只是增加了几个简单的构造方法和重写了toString()方法;

dao层以及mapper.xml文件

IStudentDao.java

public interface IStudentDao {
	//增
	public int insertStudent(Student student);
	//删
	public boolean deleteStudentById(int id);
	//改
	public boolean updateStudent(Student student);
	//查
	public Student selectStudentById(int id);
	public List<Student> selectAllStudents();
	public List<Student> selectStudentByName(String name);
	public Map<String, Student> selectStudentToMap(String mapKey);
	public List<Student> selectAllStudentsByConditions(String name,int ageStart, int ageEnd);
}

StudentMapper.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.mybatis3.dao.mapper">
	<!-- 解决字段冲突问题:主要是针对由返回结果的也就是insert语句 -->
	<!-- 解决方式1: 使用别名 select stu_name name, -->
	<!-- 解决方式2: restultMap查询结果行的映射处理:字段和属性不一致问题
		数据库表student(stu_id,stu_name,stu_age,score)
		javabean中的student[id, name, age, score] -->
	<resultMap type="com.mybatis3.model.Student" id="studentResultMapper">
		<id column="stu_id" property="id"/>
		<result column="stu_name" property="name"/>
		<result column="stu_age" property="age"/>
	</resultMap>
	
	<insert id="insertStudent" parameterType="com.mybatis3.model.Student">
		insert into student(stu_name,stu_age,score)
		values(#{name},#{age},#{score}) 
                <!--返回刚插入的这条记录的id-->
		<selectKey keyProperty="id" resultType="int">
			select @@identity
			<!-- select last_insert_id(); -->
		</selectKey>
	</insert>
	
	<delete id="deleteStudentById">
		<!-- 此处#{id}仅仅是一个占位符 -->
		delete from student where stu_id = #{id};
	</delete>
	
	<update id="updateStudent" parameterType="com.mybatis3.model.Student">
		update student set stu_name=#{name}, stu_age=#{age}, score=#{score} 
		where stu_id=#{id}
	</update>
	
	<!-- resultType将 id name age score自动转成Student
		并非指最终结果集的类型而是指将查询出来DB中的每一条记录的字段封装成的类型 -->
	<select id="selectStudentById" resultType="com.mybatis3.model.Student">
		<!-- 使用别名解决字段冲突问题 -->
		select stu_id id, stu_name name, stu_age age, score from student where stu_id=#{id};
	</select>
        
        <select id="selectAllStudents" resultType="com.mybatis3.model.Student" resultMap="studentResultMapper">
		select stu_id, stu_name, stu_age, score from student
	</select>
	
        <!-- 模糊查询字符串拼接问题 -->
	<select id="selectStudentByName" resultType="com.mybatis3.model.Student" resultMap="studentResultMapper">
		<!-- #{xxx}为占位符:mybatis会进行动态拼接,使用的是PreparedStatement的setParameter来设置参数 -->
		select stu_id, stu_name, stu_age, score from student where stu_name like '%' #{name} '%'
		<!-- 为第一种的正式写法 -->
		<!-- select id, name, age, score from student where name like concat('%' #{name} '%') -->
		<!-- ${value}为字符串拼接:mybatis会进行硬编码拼接,使用的是Statement: sql注入,没有预编译效率低下 只能是value -->
		<!-- select id, name, age, score from student where name like '%${value}%' -->
	</select>
	<select id="selectStudentToMap" resultType="com.mybatis3.model.Student" resultMap="studentResultMapper">
		select stu_id, stu_name, stu_age, score from student
	</select>
	
	<!-- 传递多个参数,#{参数map的key} -->
	<select id="selectAllStudentsByConditions" resultType="com.mybatis3.model.Student" resultMap="studentResultMapper">
		select stu_id, stu_name, stu_age, score 
		from student 
		where stu_name like '%' #{name} '%' 
		and stu_age between #{ageStart} and #{ageEnd}
	</select>
	
</mapper>
mybatis3.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
	
	
	<!-- 注册属性文件位置和 属性的值 -->	
        <!--  在 properties 元素体内<properties>指定的属性首先被读取。
             然后根据 properties 元素中的 resource 属性读取类路径下属性文件或根据 url 属性指定的路径读取属性文件,并覆盖已读取的同名属性。
   	 最后读取作为方法参数传递的属性,并覆盖已读取的同名属性。
	因此,通过方法参数传递的属性具有最高优先级,resource/url 属性中指定的配置文件次之,最低优先级的是 properties 属性中指定的属性。 -->
	
	<properties resource="db-mysql/mysql.properties">
		<!-- 开启为占位符指定一个默认值特性和三元排队特性 -->
		<property name="org.apache.ibatis.parsing.PropertyParser.enable-default-value" value="true"/>	
		<!-- 过 properties 元素的子元素来传递 -->
		<property name="dbname" value="test"/>
	</properties>
	
	<settings>
		<setting name="logImpl" value="LOG4J"/>
	</settings>
	
	<environments default="jdbc">
		<environment id="jdbc">
			<!-- Mybatis支持两种事物:JDBC MANAGED(使用容器来管理事物例如spring) -->
			<transactionManager type="JDBC"/>		
			<dataSource type="POOLED">
				<property name="driver" value="${jdbc.driver}"/>
				<!-- 使用properties中指定的属性值,优先权最低 -->
				<property name="url" value="${jdbc.url}${dbname}"/>
				<property name="username" value="${jdbc.username}"/>
				<property name="password" value="${jdbc.password}"/>
			</dataSource>
		</environment>
	</environments>
	
	<!-- 注册映射文件位置 MyBatis到哪里去找到这些定义 SQL 映射语句 -->
	<mappers>
		<!-- RESOURCE: 使用相对于类路径的资源引用 -->
		<mapper resource="com/mybatis3/dao/StudentMapper.xml"/>
		
		<!-- URL: 使用完全限定资源定位符(URL)
		<mapper url="file:///var/mappers/StudentMappper.xml"/>
		
		CLASS: 值为dao接口的全名:需要满足如下三个条件
		(1) 映射文件的名字和dao层接口的名字一样 也就是映射文件名字为IStudentDao.xml;
		(2) 映射文件放到dao层包下
		(3) 在映射文件下<mapper namespace="com.mybatis3.dao.IStudent">
		<mapper class="com.mybatis3.dao.IStudentDao"/>
		
		PACKAGE:将包内的映射器接口实现全部注册为映射器
		<package name="com.mybatis3.dao"/>
		-->
	</mappers>
</configuration>

SqlSessionUtil.java

主要是用于获取SqlSession和关闭SqlSession

package com.mybatis3.dao.utils;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlSessionUtil {
	// 线程安全 的 重量级对象,与数据库一一对应,所以一个应用由一个对象就可以,
	private static SqlSessionFactory sqlSessionFactory = null;
	/*SqlSession对象是对应于数据库的一次会话,一次会话以sqlsession创建开始,以close关闭;
	 *SqlSession对应于一次会话,所以它是线程不安全的,所以用时创建,用完马上关闭,关闭时它会检测事物是否
	 *提交,如果提交就直接关闭,如果没有提交就会回归 
	*/
	
	static{
		//获取sqlSession: 读取配置文件--> SqlSessionFactoryBuilder -> sqlSessionFactory -> sqlSession
		String resource = "mybatis3.xml";
		InputStream inputstream;
		SqlSessionFactoryBuilder sqlSessionFactoryBuilder =null;
		try {
			inputstream = Resources.getResourceAsStream(resource);
			sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
			sqlSessionFactory = sqlSessionFactoryBuilder.build(inputstream);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			//builder主要是用来创建Factory对象,只要创建完factory对象它就可以销毁,所以可以将它放到一个方法内;
			if(sqlSessionFactoryBuilder!=null){
				sqlSessionFactoryBuilder = null;
			}
		}		
	}
	
	public static SqlSession getSqlSession(){
		if(sqlSessionFactory!=null){
			return sqlSessionFactory.openSession();			
		}
		return null;
	}
	
	public static SqlSession getSqlSession(boolean autoCommit){
		if(sqlSessionFactory!=null){
			return sqlSessionFactory.openSession(autoCommit);			
		}
		return null;
	}
	
	public static void closeSqlSession(SqlSession sqlSession){
		if(sqlSession!= null){
			sqlSession.close();
		}
	}
}

StudentDao.java

package com.mybatis3.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import com.mybatis3.dao.utils.SqlSessionUtil;
import com.mybatis3.model.Student;

public class StudentDao implements IStudentDao {

	private SqlSession sqlSession = null;
	
	public int insertStudent(Student student) {
		try{
			sqlSession = SqlSessionUtil.getSqlSession();
			sqlSession.insert("insertStudent",student);
			sqlSession.commit();
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}
		return student.getId();
	}

	public boolean deleteStudentById(int id) {
		try{
			sqlSession = SqlSessionUtil.getSqlSession();
			int resultCol = sqlSession.delete("deleteStudentById", id);
			sqlSession.commit();
			if(resultCol > 0){
				return true;
			}
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}
		return false;
	}

	public boolean updateStudent(Student student) {
		try{
			sqlSession = SqlSessionUtil.getSqlSession();
			int resultCol = sqlSession.update("updateStudent", student);
			sqlSession.commit();
			if(resultCol > 0){
				return true;
			}
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}
		return false;
	}

	public Student selectStudentById(int id) {
		try{
			sqlSession = SqlSessionUtil.getSqlSession();
			Student student = sqlSession.selectOne("selectStudentById", id);
			return student;
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}
	}

	public List<Student> selectAllStudents() {
		try{
			sqlSession = SqlSessionUtil.getSqlSession();
			return sqlSession.selectList("selectAllStudents");
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}		
	}

	public List<Student> selectStudentByName(String name) {
		try{
			sqlSession = SqlSessionUtil.getSqlSession();
			return sqlSession.selectList("selectStudentByName", name);
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}
	}
	/**
	 * @param mapKey: 查询出的map所需要使用的key,这个key为数据库的字段名,也是最终每条map记录的key值
	 * 				      若数据库中mapKey的值不唯一,后面的结果会把前面的结果覆盖掉;
	 */
	public Map<String, Student> selectStudentToMap(String mapKey) {
		try{
			sqlSession = SqlSessionUtil.getSqlSession();
			return sqlSession.selectMap("selectStudentToMap", mapKey);
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}
	}

	public List<Student> selectAllStudentsByConditions(String name, int ageStart, int ageEnd) {
		try{
			//sqlSession.listXXX方法中没有传入一个数组的方法,所有只能封装成集合
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("name", name);
			paramMap.put("ageStart", ageStart);
			paramMap.put("ageEnd", ageEnd);
			sqlSession = SqlSessionUtil.getSqlSession();
			return sqlSession.selectList("selectAllStudentsByConditions",paramMap);
		}finally{
			SqlSessionUtil.closeSqlSession(sqlSession);						
		}
	}

}

StudentService.java

serviec层,调用dao层的代码

package com.mybatis3.service;

import java.util.List;
import java.util.Map;

import com.mybatis3.dao.IStudentDao;
import com.mybatis3.model.Student;

public class StudentService implements IStudentService {
	private IStudentDao studentDao;
	
	public int addStudent(Student student) {
		return studentDao.insertStudent(student);
	}

	public boolean removeStudentById(int id){
		return studentDao.deleteStudentById(id);
	}
	
	//改
	public boolean modifyStudent(Student student){
		return studentDao.updateStudent(student);
	}
	//查
	public Student findStudentById(int id){
		return studentDao.selectStudentById(id);
	}
	
	public List<Student> findAllStudents(){
		return studentDao.selectAllStudents();
	}
	
	public List<Student> findStudentByName(String name){
		return studentDao.selectStudentByName(name);
	}
	
	public Map<String, Student> findStudentToMap(String mapKey){
		return studentDao.selectStudentToMap(mapKey);
	}
		
	public IStudentDao getStudentDao() {
		return studentDao;
	}
	
	public void setStudentDao(IStudentDao studentDao) {
		this.studentDao = studentDao;
	}

	public List<Student> findAllStudents(String name, int ageStart, int ageEnd) {
		return studentDao.selectAllStudentsByConditions(name, ageStart, ageEnd);
	}
}

StudentTest.java

测试类

package com.qian.mybatis;

import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

import com.mybatis3.dao.StudentDao;
import com.mybatis3.model.Student;
import com.mybatis3.service.StudentService;

public class StudentTest {
	
	private StudentService studentService=null;
	
	@Before
	public void before(){
		studentService = new StudentService();
		studentService.setStudentDao(new StudentDao());		
	}
	
	@Test
	public void testInsert(){
		Student student = new Student();
		student.setName("张三");
		student.setAge(27);
		student.setScore(95.5);
		int id = studentService.addStudent(student);
		System.out.println("id = "+id);
	}
	
	@Test
	public void testDelete(){
		boolean result = studentService.removeStudentById(6);
		System.out.println(result);
	}
	
	@Test
	public void testUpdate(){
		Student student = new Student("LISI",23,99.9);
		student.setId(11);
		boolean result = studentService.modifyStudent(student);
		System.out.println(result);
	}
	
	@Test
	public void testFindStudentById(){
		Student student = studentService.findStudentById(11);
		System.out.println(student);
	}
	@Test
	public void testFindAllStudents(){
		List<Student> students = studentService.findAllStudents();
		System.out.println(students);
	}
	
	@Test
	public void testFindStudentByName(){
		List<Student> students = studentService.findStudentByName("李四");
		System.out.println(students);
	}
	
	@Test
	public void testFindStudentToMap(){
		Map<String,Student> students = studentService.findStudentToMap("name");
		System.out.println(students);
	}
	
	@Test
	public void testFindAllStudents2(){
		List<Student> students = studentService.findAllStudents("张三", 22, 35);
		System.out.println(students);
	}
}

参考文献:

【1】:mybatis3官网参考文档

【2】:bjpowernodeMybatis教程

























Mybatis Plus 3.0 快速入门 (简称 MP)是一个MyBatis的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。 阅读详情

相关推荐

如何评估一颗 AI 芯片的真实性能?TOPS、FPS 与 Token/sec 全解析

AI 芯片在实际部署中,其理论峰值性能往往无法反映真实执行效率。如何科学评估一颗 AI 芯片的“真实性能”,已成为芯片选型与系统集成环节中的关键技术问题。本文从工程实战角度出发,深入拆解当前常用性能评估指标(TOPS、FPS、Token/sec)背后的定义逻辑与使用陷阱,并结合推理模型部署与执行路径,系统讲解 AI 芯片在不同场景下的性能验证方法。通过对芯片算力-功耗-调度三维关系的分析,读者将掌握评估一颗 AI 芯片是否“跑得动业务”的核心判断能力。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 3434

MyBatis3——入门介绍

MyBatis——入门介绍

代码星辰的博客 2036

PX4|Gazebo模型加载失败排查指南:从环境变量到资源路径的全面解析

本文针对PX4与Gazebo联合仿真中常见的'Unable to get model name'错误,提供了从环境变量配置、资源路径排查到网络访问问题的全面解决方案。详细解析了GZ_SIM_RESOURCE_PATH等关键变量的作用与设置方法,并给出了离线模型库部署等一劳永逸的修复指南,帮助开发者彻底解决无人机模型加载失败问题。

weixin_29243063的博客 1238

Mybatis3详解 之 MyBatis 基础

MyBatis本是Apache的一个开源项目iBatis,2010年这个项目由Apache Software Foundation迁移到了Google Code,并且改名为MyBatis,也就是从3.0版本开始 iBatis改名为MyBatis。

IT小郭的技术博客 1337

单细胞测序流程(八)单细胞的marker基因转化和​GO富集分析

系列文章目录 单细胞测序流程(一)简介与数据下载 单细胞测序流程(二)数据整理 单细胞测序流程(三)质控和数据过滤——Seurat包分析,小提琴图和基因离差散点图 单细胞测序流程(四)主成分分析——PCA 单细胞测序流程(五)t-sne聚类分析和寻找marker基因 单细胞测序流程(六)单细胞的细胞类型的注释 单细胞测序流程(七)单细胞的细胞类型轨迹分析———————————————— 本期主讲内容——单细胞的maeker基因转化和​富集分析 marker基因转化是为了将基因的id和基.

qq_45478665的博客 1万+

使用vcpkg快速安装opencascade并自动配置部署开发环境

广泛的开源库:vcpkg 提供了上千个流行的 C++ 开源库,用户可以通过简单的命令安装和集成这些库,包括 Boost、OpenCV、SQLite、fmt 等。确保包版本一致性:通过 vcpkg.json 文件,开发者可以指定依赖的库版本,确保项目在不同环境下的构建结果一致,避免由于依赖库版本不一致而导致的构建问题。强大的社区支持:Vcpkg 是开源项目,拥有活跃的社区和微软团队的支持,提供了稳定的更新和问题修复。快速更新:Vcpkg 社区活跃,库的更新速度较快,开发者可以迅速获得库的最新版本。

loujiand的博客 2299

Mybatis3 快速入门

摘录百度百科的内容:MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录如果 Hibernate 是自动化持久层框架,那么 Mybatis 就是半自动化持久层框架。半自动???听起来好像 lower 了。

qq_43505188的博客 435

RFSoC应用XCZU47DR八发八收FPGA设计方案

本文介绍了基于Xilinx XCZU47DR RFSoC芯片的八发八收FPGA设计方案。该方案采用集成射频数据转换器的SoC架构,支持8路14bit ADC(5GSPS)和8路14bit DAC(9.85GSPS),可直接处理5GHz以下射频信号。硬件设计包含高性能输入缓冲器、QMC校正和复杂混频器,适用于5G/6G通信、雷达、卫星通信等领域。文章详细阐述了ADC/DAC子系统参数,包括通道配置、采样率、带宽等特性,并提供了FPGA顶层模块的硬件接口设计,展示了多通道数据收发处理能力。该方案无需外置混频器,

toonyhe的博客 1827

Mybatis3全面详解

Mybatis3 1. MyBatis的介绍 (1) MyBatis的历史 原是Apache的一个开源项目,iBatis,2010年6月这个项目由Apache Software Foundation 迁移到了 Goodle Code,随着开发团队转投Google code旗下,iBatis3.X正式更名为MyBatis,代码于2013年11月迁移到Github。 iBatis 一词 来源于 internet 和 abatis的组合。是一个基于Java的持久层框架。iBatis提供的持久层框架包括Sql M

想看什么文章都可以私信给我,综合性博客。 3197

后台管理系统-7-vue3之引入配置文件baseURL

mock=false,本地模拟。mock=true,线上模拟。baseURL+url=实际请求的URL。get请求param参数,post请求data参数。

qq_20466211的博客 216

uniapp 如何封装实现任意页面都能使用的全局弹窗

项目内容场景全局监听消息提示难点uniapp 无法全局挂载组件解决方案动态创建 DOM + 动态 Vue 实例优势跨页面 / 不依赖页面组件树 / 灵活调用如果你使用的是小程序平台,DOM 操作可能受限,需要用或方式兼容处理。想支持多个弹窗堆叠?你可以扩展,加个弹窗队列管理器。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 956

MyBatis_3

MyBatis_3 一、MyBatis相关的配置文件 1.1.MyBatis的核心配置文件 1.1.1.名称–我们可以自己定义,推荐大家使用【mybatis-config.xml】 1.1.2.位置 IntelliJ IDEA中通过Maven创建项目,一般都保存在src/main/resources目录下。 1.1.3.文件中的配置元素及其属性 例如: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration

CBXdm的博客 220

大数据分析案例-基于随机森林模型对北京房价进行预测

自1998年我国取消了福利分房的政策后,房地产市场迅速开展蓬勃起来。同时,随着社会经济的快速开展,居民的经济条件越来越好,住房条件也在不断地提升。而住房是人民根本生活的保障,也是-一个家庭最重要的资产,从一定的层面.上反映了一个家庭整体的生活水王,多方面的因素使得房地产行业在短时间开展成为我国的支柱产业之一;成为了切实关乎人民生活和利益的重要产业。然而,随着房地产行业的开展,问题也慢慢突显出来,房价一直居高不下成为了一个大问题。 作为国家的支柱产业,房地产的稳定发展关乎国计民生。近几年,房

m0_64336780的博客 8836

mybatis 超简单入门 详细图文教程

本文简单介绍了MyBatis的快速入门流程,包括环境配置、数据库准备、项目结构、核心配置文件和SQL映射文件的编写。通过创建Dept表和POJO类,利用MyBatis的配置文件和SQL映射以及代理开发和注解开发两种模式实现了数据查询功能。同时,提供了mybatis调用的优化方案,利用接口映射简化代码调用。

m0_74187645的博客 4491

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

mybatis简单入门实例

mybatis是一个数据持久层框架,他与hibernate相比,也有自己的优点,当我们进行多表关联查询的时候,很容易实现,因为他天生就是用来写sql实现功能的,而hibernate需要实现这个多表关联,也不是没有办法,就是稍微麻烦一些,hibernate是orm框架,对于简单的实体和表的映射非常的方便,但是一般的项目中,很多都是两个,甚至三个表,甚至更多表联合查询,hibernate就显得有些笨拙...

feinifi的博客 481

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

二、【MyBatis】 MyBatis入门与简单使用

Object Relation Mapping 对象关系映射。对象指的是JAVA对象,关系指的是数据库中的关系模型,对象关系映射,指的就是在JAVA对象和数据库的关系模型之间建立一种对象个关系,比如用一个Java的User类,去对应数据库中的一张表goyeer_user类,类中的属性和表中的列一一对应。User类就对应goyeer_userk类中的一行数据。我们可以使用Mybatis的注解开发一些简单映射语句,这样可以是代码显得更加简介。

记录总结工作过往 747

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

MyBatis简单例子快速入门

一、理解什么是MyBatis?   MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架。 MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索。 MyBatis 可以使用简单的XML 或注解用于配置和原始映射,将接口和 Java 的 POJO( Plain Old Java Objects,普通的Java 对象)映射成数据库中的记录。 MyBATIS 目前提供了三种语言实现的版本,包括:Java、.NET以及Ruby。 它提供的持久层框架包括SQL

小强签名设计 的博客 598

Mybatis新手教程之简单入门

这篇文章主要给大家介绍了关于Mybatis新手教程之简单入门的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧 1、Mybatis概述   MyBatis 是支持普通 SQL 查询(相比较于Hibernate的封装,Mybatis是半自动化的JDBC封装,一个特点就是Mybatis执行的SQL查询语句需要自己在配置文件中写),存储过程和高级映射的优秀持久层框架。MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设...

apple_4872330的专栏 4073

MyBatis的简单入门

MyBatis的简单入门简介Eclipse 使用的使用设计模式的简介框架是什么Mybatis测试结果 简介 首先先进行一下自我介绍 爱好女,余下好多字(其他资料自己去猜) 在这个文档内有什么不懂的可以加我的QQ:1011547386 电话:13**********(保密)来随时问我,(也欢迎批评指正) 本个文档也是帮助初级学习者的入门指导(也就是大佬饶命) 我希望用一个轻松的方式来和大家一起学习s...

qq_42511420的博客 306

Mybatis简单入门

1 mybatis简单介绍 MyBatis是一个ORM的数据库持久化框架。 Mybatis是一个支撑框架,它以映射sql语句orm方式来数据库持久化操作. ORM:对象关系映射(Object Relational Mapping,简称ORM),是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术 1.1 ORM框架映射方式 Orm框架的操作数据库关系方式有很多种,常用的有两种: 1、S...

weixin_45415977的博客 260

【MyBatis】入门程序

详解编写mybatis入门程序的主要步骤,以及junit、logback和工具类 SqlSessionUtil 的封装

August_._的博客 1185

Mybatis入门

在前面我们学习MySQL数据库时,都是利用图形化客户端工具(如:idea、datagrip),来操作数据库的。在客户端工具中,编写增删改查的SQL语句,发给MySQL数据库管理系统,由数据库管理系统执行SQL语句并返回执行结果。增删改操作:返回受影响行数查询操作:返回结果集(查询的结果)我们做为后端程序开发人员,通常会使用Java程序来完成对数据库的操作。Java程序操作数据库,现在主流的方式是:Mybatis。什么是MyBatis?MyBatis是一款优秀的持久层框架,用于简化JDBC的开发。

qq_63763836的博客 1095

Mybatis入门,从一个简单的JdbcUtil开始

大学时候就学的最原始的JDBC,刚毕业那会,笔试还要求手写JDBC。什么都不说了,看代码吧。 首先,要去官网下载一个mysql的驱动包,如:mysql-connector-java-5.1.27.jar 然后,Run As Java Application package com.rice.web; import java.sql.Connection; import java.sql.Driv...

有米oooooooo 431

3.1Mybatis 入门

Mybatis笔记参考 1.环境搭建 1. 创建maven工程,导入依赖。 pom.xml <!-- mybatis--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.3</vers

qq_45134373的博客 172

1、mybatis入门案例

mybatis 1、mybatis概述 mybatis是一个持久层框架,用java编写的。 它封装了jdbc操作的很多细节,使开发者只需要关注sql语句本身,而无需关注注册驱动,创建连接等繁杂过程 它使用了ORM思想实现了结果集的封装。 ORM: ​ Object Relational Mappging 对象关系映射 ​ 简单的说: ​ 就是把数据库表和实体类及实体类的属性对应起来 ​ 让我们可以操作实体类就实现操作数据库表。 ​ user User ​ id userId ​

weixin_44230693的博客 263
上一篇: VM12下配置CentOS7的静态ip配置
下一篇: Linux shell 自动安装总结
Coder-Qian
博客等级 码龄11年 63粉丝 73原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址