@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. 重置Mac账户密码

    前提条件,未开启FileVault. 方法: 开机时按住⌘R进入恢复模式 点菜单命令[实用工具]-[终端] 在终端里输入 resetpassword 回车,或出现重设密码窗口 选中要重设密码的硬盘(如 ...

  2. Codeforces Round #254(div2)A

    很有趣的题.想到了就非常简单,想不到就麻烦了. 其实就是一种逆向思维:最后结果肯定是这样子: WBWBWBWB... BWBWBWBW... WBWBWBWB... ... 里面有“-”的地方改成“- ...

  3. BuildPipeline.BuildAssetBundle 编译资源包

    原文出自:http://blog.csdn.net/nateyang/article/details/7567831 1.导出.unity3d格式资源: http://game.ceeger.com/ ...

  4. sed----Linux下文本处理五大神器之一

    转自:http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行 ...

  5. Catch That Cow(广搜)

    个人心得:其实有关搜素或者地图啥的都可以用广搜,但要注意标志物不然会变得很复杂,想这题,忘记了标志,结果内存超时: 将每个动作扔入队列,但要注意如何更简便,更节省时间,空间 Farmer John h ...

  6. java 使用最新api操作mongodb

    // package com.auto.test.dbmodel; import java.util.ArrayList; import org.bson.Document;import org.bs ...

  7. vertex shader must minimally write all four components of POSITION

    Though the POSITION semantic must be written out by the vertex shader, it cannot be read in by the p ...

  8. ASP.NET 整理比较全的URL重写解决方案

    经常有人请我指导应该如何动态地“重写”URL,以在他们的ASP.NETweb应用中发布比较干净的URL端点.这个博客帖子概述了几个方法,你可以用来在ASP.NET中干净地映射或重写URL,以及按照你自 ...

  9. C# Winform中窗体的美化—— 用IrisSkin轻松实现换肤功能

    今天经前辈提醒才知道winform窗体还有美化工具,呵呵,不得不说,孤陋寡闻了.下面总结一下irisskin2的使用步骤和遇到的问题及解决办法. 1.网址:http://www.pc6.com/sof ...

  10. Python collections系列之默认字典

    默认字典(defaultdict)  defaultdict是对字典的类型的补充,它默认给字典的值设置了一个类型. 1.创建默认字典 import collections dic = collecti ...