最近在自己研究,项目中用springmvc+mybatis,返回用@responsebody自动处理json,Jackson在解析返回的json字符串时始首字母是小写。网上查了很多资料,才找到解决方法
package cn.zshake.mvcdemo.bean;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
public class TSpYjLore implements java.io.Serializable {
/**
*表对应的bean
*/
private static final long serialVersionUID = -1554890848450462359L;
@JsonProperty("ORG")
private String ORG;
@JsonProperty("LORE_ID")
private String LORE_ID;
@JsonProperty("LORE_NO")
private String LORE_NO;
@JsonProperty("LORE_TITLE")
private String LORE_TITLE;
@JsonProperty("LORE_TYPE")
private String LORE_TYPE;
@JsonProperty("AUTHOR")
private String AUTHOR;
@JsonProperty("EDITOR")
private String EDITOR;
@JsonProperty("EDIT_DATE")
private String EDIT_DATE;
@JsonProperty("SOLUTION")
private String SOLUTION;
@JsonProperty("CREATE_DATE")
private String CREATE_DATE;
@JsonProperty("STATE_DATE")
private String STATE_DATE;
@JsonProperty("STATE")
private String STATE;
@JsonIgnore
public String getORG() {
return ORG;
}
@JsonIgnore
public void setORG(String oRG) {
ORG = oRG;
}
@JsonIgnore
public String getLORE_ID() {
return LORE_ID;
}
@JsonIgnore
public void setLORE_ID(String lORE_ID) {
LORE_ID = lORE_ID;
}
@JsonIgnore
public String getLORE_NO() {
return LORE_NO;
}
@JsonIgnore
public void setLORE_NO(String lORE_NO) {
LORE_NO = lORE_NO;
}
@JsonIgnore
public String getLORE_TITLE() {
return LORE_TITLE;
}
@JsonIgnore
public void setLORE_TITLE(String lORE_TITLE) {
LORE_TITLE = lORE_TITLE;
}
@JsonIgnore
public String getLORE_TYPE() {
return LORE_TYPE;
}
@JsonIgnore
public void setLORE_TYPE(String lORE_TYPE) {
LORE_TYPE = lORE_TYPE;
}
@JsonIgnore
public String getAUTHOR() {
return AUTHOR;
}
@JsonIgnore
public void setAUTHOR(String aUTHOR) {
AUTHOR = aUTHOR;
}
@JsonIgnore
public String getEDITOR() {
return EDITOR;
}
@JsonIgnore
public void setEDITOR(String eDITOR) {
EDITOR = eDITOR;
}
@JsonIgnore
public String getEDIT_DATE() {
return EDIT_DATE;
}
@JsonIgnore
public void setEDIT_DATE(String eDIT_DATE) {
EDIT_DATE = eDIT_DATE;
}
@JsonIgnore
public String getSOLUTION() {
return SOLUTION;
}
@JsonIgnore
public void setSOLUTION(String sOLUTION) {
SOLUTION = sOLUTION;
}
@JsonIgnore
public String getCREATE_DATE() {
return CREATE_DATE;
}
@JsonIgnore
public void setCREATE_DATE(String cREATE_DATE) {
CREATE_DATE = cREATE_DATE;
}
@JsonIgnore
public String getSTATE_DATE() {
return STATE_DATE;
}
@JsonIgnore
public void setSTATE_DATE(String sTATE_DATE) {
STATE_DATE = sTATE_DATE;
}
@JsonIgnore
public String getSTATE() {
return STATE;
}
@JsonIgnore
public void setSTATE(String sTATE) {
STATE = sTATE;
}
@Override
public String toString() {
return "TSpYjLore [ORG=" + ORG + ", LORE_ID=" + LORE_ID + ", LORE_NO="
+ LORE_NO + ", LORE_TITLE=" + LORE_TITLE + ", LORE_TYPE="
+ LORE_TYPE + ", AUTHOR=" + AUTHOR + ", EDITOR=" + EDITOR
+ ", EDIT_DATE=" + EDIT_DATE + ", SOLUTION=" + SOLUTION
+ ", CREATE_DATE=" + CREATE_DATE + ", STATE_DATE=" + STATE_DATE
+ ", STATE=" + STATE + "]";
}
}
这样出口返回的json就是全部大写的了:
{"dateFormat":"yyyy-MM-dd","items":[{"ORG":null,"LORE_ID":"2","LORE_NO":"1212","LORE_TITLE":"34","LORE_TYPE"
:"应急知识","AUTHOR":"zshake","EDITOR":"
","EDIT_DATE":"2013-06-03","SOLUTION":"zshake
zshake
","CREATE_DATE":null,"STATE_DATE":null,"STATE":null},{"ORG":null,"LORE_ID":"3","LORE_NO":"35435"
,"LORE_TITLE":"4543","LORE_TYPE":"应急知识","AUTHOR":"4354","EDITOR":"543","EDIT_DATE":"2013-06-02","SOLUTION"
:"435","CREATE_DATE":null,"STATE_DATE":null,"STATE":null},{"ORG":null,"LORE_ID":"1","LORE_NO":"423432"
,"LORE_TITLE":"423","LORE_TYPE":"应急知识","AUTHOR":"23423","EDITOR":"432432","EDIT_DATE":"2013-06-02","SOLUTION"
:"324","CREATE_DATE":null,"STATE_DATE":null,"STATE":null}],"total":"11"}