@JsonIgnore
private String password;

    @JsonFormat(pattern="yyyy-MM-dd hh:mm:ss a",locale="zh", timezone="GMT+8")
private Date birthday;
@JsonInclude(Include.NON_NULL)
private String desc;

 /imooc-springboot-starter/src/main/java/com/imooc/controller/UserController.java

package com.imooc.controller;

import java.util.Date;

//import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import com.imooc.pojo.LeeJSONResult;
import com.imooc.pojo.User; //@Controller
@RestController // @RestControler = @Controller + @ResponseBody
@RequestMapping("/user")
public class UserController { //@RequestMapping("/hello")
@RequestMapping("/getUser")
//@ResponseBody
public User hello() {
//public User getUser() {
User u = new User();
u.setName("imooc");
u.setAge(18);
u.setBirthday(new Date());
u.setPassword("imooc");
//u.setDesc(null);
u.setDesc("hello imooc~~"); return u; }
@RequestMapping("/getUserJson")
//@ResponseBody
public LeeJSONResult hello1() {
//public LeeJsonResult getUserJson() {
User u = new User();
u.setName("imooc");
u.setAge(18);
u.setBirthday(new Date());
u.setPassword("imooc");
//u.setDesc(null);
u.setDesc("hello imooc~~"); return LeeJSONResult.ok(u); }
}

/imooc-springboot-starter/src/main/java/com/imooc/pojo/User.java

package com.imooc.pojo;

import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@JsonIgnoreProperties
public class User { private String name;
@JsonIgnore
private String password;
private Integer age;
@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss a",locale="zh", timezone="GMT+8")
private Date birthday;
@JsonInclude(Include.NON_NULL)
private String desc;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
} }

第3章 springboot接口返回json 3-2 Jackson的基本演绎法的更多相关文章

  1. 第3章 springboot接口返回json 3-1 SpringBoot构造并返回一个json对象

    数据的使用主要还是以JSON为主,我们不会去使用XML. 这个时候我们先不使用@RestController,我们使用之前SpringMVC的那种方式,就是@Controller.  @Respons ...

  2. C#调用接口返回json数据中含有双引号 或其他非法字符的解决办法

    这几天,调用别人接口返回json数据含有特殊符号(双引号),当转换成json对象总是报错, json字符格式如下 { "BOXINFO":[ { ", "ITE ...

  3. java通过url调用远程接口返回json数据

    java通过url调用远程接口返回json数据,有用户名和密码验证, 转自 https://blog.csdn.net/wanglong1990421/article/details/78815856 ...

  4. 上手spring boot项目(四)之springboot如何返回json数据

    在springboot整合thymeleaf中,经常会在HTML页面中接收来自服务器的json数据,然后处理json数据并在页面上渲染.那么如何在服务器中返回json类型的数据呢? 1.使用@Resp ...

  5. 接口返回json

    use Mojolicious::Lite; use JSON qw/encode_json decode_json/; # /foo?user=sri get '/api' => sub { ...

  6. 【Golang 接口自动化04】 解析接口返回JSON串

    前言 上一次我们一起学习了如何解析接口返回的XML数据,这一次我们一起来学习JSON的解析方法. JSON(Javascript Object Notation)是一种轻量级的数据交换语言,以文字为基 ...

  7. 2.SpringBoot之返回json数据

    一.创建一个springBoot个项目 操作详情参考:1.SpringBoo之Helloword 快速搭建一个web项目 二.编写实体类 /** * Created by CR7 on 2017-8- ...

  8. SpringBoot之返回json数据

    一.创建一个springBoot个项目 二.编写实体类 /** * 返回Json数据实体类 */ public class User { private int id; private String ...

  9. SpringBoot 02_返回json数据

    在SpringBoot 01_HelloWorld的基础上来返回json的数据,现在前后端分离的情况下多数都是通过Json来进行交互,下面就来利用SpringBoot返回Json格式的数据. 1:新建 ...

随机推荐

  1. 《Effective C++》——条款17:以独立语句将newed对象置入智能指针

    假设有如下两个函数: int priority(); void processWidget(std::tr1::shared_ptr<Widget>pw, int priority); 对 ...

  2. Leetcode 969. Pancake Sorting

    每次找到当前最大数,转两下把最大数转到最右边.重复这个操作,直到都转完. 时间复杂度O(n**2) class Solution(object): def pancakeSort(self, A): ...

  3. Scala极速入门

    摘要 当面向对象遇到函数式编程,这就是Scala.简练的语言描述与简单的例子相辅相成,希望能够对大家学习Scala有所帮助. scala 入门 定义 Scala语言是一种面向对象语言,同时又结合了命令 ...

  4. [BZOJ1242]Fishing Net

    dbzoj vjudge1 vjudge2 sol 给一个无向图,求判定是不是弦图. sol 还是弦图那套理论. 复杂度是\(O(n^2)\)的,因为\(m\)本质上和\(n^2\)是同级的. cod ...

  5. 图m的着色问题(搜索)

    图的m着色问题 [问题描述]        给定无向连通图G和m种不同的颜色.用这些颜色为图G的各顶点着色,每个顶点着一种颜色.如果有一种着色法使G中每条边的2个顶点着不同颜色,则称这个图是m可着色的 ...

  6. celery 停止执行中 task

    目录 原因 解决过程 原因 因为最近项目需求中需要提供对异步执行任务终止的功能,所以在寻找停止celery task任务的方法.这种需求以前没有碰到过,所以,只能求助于百度和google,但是找遍了资 ...

  7. 横向排列两个多个div盒子的方法(CSS浮动清除float-clear/inline)/办法

    最近在做一个div css切割,昨晚发现了长期以来一直无记录下来的问题!关于兼容IE跟FF的float属性.趁现在还清醒赶紧记下笔记先:一.并排在一行的两个div样式有这种情况:ie或者ff下对于子d ...

  8. Dubbo与Zookeeper

    ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一致性服务的软件,提供的功 ...

  9. 【转载,实测好用】gitlab结合sourcetree使用

    转载 的出处http://blog.csdn.net/u012764358/article/details/62886427 Gitlab和Sourcetree结合使用实现代码管理 这是本人第一次发表 ...

  10. Mezzanine汉化

    1.编辑/path/to/projectname/projectname下的setting.pyALLOWED_HOSTS = ['www.xxx.com'] 为了使用域名来访问TIME_ZONE = ...