0%

Springboot练习-学生教务系统笔记2

前言:在Springboot练习-学生教务系统笔记1中,初步搭建springboot框架并实现controller与前端页面的访问,这一次将正式开始学生教务系统的开发,加入数据库并使用mybatis实现对数据的CRUD以及controller、service设计

数据库参考

image-20200117000456358

maven依赖

mybatis与spring data jpa

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

application.properties

配置文件参考

1
2
3
4
5
6
7
8
9
10
11
12
13
server.port=8080
server.servlet.context-path=/orange
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false

spring.datasource.username=root
spring.datasource.password=orange
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/sms?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

mybatis.mapper-locations=classpath:/mybatis/mapping/*.xml
mybatis.config-location=classpath:/mybatis/config/mybatis-config.xml

mybatis

mybatis-config.xml

mybatis配置参考
仅仅配置了下划线转驼峰

1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
包名结构

image.png

mybatis相关文件路径

本次笔记实现了Student 增删改查与界面设计,请忽略Course、Teacher

image.png

image.png

实体类 Student
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @author shency
* @description: 学生实体类
*/
@Table(name = "student")
public class Student {
/**
* 学生编号
*/
@Id
@Column(name = "student_id")
private String studentId;

/**
* 学生姓名
*/
@Column(name = "student_name")
private String studentName;

/**
* 学生学号
*/
@Column(name = "student_number")
private String studentNumber;

/**
* 学生性别
* 0 male
* 1 female
*/
@Column(name = "student_sex")
private String studentSex;

/**
* 学生电话
*/
@Column(name = "student_phone_number")
private String studentPhoneNumber;

/**
* 学生邮箱
*/
@Column(name = "student_email")
private String studentEmail;

/**
* 创建时间
*/
@Column(name = "create_time")
private Date createTime;

/**
* 修改时间
*/
@Column(name = "modify_time")
private Date modifyTime;

/**
* 入学时间
*/
@Column(name = "student_enrollment_date")
private Date studentEnrollmentDate;

/**
* 省略Getter/Setter方法 或者使用注解
*/

}
StudentDTO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @author shency
* @description: StudentDTO
*/
public class StudentDTO {
/**
* 学生编号
*/
private String studentId;

/**
* 学生姓名
*/
private String studentName;

/**
* 学生学号
*/
private String studentNumber;

/**
* 学生性别
* 0 male
* 1 female
*/
private String studentSex;

/**
* 学生电话
*/
private String studentPhoneNumber;

/**
* 学生邮箱
*/
private String studentEmail;

/**
* 入学时间
*/
private Date studentEnrollmentDate;

/**
* 省略Getter/Setter方法 或者使用注解
*/
}
StudentMapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?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.scy.sms.dao.mapper.StudentMapper">
<resultMap id="studentMap" type="com.scy.sms.dao.entity.Student">
<id column="student_id" property="studentId" jdbcType="VARCHAR"/>
<result column="student_name" property="studentName" jdbcType="VARCHAR"/>
<result column="student_number" property="studentNumber" jdbcType="VARCHAR"/>
<result column="student_sex" property="studentSex" jdbcType="VARCHAR"/>
<result column="student_phone_number" property="studentPhoneNumber" jdbcType="VARCHAR"/>
<result column="student_email" property="studentEmail" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
<result column="student_enrollment_date" property="studentEnrollmentDate" jdbcType="VARCHAR"/>
</resultMap>
<sql id="insertKey">
<trim suffixOverrides=",">
student_id,
<if test="studentName != null and studentName != ''">
student_name,
</if>
<if test="studentNumber != null and studentNumber != ''">
student_number,
</if>
<if test="studentSex != null and studentSex != ''">
student_sex,
</if>
<if test="studentPhoneNumber != null and studentPhoneNumber != ''">
student_phone_number,
</if>
<if test="studentEmail != null and studentEmail != ''">
student_email,
</if>
<if test="studentEnrollmentDate != null and studentEnrollmentDate != ''">
student_enrollment_date,
</if>
</trim>
</sql>

