后台
#查询时间
DATE_FORMAT(cp.begin_time,'%Y-%m-%d %H:%i:%S') AS begin_time //`begin_time` timestamp 2019-03-24 11:48:04 2019-03-24 11:48:04 后端用VARCHAR接收
FROM_UNIXTIME(a.create_time/1000) //`create_time` bigint(13) 1536144697878 2018-09-05 18:51:37.8780
使用@JSONField(format="yyyy-MM-dd")加在pojo中对应字段上,原来的long值就能变成日期格式,前提好像是有fastJson
wdatepicker默认时间 onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="<#if sendDateQi??>${sendDateQi?string("yyyy-MM-dd HH:mm:ss")}</#if>" //赋值
DateFormatUtils.format(date, pattern)
#springmvc的restFul风格
@RequestMapping("/gotoJifen/{operator}/{id}/{typeName}")
@PathVariable("operator")String operator
#like搜索
AND member_name LIKE concat('%',#{memberName},'%')
#查询中文字段
case
when sm.member_sex='1' then '男'
when sm.member_sex='2' then '女'
end '性别',
#查询与json数据比较
LEFT JOIN bus_point_get bpg ON bal.fee_detail LIKE CONCAT('%',bpg.order_no,'%') //fee_detail是json字段
#java8直接排序和设置结果
List<Integer> seriesData1=new ArrayList<>();
List<AccountDetail> es=accountDetailsMap.get(month);
seriesData1.set(month-1,es.stream()
.filter(e->StaticValue.CLAIM_INSURANCE_COMMON.equals(e.getInsuranceType()))
.collect(Collectors.groupingBy(AccountDetail::getOrderSn)).size());
#java8按月份分组
Map<Integer, List<AccountDetail>> accountDetailsMap = accountDetails.stream().collect(Collectors.groupingBy(AccountDetail::getMonth));
#将结果转成json
@ResponseBody 将结果以json格式返回 @RequestBody将json转成属性(可以是分开也可以是VO)例如:@RequestBody User
user,@RequestBody String goodsArray
$.ajax({
url:"/login",
type:"POST",
data:'{"userName":"admin","pwd","admin123"}',
content-type:"application/json charset=utf-8",
success:function(data){
alert("request success ! ");
}
});
@requestMapping("/login")
public void login(@requestBody String userName,@requestBody String pwd){
System.out.println(userName+" :"+pwd);
}
#用 JSON.stringify序列化后,然后发送,在服务器端接到然后用 JSON.parse 进行还原就行了
$.ajax({
dataType: 'json',
contentType: 'application/json',//发送给服务器的格式 dataType是收到服务器数据的格式
data: JSON.stringify({a: [{b:1, a:1}]})
})
#将json转成map(json对象而不是json串)
Map<String,Object> paramsMap = JSON.parseObject(params)
JSONObject retJSON = JSON.parseObject(ret);//字符串转成json对象
if ("000".equals(retJSON.getString("rescode")))
JSONObject jsoncontent = JSON.parseObject(resultFromMTJson.getString("content"));
JSONArray staffResults = jsoncontent.getJSONArray("staffResults");
JSON.toJSONString(staffResults);
for (Object obj:staffResults) {
((JSONObject)JSON.toJSON(obj)).getString("staffSerialNum");
}
#字符串判断
couponId.endsWith(",") substring
#将json转成类
List<ThirdGoods> goodsNames = JSONArray.parseArray(result.getGoodsName(), ThirdGoods.class);
其他
#git拉取
git clone url
git submodule update --init
#创建分支
在master分支上 git checkout -b dev_gaofei
#删除分支
git branch -d <BranchName>
git push origin -d BranchName
#重新编译
mvn clean compile -Dmaven.test.skip=true
前端
#简单的post提交表单
$.post(url,{id:id,typeName:typeName},function (data) {}) //String id,String typeName
$.ajax({
type:"post",
url:"${base}/health/api/getSimpleTjData",
data:{policyId:policyId,nomDate:nomDate,belongType:'1'},
dataType:"json",
success:function(data){
voidSimpleTjData(data.data);
}
});@RequestParam("policyId") String policyId, @RequestParam("nomDate") String nomDate,@RequestParam("belongType") String belongType
#页面赋值vo,前提params下的结构不管,但必须有<input name/>
var busPointSendVo = null;
$("#params [name]").each(function () {
var val = $(this).val();
var name = $(this).attr("name");
if (val) {
if (busPointSendVo == null) {
busPointSendVo = {};
}
busPointSendVo[name] = val;
}
});
#页面赋值json,直接使用
//index:page //offset:lastIndex(start) = pager.offset / lastSize + 1 直接封装到vo
var loadList = function () {
var jifenVo = null;
$("#params [name]").each(function () {
var val = $(this).val();
var name = $(this).attr("name");
if (val) {
if (jifenVo == null) {
jifenVo = {};
}
jifenVo[name] = val;
}
});
var pager = {offset: 0, size: 10};
var argc = arguments.length;
if (argc > 1) {
var size = arguments[1];
size = parseInt(size);
if (!isNaN(size) && size >= 0) {
pager.size = size;
}
}
if (argc > 0) {
var index = arguments[0];
index = parseInt(index);
if (!isNaN(index) && index > 0) {
pager.offset = (index - 1) * pager.size;
}
}
lastSize = pager.size;
lastIndex = pager.offset / lastSize + 1;
if (params) {
pager.params = params;
}
if (jifenVo == null) {
jifenVo = {};
}
jifenVo['offset'] = pager.offset;
jifenVo['size'] = pager.size;
$("#orderList").load("${base}/point/jifenXiangxiList", jifenVo, function () {
});
};
#遍历json
function initPolicyInfoList(data){
data.forEach(function (item) {
});
}
#定义全局变量保存最基础数据变更
success:function(data){
var policyIdData=data.data;
}
$(".divModal").click(function () {
$("#closeModule").click();
var indexVal=$(this).index();
initPolicyInfoData(policyListData[indexVal]);
});
//软件UltraEdit、DataGrip
#BigDecimal赋值
BigDecimal goodsAmount=goodsAmount.add(busMedicineGoods.getSellPrice().multiply(new BigDecimal(shopMedicineOrderGoods.getGoodsNum()+"")).setScale(2,BigDecimal.ROUND_HALF_UP));
BigDecimal orderAmount=new BigDecimal(String.valueOf(priceMap.get("orderAmount")));
#json取出
JSONArray getJsonArray=JSONArray.fromObject([{name1:{name2:{name3:'value1',name4:'value2'}}},{}]);//将结果转换成JSONArray对象的形式
JSONObject getJsonObj = getJsonArray.getJSONObject(0);//获取json数组中的第一项
String result=getJsonObj.getJSONObject("name1").getJSONObject("name2").getJSONObject("name4");
#jsonObject赋值
jsonObject.put("goodsId",cart.getGoodsId());
JSONArray goodsJsonArray = new JSONArray();
goodsJsonArray.add(jsonObject);
#GROUP_CONCAT使用
select SUBSTRING_INDEX(GROUP_CONCAT(stuName ORDER BY score ASC),',',1),min(score) as score,course from grade1 group by course;
substring_index(被截取字段,关键字,关键字出现的次数)
select substring_index("blog.jb51.net",".",2) as abstract from my_content_t
结果:blog.jb51
group_concat( [distinct] 要连接的字段 [order by 排序字段 asc/desc ] [separator '分隔符']
select name,GROUP_CONCAT(concat_ws('-',id,score)order by id) from t group by name
小明 1-80,5-50,6-70
小王 2-90,4-85
以stuName分组,把score字段的值打印在一行,逗号分隔(默认),我们只需要把这个字符串截取第一个人的名字就可以了,我们使用SUBSTRING_INDEX