目录
导入user.sql文件
在RuoYi-Vue数据库导入user.sql文件,或者自己新建表
添加代码
代码入下所列
HelloController
User
public class User {
public int id;
private String name;
private int age;
public String sex;
public String create_time;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getcreate_time() {
return create_time;
}
public void setcreate_time(String create_time) {
this.create_time = create_time;
}
@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", name=" + name +
", sex=" + sex +
", age=" + age +
", create_time=" + create_time +
'}';
}
}
UserMapper
UserService
UserMapper.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.ruoyi.system.mapper.UserMapper">
<resultMap id="UserResult" type="User">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="age" column="age" />
<result property="sex" column="sex" />
<result property="create_time" column="create_time" />
</resultMap>
<!-- 查询所有用户信息-->
<select id="selectAllUser" resultMap="UserResult">
select * from user
</select>
<!-- 插入用户信息-->
<insert id="insert" parameterType="User">
INSERT into user(name,age,sex,create_time) VALUES (#{name},#{age},#{sex},#{create_time})
</insert>
<!-- 根据id删除信息-->
<delete id="delete" parameterType="int">
DELETE from user where id=#{id}
</delete>
<update id="update" parameterType="User">
UPDATE user
<set>
<if test="name !=null">
name=#{name},
</if>
<if test="age !=null">
age=#{age},
</if>
<if test="sex !=null">
sex=#{sex},
</if>
<if test="create_time !=null">
create_time=#{create_time}
</if>
</set>
<where>
id=#{id}
</where>
</update>
</mapper>