<sql id="insertValues">
<trim suffixOverrides=",">
#{studentId},
<if test="studentName != null and studentName != ''">
#{studentName},
</if>
<if test="studentNumber != null and studentNumber != ''">
#{studentNumber},
</if>
<if test="studentSex != null and studentSex != ''">
#{studentSex},
</if>
<if test="studentPhoneNumber != null and studentPhoneNumber != ''">
#{studentPhoneNumber},
</if>
<if test="studentEmail != null and studentEmail != ''">
#{studentEmail},
</if>
<if test="studentEnrollmentDate != null and studentEnrollmentDate != ''">
#{studentEnrollmentDate},
</if>
</trim>
</sql>
<select id="studentPageQuery" parameterType="map" resultType="com.scy.sms.dto.StudentDTO">
SELECT
student_id,
student_name,
student_number,
student_sex,
student_phone_number,
student_email,
create_time,
modify_time,
student_enrollment_date
FROM
student
<where>
<if test="studentId != null and studentId != ''">
and student_id = #{studentId}
</if>
<if test="studentName != null and studentName != ''">
and student_name = #{studentName}
</if>
<if test="studentNumber != null and studentNumber != ''">
and student_number = #{studentNumber}
</if>
</where>
order by student_id desc
limit #{offset} , #{limit}
</select>
<select id="studentDetailQuery" parameterType="java.lang.String" resultType="com.scy.sms.dto.StudentDTO">
SELECT
student_id,
student_name,
student_number,
student_sex,
student_phone_number,
student_email,
create_time,
modify_time,
student_enrollment_date
FROM
student
WHERE
student_id = #{studentId}
</select>
<!-- <update id="studentUpdate" parameterType="com.scy.smso.StudentDTO">
update student
<trim prefix="set" suffixOverrides=",">
<if test="studentName != null and studentName != ''">
student_name = #{studentName},
</if>
<if test="studentNumber != null and studentNumber != ''">
student_number = #{studentNumber},
</if>
<if test="studentSex != null and studentSex != ''">
student_sex = #{studentSex},
</if>
<if test="studentPhoneNumber != null and studentPhoneNumber != ''">
student_phone_number = #{studentPhoneNumber},
</if>
<if test="studentEmail != null and studentEmail != ''">
studentEmail = #{studentEmail},
</if>
<if test="studentEnrollmentDate != null and studentEnrollmentDate != ''">
student_enrollment_date = #{studentEnrollmentDate},
</if>
</trim>
where
student_id = #{studentId,jdbcType=VARCHAR}
</update>-->
<update id="studentUpdate" parameterType="com.scy.sms.dto.StudentDTO">
update student
<set>
<if test="studentName != null and studentName != ''">
student_name = #{studentName},
</if>
<if test="studentNumber != null and studentNumber != ''">
student_number = #{studentNumber},
</if>
<if test="studentSex != null and studentSex != ''">
student_sex = #{studentSex},
</if>
<if test="studentPhoneNumber != null and studentPhoneNumber != ''">
student_phone_number = #{studentPhoneNumber},
</if>
<if test="studentEmail != null and studentEmail != ''">
student_email = #{studentEmail},
</if>
<if test="studentEnrollmentDate != null and studentEnrollmentDate != ''">
student_enrollment_date = #{studentEnrollmentDate},
</if>
</set>
where
student_id = #{studentId,jdbcType=VARCHAR}
</update>

<insert id="studentInsert" parameterType="com.scy.sms.dto.StudentDTO">
insert into student(<include refid="insertKey"/>)
values(<include refid="insertValues"/>)
</insert>

<delete id="studentDelete" parameterType="com.scy.sms.dto.StudentDTO">
delete from student where student_id=#{studentId}
</delete>
</mapper>

请求类

