<?xml version="1.0" encoding="UTF-8"?><projectxmlns="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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.5</version><relativePath/><!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.4</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
创建实体类Student
package com.lalila.springboottest.entity;publicclassStudent{private Long id;private String name;private Long age;public Long getAge(){return age;}publicvoidsetAge(Long age){this.age = age;}public String getName(){return name;}publicvoidsetName(String name){this.name = name;}public Long getId(){return id;}publicvoidsetId(Long id){this.id = id;}@Overridepublic String toString(){return"Student{"+"id="+ id +", name='"+ name +'\''+", age="+ age +'}';}}
<?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"><mappernamespace="com.lalila.springboottest.repository.StudentRepository"><selectid="findAll"resultType="Student">
select * from student
</select><selectid="findById"parameterType="java.lang.Long"resultType="Student">
select * from student where id =#{id}
</select><insertid="save"parameterType="Student">
insert into student(id,name,age) values(#{id},#{name},#{age})
</insert><updateid="update"parameterType="Student">
update student set name = #{name},age = #{age} where id = #{id}
</update><deleteid="deleteById"parameterType="java.lang.Long">
delete from student where id = #{id}
</delete></mapper>