赞
踩
本人负责后端,本次完成了user的查询所有和添加功能
- @Mapper
- public interface UserDao {
- User selectByNameId(User user); //根据username和password查询
-
- List<User> selectAll();//查询所有
-
- int addUser(User user);//添加user
-
- int deleteUser(String id);//通过工号删除(修改逻辑删除字段0为删除)
- }
- <insert id="addUser">
- insert into studentsystem.tb_user values (#{id},#{name},#{college},#{tel},#{email},#{username},#{password},#{status},#{deleted})
- </insert>
- <update id="deleteUser">
- update studentsystem.tb_user set deleted = 0 where id = #{id};
- </update>
-
- <select id="selectByNameId" resultType="com.example.studentsystem.pojo.User">
- select * from studentsystem.tb_user where username = #{username} and password = #{password}
- </select>
- <select id="selectAll" resultType="com.example.studentsystem.pojo.User">
- select * from studentsystem.tb_user where deleted = 1
- </select>
- @Transactional
- public interface UserService {
- boolean login(User user); //登录
-
- List<User> selectAll(); //查询所有
-
- boolean addUser(User user);//添加
-
- boolean deleteUser(String id);
- }
- @Service
- public class UserServiceImpl implements UserService {
- @Autowired
- private UserDao userDao;
-
- @Override
- public boolean login(User user) {
- User user1 = userDao.selectByNameId(user);
- if(user1 == null){
- return false;
- }
- return user1.getDeleted() != 0 && user1.getStatus() != 0;
- }
-
- @Override
- public List<User> selectAll() {
- List<User> users = userDao.selectAll();
- return users;
- }
-
- @Override
- public boolean addUser(User user) {
- if(user == null){
- return false;
- }
- user.setStatus(1);
- user.setDeleted(1);
- int i = userDao.addUser(user);
- return i>0;
- }
-
- @Override
- public boolean deleteUser(String id) {
- int i = userDao.deleteUser(id);
- return i>0;
- }
- }
- @Slf4j
- @RestController
- @RequestMapping("/users")
- public class UserController {
- @Autowired
- private UserService userService;
-
- @PostMapping("/login")
- public Result login(@RequestBody User user) {
- boolean flag = userService.login(user);
- return new Result(flag ? Code.SUCCESS : Code.FAIL, flag);
- }
-
- @PostMapping("/selectAll")
- public Result selectAll() {
- List<User> users = userService.selectAll();
- boolean flag = !users.isEmpty();
- log.info(users.toString());
- return new Result(flag ? Code.SUCCESS : Code.FAIL,users);
- }
-
- @PostMapping("/addUser")
- public Result addUser(@RequestBody User user) {
- boolean flag = userService.addUser(user);
- return new Result(flag ? Code.SUCCESS : Code.FAIL,flag);
- }
-
- @GetMapping("/deleteUser")
- public Result deleteUser(String id){
- boolean flag = userService.deleteUser(id);
- return new Result(flag ? Code.SUCCESS : Code.FAIL,flag);
- }
- }
- create table studentsystem.tb_administrativeclass
- (
- name varchar(32) not null comment '班级名称'
- primary key,
- teacherid varchar(32) null comment '班主任工号',
- count int null comment '班级总人数',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint fk_administrativeclass_teacherid
- foreign key (teacherid) references studentsystem.tb_user (id)
- )
- comment '行政班';
- create table studentsystem.tb_college
- (
- name varchar(32) not null comment '学院名称'
- primary key,
- deleted int default 1 null comment '逻辑删除字段0表示已删除'
- )
- comment '学院表';
-
- create table studentsystem.tb_course
- (
- id varchar(32) not null comment '课程ID'
- primary key,
- name varchar(32) null comment '课程名称',
- deleted int default 1 null comment '逻辑删除字段0表示已删除'
- )
- comment '课程表';
-
- create table studentsystem.tb_courseaim
- (
- id bigint not null comment '主键id'
- primary key,
- description varchar(1024) null comment '课程目标描述',
- courseid varchar(32) null comment '课程ID',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint fk_courseaim_courseid
- foreign key (courseid) references studentsystem.tb_course (id)
- )
- comment '课程目标表';
-
- create table studentsystem.tb_courseaim_evaluationbasis
- (
- id bigint not null comment '主键ID'
- primary key,
- courseaimid bigint null comment '课程目标ID',
- evaluationbasis bigint null comment '评价标准ID',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint fk_courseaim_evaluationbasis_courseaimid
- foreign key (courseaimid) references studentsystem.tb_courseaim (id),
- constraint fk_courseaim_evaluationbasis_evaluationbasis
- foreign key (evaluationbasis) references studentsystem.tb_evaluationbasis (id)
- )
- comment '课程目标与评价标准中间表';
-
- create table studentsystem.tb_evaluationbasis
- (
- id bigint not null comment '主键ID'
- primary key,
- name varchar(16) null comment '评价标准名称',
- deleted int default 1 null comment '逻辑删除字段0表示已删除'
- )
- comment '评价标准表';
-
- create table studentsystem.tb_student
- (
- id bigint not null comment '学号'
- primary key,
- name varchar(12) null comment '姓名',
- sex char null comment '性别',
- classname varchar(32) null comment '行政班级名称',
- college varchar(32) null comment '学院名称',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint fk_student_classname
- foreign key (classname) references studentsystem.tb_administrativeclass (name),
- constraint fk_student_college
- foreign key (college) references studentsystem.tb_college (name)
- )
- comment '学生表';
-
- create table studentsystem.tb_student_course
- (
- id bigint not null comment '主键ID'
- primary key,
- studentid bigint null comment '学生ID',
- courseid varchar(32) null comment '课程ID',
- score double null comment '总分',
- jsonscore varchar(2048) null comment '各评价标准成绩',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint fk_student_course_courseid
- foreign key (courseid) references studentsystem.tb_course (id),
- constraint fk_student_course_studentid
- foreign key (studentid) references studentsystem.tb_student (id)
- )
- comment '学生与课程中间表';
-
- create table studentsystem.tb_student_course
- (
- id bigint not null comment '主键ID'
- primary key,
- studentid bigint null comment '学生ID',
- courseid varchar(32) null comment '课程ID',
- score double null comment '总分',
- jsonscore varchar(2048) null comment '各评价标准成绩',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint fk_student_course_courseid
- foreign key (courseid) references studentsystem.tb_course (id),
- constraint fk_student_course_studentid
- foreign key (studentid) references studentsystem.tb_student (id)
- )
- comment '学生与课程中间表';
-
- create table studentsystem.tb_teachclass
- (
- id bigint not null comment '主键id'
- primary key,
- teacherid varchar(32) null comment '老师工号',
- couseid varchar(32) null comment '课程ID',
- name varchar(32) null comment '班级名称',
- count int null comment '班级总人数',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint fk_teachclass_couseid
- foreign key (couseid) references studentsystem.tb_course (id),
- constraint fk_teachclass_teacherid
- foreign key (teacherid) references studentsystem.tb_user (id)
- )
- comment '教学班';
-
- create table studentsystem.tb_user
- (
- id varchar(32) not null comment '教职工工号'
- primary key,
- name varchar(12) null comment '老师姓名',
- college varchar(32) null comment '学院名称',
- tel char(11) null comment '电话号码',
- email varchar(32) null comment '邮箱',
- username varchar(32) null comment '用户名',
- password varchar(32) null comment '密码',
- status int default 1 null comment '账号状态1正常,0异常',
- deleted int default 1 null comment '逻辑删除字段0表示已删除',
- constraint username
- unique (username),
- constraint fk_user_college
- foreign key (college) references studentsystem.tb_college (name)
- )
- comment '用户表';
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。