BaseRequset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* @author shency
* @description: BaseRequset
*/
@Data
public abstract class BaseRequset implements Serializable {

private static final long serialVersionUID = 985010454743040538L;

// 请求IP
public String requestIp;

// 请求时间
public String requestTime;

}
BasePageRequest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @author shency
* @description: BasePageRequest
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class BasePageRequest extends BaseRequset{
/**
* 页码
*/
private Integer page = 1;

/**
* 每页显示条数
*/
private Integer limit = 10;

/**
* 查询开始时间
*/
public String startTime;

/**
* 查询结束时间
*/
public String endTime;

@SuppressWarnings("unused")
private Integer offset;

public Integer getOffset() {
return (page - 1) * limit;
}
}
StudentQueryRequest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* @author shency
* @description: 学生查询操作请求类
*/
@Getter
@Setter
public class StudentQueryRequest extends BasePageRequest {
/**
* 学生编号
*/
private String studentId;

/**
* 学生姓名
*/
private String studentName;

/**
* 学生学号
*/
private String studentNumber;
}
StudentDeleteRequest
1
2
3
4
5
6
7
8
9
10
11
12
/**
* @author shency
* @description: 学生删除操作请求类
*/
@Getter
@Setter
public class StudentDeleteRequest {
/**
* 学生编号
*/
private String studentId;
}
StudentUpdateRequest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @author shency
* @description: 学生更新操作请求类
*/
@Getter
@Setter
public class StudentUpdateRequest {
/**
* 学生编号
*/
private String studentId;

/**
* 学生姓名
*/
private String studentName;

/**
* 学生学号
*/
private String studentNumber;

/**
* 学生性别
* 0 male
* 1 female
*/
private String studentSex;

/**
* 学生电话
*/
private String studentPhoneNumber;

/**
* 学生邮箱
*/
private String studentEmail;

/**
* 创建时间
*/
private Date createTime;
}
StudentInsertRequest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @author shency
* @description: 学生新增操作请求类
*/
@Getter
@Setter
public class StudentInsertRequest {
/**
* 学生编号
*/
private String studentId;

/**
* 学生姓名
*/
private String studentName;

/**
* 学生学号
*/
private String studentNumber;

/**
* 学生性别
* 0 male
* 1 female
*/
private String studentSex;

/**
* 学生电话
*/
private String studentPhoneNumber;

/**
* 学生邮箱
*/
private String studentEmail;

/**
* 创建时间
*/
private Date createTime;
}

CommonResultCodeEnum

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @author shency
* @description: 通用返回结构枚举
*/
public enum CommonResultCodeEnum {
SUCCESS("000000", "运行成功"),
SYSTEM_ERROR("999999", "系统错误"),
QUERY_ERROR("900000", "查询数据错误"),
INSERT_ERROR("900001", "插入数据错误"),
DELETE_ERROR("900002", "删除数据错误"),
UPDATE_ERROR("900003", "更新数据错误"),

PHONE_NUMBER_ERROR("901000", "电话数据错误");
private final String code;

private final String desc;

public String getCode() {
return code;
}

public String getDesc() {
return desc;
}

CommonResultCodeEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}

public static CommonResultCodeEnum getResultCode(String code) {
for (CommonResultCodeEnum resultCode : values()) {
if (resultCode.getCode().equals(code)) {
return resultCode;
}
}
return SYSTEM_ERROR;
}
}

