package com.abc.entity;
import lombok.Data;
import lombok.ToString;
import java.time.LocalDateTime;
@ToString
@Data
public class Student {
private Long id;
private LocalDateTime createTime;
private LocalDateTime modifyTime;
private String name;
private Integer age;
private String homeAddress;
}
package com.abc.entity;
import lombok.Data;
import lombok.ToString;
import java.time.LocalDateTime;
@ToString
@Data
public class Teacher {
private Long id;
private LocalDateTime createTime;
private LocalDateTime modifyTime;
private String name;
private Integer age;
private String homeAddress;
}
package com.abc.provider;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;
import org.apache.ibatis.jdbc.SQL;
public class TeacherProvider implements ProviderMethodResolver {
public static String select2(String name, String homeAddress) {
return new SQL(){{
SELECT("*");
FROM("a_teacher");
if (name != null && !"".equals(name)) {
WHERE("name like #{name}");
}
if (name != null && !"".equals(homeAddress)) {
WHERE("home_address like #{name}");
}
}}.toString();
}
}
package com.abc.mapper;
import com.abc.entity.Student;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
public interface StudentMapper {
void insert(Student student);
void update(Student student);
Student selectById(Long id);
List<Student> select(@Param("name") String name, @Param("homeAddress") String homeAddress);
List<Map<String, Object>> select2(String name, String homeAddress);
void delete(Long[] ids);
}
<?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.abc.mapper.StudentMapper">
<insert id="insert" parameterType="com.abc.entity.Student" useGeneratedKeys="true" keyProperty="id">
insert into a_student(create_time,modify_time,name,age,home_address)
values(#{createTime},#{modifyTime},#{name},#{age},#{homeAddress})
</insert>
<update id="update" parameterType="com.abc.entity.Student">
update a_student set id=id
<if test="name != null and name != ''">
,name=#{name}
</if>
<if test="age != null">
,age=#{age}
</if>
<if test="homeAddress != null and homeAddress != ''">
,home_address=#{homeAddress}
</if>
where id=#{id}
</update>
<select id="selectById" resultType="com.abc.entity.Student">
select * from a_student where id=#{id}
</select>
<select id="select" resultType