2024-10-09

This commit is contained in:
17940 2024-10-09 20:14:18 +08:00
parent d2febf455b
commit 14e295af9d
26 changed files with 535 additions and 7 deletions

View File

@ -3,8 +3,18 @@
<component name="Encoding">
<file url="file://$PROJECT_DIR$/Eight-MyBatis/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Fifth-SpringBoot-QS/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/First-Spring/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/First-Spring/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Forth-SpringMVC/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Forth-SpringMVC/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Night-Name/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Nineth-MyBatis-XML-Demo/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Nineth-MyBatis-XML-Demo/src/main/java/xg/xmz/mapper/AccountMapper.java" charset="GBK" />
<file url="file://$PROJECT_DIR$/Nineth-MyBatis-XML-Demo/src/main/java/xg/xmz/mapper/ScoreMapper.java" charset="GBK" />
<file url="file://$PROJECT_DIR$/Seven-SpringBoot-RESTful/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Six-Springboot/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Third-SpringMVC/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/Third-SpringMVC/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>

View File

@ -13,8 +13,16 @@
<option value="$PROJECT_DIR$/Seven-SpringBoot-RESTful/pom.xml" />
<option value="$PROJECT_DIR$/Six-Springboot/pom.xml" />
<option value="$PROJECT_DIR$/Third-SpringMVC/pom.xml" />
<option value="$PROJECT_DIR$/Night-Name/pom.xml" />
<option value="$PROJECT_DIR$/Nineth-MyBatis-XML-Demo/pom.xml" />
</list>
</option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/Eight-MyBatis/pom.xml" />
<option value="$PROJECT_DIR$/Night-Name/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="24" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />

View File

@ -10,12 +10,18 @@ import java.util.List;
@Mapper
public interface studentmapper {
@Select("select * from student")
List<student> students();
public List<student> students();
@Select("SELECT * FROM student WHERE id = #{id}")
student getById(String id);
public student getById(String id);
@Select("select * from student where name like concat(#{lastname},'%')")
List<student> getGetByLastname(String lastname);
@Select("select * from student where name like concat('%',#{lastName},'%')")
public List<student> getByLastName(String lastName);
// 查询姓名为n个字的学生并降序
@Select("select * from student " +
"where char_length(student.name)=#{len} " +
"order by student.create_time desc;")
public List<student> getByNameLen(int len);
}

View File

@ -0,0 +1,13 @@
package xg.xmz;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FifthSpringBootQsApplication {
public static void main(String[] args) {
SpringApplication.run(FifthSpringBootQsApplication.class, args);
}
}

View File

@ -0,0 +1 @@
spring.application.name=Fifth-SpringBoot-QS

View File

@ -0,0 +1,13 @@
package xg.xmz;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class FifthSpringBootQsApplicationTests {
@Test
void contextLoads() {
}
}

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xg.xmz</groupId>
<artifactId>ThirdWeek</artifactId>
<artifactId>JavaEE2024</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xg.xmz</groupId>
<artifactId>ThirdWeek</artifactId>
<artifactId>JavaEE2024</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

33
Nineth-MyBatis-XML-Demo/.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 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>3.3.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>xg.xmz</groupId>
<artifactId>Nineth-MyBatis-XML-Demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Nineth-MyBatis-XML-Demo</name>
<description>Nineth-MyBatis-XML-Demo</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<!-- 热部署 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<!-- mybatis-plus -->
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.5</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,13 @@
package xg.xmz;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class NinethMyBatisXmlDemoApplication {
public static void main(String[] args) {
SpringApplication.run(NinethMyBatisXmlDemoApplication.class, args);
}
}

View File

@ -0,0 +1,12 @@
package xg.xmz.Pojo;
import lombok.Data;
@Data
public class Account extends BaseEntity {
private Integer id;
private String account;
private String password;
private Integer role = 1;
}

View File

