发表于: 2018-10-14 21:45:31

3 476


今日完成:

总结 Restful 接口风格

以前误以为所有的参数都可以通过 json 来传递

而 json 存储在 http 请求的 body 中,但实际上在使用 Get 方法是不存在 body 体的,只能通过 url 来调整参数


15.不用使用JSON Tag-lib,直接用Spring 返回JSON对象,对比两种实现方式的差别和应用场景

在标记 @Responsebody 将回应结果作为 JSON 将会自动解析,所以 JSON 内容是动态配置的,而是用 Tag-lib 是要写 JSP 页面作具体的配置,不灵活且修改不方便。


简单了解 Spring messageResource 是什么

作为 Spring 5.X 的新功能, 可以提供 国际化的消息处理机制




明天计划的事情:

1.早上详细学习关于 @Responsebody 注解的使用

将返回结果作为 JSON, 什么样的对象可以自动解析。


2.早上关于 Jackson 和 Gson 的区别,并选择一种详细学习


遇到的问题:

未解决

关于 Pagehelper 的分页,将会查询不必要的字段。

//required = false 可以不传参数, required = true 必须传参数
@ResponseBody
@RequestMapping(value = "/student/page/{page}", method = RequestMethod.GET)
public PageInfo<Student> getList(
@PathVariable int page,
       @RequestParam(required = false, defaultValue = "10") int rows) {

//只对该语句以后的第一个查询语句得到的数据进行分页
   //所以避免分页有时候有效果有时候没效果要立即调用 Mybatis 进行查询较好
   PageHelper.startPage(page, rows);
   List<Student> students = studentService.selectAllStudent();
   PageInfo<Student> pageInfo = new PageInfo<>(students);

   return pageInfo;
}

在 mapper 中调用的第一句 SQL 如下

<select id="selectAllStudent" resultType="com.draper.entity.Student">
   SELECT it_mates_table.online_id, study_type, start_study_time, daily_link, wish, coach_senior, know_from, name, qq, graduate_school
FROM it_mates_table, simple_mates_table
WHERE 1 = 1
AND it_mates_table.online_id = simple_mates_table.online_id
</select>

并没有字段 create_at 和 update_at,但实际的分页结果中包含这两个字段,为什么?



返回列表 返回列表
评论

    分享到