BizException

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @author shency
* @description: 业务层异常类
*/
public class BizException extends RuntimeException implements Serializable {

private static final long serialVersionUID = -5170146508231708688L;
private String code;

private String msg;

private String detailMessage;

public BizException() {
super();
}

public BizException(CommonResultCodeEnum resultCode) {
super();
this.code = resultCode.getCode();
this.msg = resultCode.getDesc();
}

public BizException(String code, String message) {
super();
this.code = code;
this.msg = message;
}

public BizException(CommonResultCodeEnum resultCode, String detailMessage) {
super();
this.code = resultCode.getCode();
this.msg = resultCode.getDesc();
this.detailMessage = detailMessage;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

public void setDetailMessage(String detailMessage) {
this.detailMessage = detailMessage;
}

@Override
public String getMessage() {
return StringUtils.isEmpty(detailMessage) ? msg : detailMessage;
}

@Override
public String toString() {
StringBuffer controlExceptionStr = new StringBuffer();
controlExceptionStr.append("[BizException]");
controlExceptionStr.append("code:");
controlExceptionStr.append(code);
controlExceptionStr.append(",msg:");
controlExceptionStr.append(msg);
controlExceptionStr.append(",detailMessage:");
controlExceptionStr.append(detailMessage);

return controlExceptionStr.toString();
}

}

StudentService

IStudentService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @author shency
* @description: IStudentService
*/
public interface IStudentService {
/**
* 学生分页查询
*/
ResultModel<List<StudentDTO>> studentPageQuery(StudentPageQueryRequest studentPageQueryRequest);

/**
* 学生详情查询
*/
ResultModel<StudentDTO> studentDetailQuery(String studentId);

/**
* 学生更新
*/
ResultModel<Boolean> studentUpdate(StudentUpdateRequest studentUpdateRequest);

/**
* 学生删除
*/
ResultModel<Boolean> studentDelete(StudentDeleteRequest studentDeleteRequest);

/**
* 学生新增
*/
ResultModel<Boolean> studentInsert(StudentInsertRequest studentInsertRequest);
}
StudentService
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @author shency
* @description: StudentService
*/
@Slf4j
@Service
public class StudentService implements IStudentService {
@Resource
private StudentMapper studentMapper;

/**
* 学生分页查询
*/
@Override
public ResultModel<List<StudentDTO>> studentPageQuery(StudentPageQueryRequest studentPageQueryRequest){

ResultModel<List<StudentDTO>> result = new ResultModel<List<StudentDTO>>();
Map<String, Object> params = new HashMap<>();
params.put("studentId", studentPageQueryRequest.getStudentId());
params.put("studentName", studentPageQueryRequest.getStudentName());
params.put("studentNumber", studentPageQueryRequest.getStudentNumber());
params.put("limit", studentPageQueryRequest.getLimit());
params.put("offset", studentPageQueryRequest.getOffset());
try{
List<StudentDTO> studentList = studentMapper.studentPageQuery(params);
if (CollectionUtils.isEmpty(studentList)) {
studentList = new ArrayList<StudentDTO>();
}
result.setCount(studentList.size());
result.setSuccess(studentList);
}
catch(Exception e){
log.info("学生信息分页查询-异常" + e.getMessage());
e.printStackTrace();
}

return result;
}

/**
* 学生详细查询
*/
@Override
public ResultModel<StudentDTO> studentDetailQuery(String studentId) {
ResultModel<StudentDTO> result = new ResultModel<StudentDTO>();
try{
StudentDTO studentDTO = studentMapper.studentDetailQuery(studentId);
result.setCount(1);
result.setSuccess(studentDTO);
}
catch(Exception e){
log.info("学生信息详情查询-异常" + e.getMessage());
e.printStackTrace();
}
return result;
}

/**
* 更新学生
*/
@Override
public ResultModel<Boolean> studentUpdate(StudentUpdateRequest studentUpdateRequest) {
try{
StudentDTO studentDTO = new StudentDTO();
BeanUtils.copyProperties(studentUpdateRequest,studentDTO);
if (StringUtils.isNotBlank(studentDTO.getStudentPhoneNumber()) && studentDTO.getStudentPhoneNumber().length() != 11) {
throw new BizException(CommonResultCodeEnum.PHONE_NUMBER_ERROR);
}
studentMapper.studentUpdate(studentDTO);
}catch(Exception e){
log.info("学生信息更新-异常" + e.getMessage());
e.printStackTrace();
return new ResultModel<Boolean>().setSuccess(false);
}
return new ResultModel<Boolean>().setSuccess(false);
}

/**
* 删除学生
*/
@Override
public ResultModel<Boolean> studentDelete(StudentDeleteRequest studentDeleteRequest) {
try{
StudentDTO studentDTO = new StudentDTO();
BeanUtils.copyProperties(studentDeleteRequest,studentDTO);
studentMapper.studentDelete(studentDTO);
}catch(Exception e){
log.info("学生信息删除-异常" + e.getMessage());
e.printStackTrace();
return new ResultModel<Boolean>().setSuccess(false);
}
return new ResultModel<Boolean>().setSuccess(false);
}

/**
* 新增学生
*/
@Override
public ResultModel<Boolean> studentInsert(StudentInsertRequest studentInsertRequest) {
try{
String date = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()).toString();
studentInsertRequest.setStudentId(date+ RandomStringUtils.randomNumeric(6));
StudentDTO studentDTO = new StudentDTO();
BeanUtils.copyProperties(studentInsertRequest,studentDTO);
if (studentDTO.getStudentPhoneNumber().length() != 11) {
throw new BizException(CommonResultCodeEnum.PHONE_NUMBER_ERROR);
}
studentMapper.studentInsert(studentDTO);
}catch(Exception e){
log.info("学生信息插入-异常" + e.getMessage());
e.printStackTrace();
return new ResultModel<Boolean>().setSuccess(false);
}
return new ResultModel<Boolean>().setSuccess(true);
}
}