@ -0,0 +1,14 @@
package xg.xmz.Pojo;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class BaseEntity {
private Integer createBy;
private LocalDateTime createTime;
private Integer updateBy;
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,10 @@
package xg.xmz.Pojo;
import lombok.Data;
@Data
public class Course extends BaseEntity{
private Integer id;
private String name;
}

View File

@ -0,0 +1,10 @@
package xg.xmz.Pojo;
import lombok.Data;
@Data
public class Gender extends BaseEntity {
private Integer id;
private String name;
}

View File

@ -0,0 +1,16 @@
package xg.xmz.Pojo;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class Score extends BaseEntity{
private Integer id;
private String studentId;
private String courseId;
private Integer score;
private LocalDateTime createTime;
}

View File

@ -0,0 +1,15 @@
package xg.xmz.Pojo;
import lombok.Data;
import java.time.LocalDate;
@Data
public class Student extends BaseEntity {
private String id;
private String name;
private Integer gender;
private LocalDate birthday;
private Gender genderDetails;
}

View File

@ -0,0 +1,9 @@
package xg.xmz.mapper;
import org.apache.ibatis.annotations.Mapper;
import xg.xmz.Pojo.Account;
@Mapper
public interface AccountMapper {
void insertAccount(Account account);
}

View File

@ -0,0 +1,15 @@
package xg.xmz.mapper;
import org.apache.ibatis.annotations.Mapper;
import xg.xmz.Pojo.Score;
import java.util.List;
@Mapper
public interface ScoreMapper {
void insert(Score score);
void deleteById(Integer id);
void deleteByIds(List<Integer> ids);
}

View File

@ -0,0 +1,21 @@
package xg.xmz.mapper;
import org.apache.ibatis.annotations.Mapper;
import xg.xmz.Pojo.Student;
import java.util.List;
@Mapper
public interface StudentMapper {
List<Student> getAll();
Student getById(String id);
List<Student> getByCondition(Integer len, Integer gender);
void insert(Student student);
void update(Student student);
}

View File

@ -0,0 +1,26 @@
spring.application.name=Nineth-MyBatis-XML-Demo
#?????
spring.devtools.restart.enabled=true
#??????
spring.devtools.restart.additional-paths=src/main/java
# ???? ???????????????????
spring.jackson.time-zone=Asia/Shanghai
#?? cLasspath ????WEB-INF??????????(???????????????????
spring.devtools.restart.exclude=static/**
# ?????
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# ???????????????
spring.datasource.url=jdbc:mysql://10.33.66.120:3306/mb202210080224
# ???????????????
spring.datasource.username=mb202210080224
# ???????????????
spring.datasource.password=YMVGPV317282
# ?? mybatis ????????????
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
# ?? mybatis ???????????
mybatis.configuration.map-underscore-to-camel-case=true
# ?? mybatis ?????????????????
mybatis.mapper-locations=classpath*:mapper/*.xml
# ???????Java?????????????????
mybatis.type-aliases-package=xg.xmz.Pojo

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xg.xmz.mapper.AccountMapper">
<insert id="insertAccount" keyProperty="id" useGeneratedKeys="true" parameterType="xg.xmz.Pojo.Account">
insert into account(account, password, role, create_by)
values(#{account}, #{password}, #{role}, #{createBy})
</insert>
</mapper>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xg.xmz.mapper.ScoreMapper">
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into score(id,student_id,course_id,score,create_by,create_time)
values(#{id},#{studentId},#{courseId},#{score},#{createBy},#{createTime})
</insert>
<delete id="deleteById">
delete from score where id = #{id}
</delete>
<delete id="deleteByIds">
delete from score where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xg.xmz.mapper.StudentMapper">
<sql id="commonSelect">
select * from student
</sql>
<select id="getAll" resultType="xg.xmz.Pojo.Student">
<include refid="commonSelect"></include>
</select>
<select id="getById" resultType="xg.xmz.Pojo.Student">
<include refid="commonSelect"></include>
where id = #{id}
</select>
<select id="getByCondition" resultType="xg.xmz.Pojo.Student">
<include refid="commonSelect"></include>
<where>
<if test="len !=null">CHAR_LENGTH(student.`name`) = #{len} </if>
<if test="gender !=null">and gender = #{gender}</if>
</where>
</select>
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into student(id, name, gender, birthday, create_by, create_time)
values(#{id}, #{name}, #{gender}, #{birthday}, #{createBy}, #{createTime})
</insert>
<update id="update">
update student
<set>
<if test="name != null">name = #{name},</if>
<if test="gender != null">gender = #{gender},</if>
<if test="birthday != null">birthday = #{birthday},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime}</if>
</set>
where id = #{id}
</update>
</mapper>

View File

@ -0,0 +1,104 @@
package xg.xmz;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import xg.xmz.Pojo.Account;
import xg.xmz.Pojo.Score;
import xg.xmz.Pojo.Student;
import xg.xmz.mapper.AccountMapper;
import xg.xmz.mapper.ScoreMapper;
import xg.xmz.mapper.StudentMapper;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
@SpringBootTest
class NinethMyBatisXmlDemoApplicationTests {
@Autowired
StudentMapper studentMapper;
@Autowired
AccountMapper accountMapper;
@Autowired
ScoreMapper scoreMapper;
@Test
public void testGetAll() {
List<Student> students = studentMapper.getAll();
System.out.println(students);
}
@Test
public void testGetById() {
Student student = studentMapper.getById("12138");
System.out.println(student);
}
@Test
public void testGetByCondition() {
List<Student> student = studentMapper.getByCondition(null,null);
System.out.println(student);
}
@Test
public void testInsertAccount() {
Account account = new Account();
account.setAccount("12143");
account.setPassword("123456");
account.setCreateBy(1);
LocalDateTime now = LocalDateTime.now();
account.setCreateTime(now);
accountMapper.insertAccount(account);
}
@Test
public void testInsertStudent() {
Student student = new Student();
student.setId("12143");
student.setName("½չ²©");
student.setGender(1);
student.setBirthday(LocalDate.of(2002,10,14));
student.setCreateBy(1);
LocalDateTime now = LocalDateTime.now();
student.setCreateTime(now);
studentMapper.insert(student);
}
@Test
public void testInsertScore(){
Score score = new Score();
score.setStudentId("12142");
score.setCourseId("102");
score.setScore(90);
score.setCreateBy(1);
LocalDateTime now = LocalDateTime.now();
score.setCreateTime(now);
scoreMapper.insert(score);
System.out.println(score.getId());
}
@Test
public void testUpdateStudent() {
Student student = new Student();
student.setId("12141");
student.setName("test");
student.setUpdateBy(1);
student.setUpdateTime(LocalDateTime.now());
studentMapper.update(student);
}
@Test
public void testDeleteScore() {
scoreMapper.deleteById(32);
}
@Test
public void testDeleteScores() {
List<Integer> ids = Arrays.asList(29,30,31);
scoreMapper.deleteByIds(ids);
}
}

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xg.xmz</groupId>
<artifactId>ThirdWeek</artifactId>
<artifactId>JavaEE2024</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>Third-SpringMVC</artifactId>