案例详解
首先在Navicat中创建一张表。
创建一个SpringBoot工程,在pom文件中添加所需依赖。
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
test
mysql
mysql-connector-java
runtime
5.1.9
com.baomidou
mybatis-plus-boot-starter
3.0.5
编写数据库中student表对应的实体类。
package com.szh.mybatisplus.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
/**
*
*/
@TableName(value = 'student')
public class Student {
@TableId(value = 'id',type = IdType.AUTO)
private Integer id;
@TableField(value = 'name')
private String name;
@TableField(value = 'age')
private Integer age;
@TableField(value = 'email')
private String email;
@TableField(value = 'status')
private Integer status;
//getter and setter
//toString
}
编写mapper接口。之前几篇文章中,我们的mapper接口中没有任何方法,是因为继承了MP框架中的BaseMapper模板类,可以直接使用BaseMapper中的CRUD操作方法。那么现在我们定义的mapper接口仍然让它继承MP框架中的BaseMapper模板类,但是我对StudentMapper接口做一个扩展,添加我们自定义的CRUD操作方法。
package com.szh.mybatisplus.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.szh.mybatisplus.entity.Student;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
*
*/
public interface StudentMapper extends BaseMapper {
//自定义方法
int insertStudent(Student student);
Student selectStudentById(@Param('id') Integer id);
List selectAll();
}
insert into student(name,age,email,status)
values(#{name},#{age},#{email},#{status})
#配置数据库的相关连接信息
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springdb?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=12345678
#配置对应的日志信息
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#指定MyBatis-Plus映射文件的路径
mybatis-plus.mapper-locations=classpath:mapper/*.xml
文章为作者独立观点,不代表 股票程序化软件自动交易接口观点
在路上2023-03-17
这个很正常,那个买半导体股票是出于支持国家产业政策。都一样!你不也是想利用政策支持赚钱。