StudentController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @author shency
* @description: StudentController
*/
@Slf4j
@Controller
public class StudentController {
@Autowired
private IStudentService studentService;

@ResponseBody
@RequestMapping("/student/studentQuery.json")
public ResultModel<List<StudentDTO>> studentQuery(@RequestBody StudentQueryRequest studentQueryRequest) {
return studentService.studentMapQuery(studentQueryRequest);
}

@ResponseBody
@RequestMapping("/student/studentInsert.json")
public ResultModel<Boolean> studentInsert(@RequestBody StudentInsertRequest studentInsertRequest) {
return studentService.studentInsert(studentInsertRequest);
}

@ResponseBody
@RequestMapping("/student/studentUpdate.json")
public ResultModel<Boolean> studentUpdate(@RequestBody StudentUpdateRequest studentUpdateRequest) {
return studentService.studentUpdate(studentUpdateRequest);
}

@ResponseBody
@RequestMapping("/student/studentDelete.json")
public ResultModel<Boolean> studentDelete(@RequestBody StudentDeleteRequest studentDeleteRequest) {
return studentService.studentDelete(studentDeleteRequest);
}
}

BasePageController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @author shency
* @description: 通用路由页面
*/
@Slf4j
@Controller
public class BasePageController {
@GetMapping(value = "/index.html")
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
ModelAndView view = new ModelAndView();
view.setViewName("index");
return view;
}

@GetMapping(value = "/main.html")
public ModelAndView main(HttpServletRequest request, HttpServletResponse response) {
ModelAndView view = new ModelAndView();
view.setViewName("main");
return view;
}

@GetMapping("/{first}/{second}.html")
public String page(@PathVariable("first") String first,
@PathVariable("second") String second, HttpServletRequest request) {
String url = first + "/" + second;
System.out.println(url);
return url;
}

@GetMapping("/{first}/{second}/{third}.html")
public String page(@PathVariable("first") String first,
@PathVariable("second") String second,
@PathVariable("third") String third, HttpServletRequest request) {
String url = first + "/" + second + "/" + third;
System.out.println(url);
return url;
}

}

ResultModel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @author shency
* @description: Controller层返回结果模型
*/
@Data
public class ResultModel<T> implements Serializable {

private static final long serialVersionUID = -9090347033463853016L;

/**
* 返回数据总数量
*/
private Integer count;

/**
* 接口返回对象
*/
private T result;

/**
* 接口返回code
*/
private String code;

/**
* 接口返回msg
*/
private String msg;

public ResultModel() { };

public ResultModel(String code, String msg) {
this.code = code;
this.msg = msg;
}

public ResultModel(T result, String msg, String code) {
this.result = result;
this.msg = msg;
}

public ResultModel<T> setSuccess(T result) {
this.result = result;
this.msg = CommonResultCodeEnum.SUCCESS.getDesc();
this.code = CommonResultCodeEnum.SUCCESS.getCode();
return this;
}
}
-------------本文结束感谢您的阅读-------------