java实用小技巧
1.返回上一层页面
<a class="btn btn-default" onclick="window.history.back(-1);" >上一步</a>
页面小技巧
location.history.go
https://blog.youkuaiyun.com/hao1993015/article/details/81127824
2.判难内容当中的值是否大于0
if (bzEvaluationTemplate_image.size()>0){
bzEvaluationTemplate.setImageUrl("http://oss.6noble.com/"+bzEvaluationTemplate_image.get(0).getFileEntity().getFileId());
super.update(bzEvaluationTemplate);
}
3.onclick事件
<a href="javascript.void(0);" onclick="submitForm('${pid}');return false;" class="btn" title="${text('保存题目')}"><i class="fa fa-plus"></i> ${text('保存题目')}</a>
function submitForm(pid){
$.ajax({
url: "${ctx}/questionBank/bzTemplateDetail/saveQuestion",
data: {formNo:pid},
type: "post",
success: function () {
//console.log("<<<<<<<<<<")
$("#dataGrid").trigger("reloadGrid");// 刷新整个列表
}
})
}
4.刷新整个页面
$("#dataGrid").trigger("reloadGrid");// 刷新整个列表
5.bootstrap设置不能为空
<#form:input path="durationMin" maxlength="11" blankOption="true" class="form-control digits required"/>
6.controller层返回值页面展示
success: function (res) {
js.showMessage(res.message);
//console.log("<<<<<<<<<<")
$("#dataGrid").trigger("reloadGrid");// 刷新整个列表
}
7.判断是否为空
if(model.getPid().equals("") || model.getPid().isEmpty() StringUtils.isNotBlank()){
判断为空 isNotBlank 不为空 isBlank
8.强转String类型
bzSite.setId(String.valueOf(System.currentTimeMillis()));
9.判断前端传过来的实体是否是新纪录的方法
if(bzFacility.getIsNewRecord()){
bzFacility.setPid(pid);
}
10.生成随机数
String id= IdGen.nextId().substring(3,7); 截取
11.日志打印
声明:
private static Logger log = Logger.getLogger(BzSiteController.class);
打印:
日志
log.info(bzSite.getSiteName()+"++++++++++++++++++++++++++++++++++++++++++");
错误日志
log.error(bzSite.getSiteName()+"------------------------------------------");
11.判断是否包含
if (sendMode.contains(".com")){
12.double类型好评率-取小数点后两位
String.format("%.2f",feedBack)
bzCounselor.setFeedBack(String.format("%.2f",feedBack) + "%");
13.service层条件查询
BzComment bzComment = new BzComment();
bzComment.setCounselorId(employeeId);
bzComment.getSqlMap().getWhere().and("comment_score", QueryType.GTE,3);
long goodCount = super.findCount(bzComment);
return goodCount;
split 使用
.split(“o”)[0]得到的是第一个o之前的内容
.split(“o”)[1]得到的是第一个o和第二个o之间的内容
.split(“o”)[3]得到的是第三个o后和第四个o前之间的内容
.split("[")[0]得到的是第一个 [ 之前的内容
删除头尾空格
.trim()
不同类型的加减对比
如果指定的数与参数相等返回0。
如果指定的数小于参数返回 -1。
如果指定的数大于参数返回 1。
例:aaa.compareTo(某数 > 0 或 < 或 = 或 != 某某值)
去掉小数
.intValue()
StringBuffer的delete方法与deleteCharAt的区别
delete方法与deleteCharAt两个方法都是用来删除StringBuffer字符串指定索引字符的方法;
delete(int a,int b)有两个参数,使用时删除索引从a开始(包含a)到b(不包含b)的所有字符;
deleteCharAt(int a)只有一个参数,使用时删除索引为a的字符;
springboot启动类配置—>禁止 SpringBoot 自动注入数据源配置
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
list升序降序排列(默认是升序,reverseOrder()改为降序)
Collections.sort(需要排序的list,Collections.reverseOrder());