java开发中遇到的问题

contains就是包含(abc中包含a)
equals就是相等(完全一样).
<![CDATA[<=]]>

jav8特性:
Map<String, SysDept> sysDeptMap=sysDeptList.stream().collect(Collectors.toMap(SysDept::getName, v -> v));
List<SysRoleMenu> roleMenuList = Arrays.stream(menuIds.split(",")).map(menuId -> {
SysRoleMenu roleMenu = new SysRoleMenu();
roleMenu.setRoleId(roleId);
roleMenu.setMenuId(Integer.valueOf(menuId));
return roleMenu;
}).collect(Collectors.toList());

List<Integer> dataType = StringUtils.isNotBlank(quotaLibrary.getDataType()) ? JSONArray.parseArray(quotaLibrary.getDataType(), Integer.TYPE) : new ArrayList<>();
list拼接字符串逗号拼接
String join = CollectionUtil.join(deptIds, ",");
String rules = StringUtils.join(ruleList, ",");
String.join(",", newFunctionStrs)
String转list
String[] split = rules.split(",");
List<String> ruleList = Arrays.asList(split);

String[] functionStrs = StrUtil.split(f.getFieldFunction(), ",");
List<String> functionStrs = CollUtil.toList(StrUtil.split(functionField.getFieldFunction(), ","));

//list转map
List<SysDept> sysDeptList = new SysDept().selectList(sysDeptQueryWrapper);
Map<String, SysDept> sysDeptMap = new HashMap<>();
if(CollUtil.isNotEmpty(sysDeptList)){
sysDeptMap=sysDeptList.stream().collect(Collectors.toMap(SysDept::getName, v -> v));
}
Map<Long, Long> interfaceDataMap = new HashMap<>();
interfaceDataMap = interfaceData.stream().collect(Collectors.toMap(GradeInterfaceData::getInterfaceId,GradeInterfaceData::getInterfaceId));
---------------------------------------直接执行当前方法-------------------------------------------------
List<TaskBaseMaterial> taskBaseMaterialList = new ArrayList<>();
newMaterialList.forEach(matMaterial -> {
TaskBaseMaterial taskBaseMaterial = new TaskBaseMaterial();
taskBaseMaterial.setTaskId(guideId);
taskBaseMaterial.setMaterialId(matMaterial.getId());
taskBaseMaterialList.add(taskBaseMaterial);
});

private static Map<String, String> map = new HashMap<>();
@Resource
private HttpSessionService httpSessionService;
static {
map.put("1", "getRadioMap");
map.put("2", "getRadioMap");
map.put("3", "getRadioMap");
map.put("4", "getRadioMap");
map.put("5", "getRadioMap");
// 获得填空类型的统计
map.put("6", "getFillMap");
// 获得多项填空类型的统计
map.put("7", "getMultiFillMap");
// 获得打分统计
map.put("8", "getGradeMap");
// 获得上传类型的统计
map.put("9", "getUploadMap");
}

@Override
@SuppressWarnings("unchecked")
public Map getStatistics(Long questionId) {
Map<String, Object> resultMap = new HashMap<>(16);
QuesQuestion quesQuestion = new QuesQuestion().selectById(questionId);
try {
if (map.containsKey(quesQuestion.getType())) {

resultMap = (Map<String, Object>) this.getClass()
.getDeclaredMethod(map.get(quesQuestion.getType()), Long.class).invoke(this, questionId);
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
resultMap.put("questionId", questionId);
resultMap.put("type", quesQuestion.getType());
resultMap.put("title", quesQuestion.getTitle());
resultMap.put("orderNumber", quesQuestion.getOrderNumber());
return resultMap;
}

 


菜单权限
@PreAuthorize("@pms.hasPermission('sys_dept_edit')")

and prcsTime!='0000-00-00 00:00:00'
//string转jsonobject 阿里转换
JSONObject jsonObject=new JSONObject();
jsonObject=JSONObject.parseObject(JSON.toJSONString(bean));
//string转list
List<GradeQuotaVO> quotaList=new ArrayList<>();
quotaList=JSONArray.parseArray(jsonObject.getJSONArray("quotaList").toJSONString(),GradeQuotaVO.class);

List<Integer> dataType = StringUtils.isNotBlank(quotaLibrary.getDataType()) ? JSONArray.parseArray(quotaLibrary.getDataType(), Integer.TYPE) : new ArrayList<>();


hutool转换jsonobject
String jsonStr = "{\"b\":\"value2\",\"c\":\"value3\",\"a\":\"value1\"}";
//方法一:使用工具类转换
JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
//方法二:new的方式转换
JSONObject jsonObject2 = new JSONObject(jsonStr);
//对象转换成json字符串
JSONUtil.toJsonStr()

//如果我们想获得格式化后的JSON
JSONUtil.toJsonPrettyStr(sortedMap);
//JSON字符串解析
String html = "{\"name\":\"Something must have been changed since you leave\"}";
JSONObject jsonObject = JSONUtil.parseObj(html);
jsonObject.getStr("name");
//XML字符串转换为JSON
String s = "<sfzh>123</sfzh><sfz>456</sfz><name>aa</name><gender>1</gender>";
JSONObject json = JSONUtil.parseFromXml(s);

json.get("sfzh");
json.get("name");
Copy to clipboardErrorCopied
//JSON转换为XML
final JSONObject put = JSONUtil.createObj()
.set("aaa", "你好")
.set("键2", "test");

// <aaa>你好</aaa><键2>test</键2>
final String s = JSONUtil.toXmlStr(put);
Copy to clipboardErrorCopied
//hutool转list
List<GradeInterfaceItem> interfaceItem = JSONUtil.toList(jsonArray.getJSONObject(i).getJSONArray("interfaceItem"), GradeInterfaceItem.class);

//JSON转Bean
我们先定义两个较为复杂的Bean(包含泛型)

@Data
public class ADT {
private List<String> BookingCode;
}

@Data
public class Price {
private List<List<ADT>> ADT;
}
Copy to clipboardErrorCopied
String json = "{\"ADT\":[[{\"BookingCode\":[\"N\",\"N\"]}]]}";

Price price = JSONUtil.toBean(json, Price.class);

//
price.getADT().get(0).get(0).getBookingCode().get(0);


SysDept sysDept = new SysDept();
BeanUtils.copyProperties(dept, sysDept);

//判断是否为空
ObjectUtil.isNotNull
//判断集合是否为空
CollUtil.isNotEmpty()

 

List<GradeInterfaceDTO> dtoList = new ArrayList<>();
list=new GradeInterface().selectList(queryWrapper);
if(list!=null&&!list.isEmpty()){
list.forEach(q -> {
//查询问题选项
GradeInterfaceDTO interfaceDTO = new GradeInterfaceDTO();
BeanUtils.copyProperties(q, interfaceDTO);
dtoList.add(interfaceDTO);
});
}

str=str.trim().replaceAll("\\u00A0","");

 

handleChooseByLib() {
// // @ts-ignore
exportGradeSystem(this.row.form.id).then(data=> {
let balo = data.data;
let url = window.URL.createObjectURL(new Blob([balo]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
const filename = decodeURI(data.headers['content-disposition'].split(';')[1].split('=')[1])
link.setAttribute('download', filename)
document.body.appendChild(link)
link.click()
});
},

if(CollUtil.isNotEmpty(quesAnswerList)){
如果曾经的数据都不需要的话,可以直接清空所有数据,并将自增字段恢复从1开始计数:

 

wrapper.apply("start_time <= '" + now + "' and '" + now + "' < end_time");

eq.last(" group by DATE_FORMAT(benchmark_date,'%Y-%m')");
QueryWrapper<AssessmentDeptTask> wrapper = new QueryWrapper<>();
LambdaQueryWrapper<QuesAnswer> wrapper = new LambdaQueryWrapper<>();
UpdateWrapper<QuesAnswer> uw = new UpdateWrapper<>();
uw.lambda().set(QuesAnswer::getDelFlag,1);
if(StringNullUtil.isNotBlankLong(String.valueOf(quesAnswer.getQuestionnaireId()))){
uw.lambda().eq(QuesAnswer::getId,quesAnswer.getQuestionnaireId());

list转单个stirng数组
List<Long> oldIds = list.stream().map(QuesQuestionTask::getId).collect(Collectors.toList());
list转JSONARRAY
dnaAnswerList.stream().map(QuesAnswer::getContent).map(JSON::parseArray).toArray()
//?:0或1个, *:0或多个, +:1或多个
Boolean strResult = str.matches("^[-\\+]?([0-9]+\\.?)?[0-9]+$");
//获取最大的部门id
Integer parentId = deptAllList.stream().max(Comparator.comparing(SysDept::getParentId)).get().getParentId();
// 获取最大值
Optional<GradeQuota> userOp = gradeQuotaList.stream().max(Comparator.comparingInt(GradeQuota::getQuotaLevel));
gradeQuotaList.stream().filter(gradeQuota -> gradeQuota.getHasSon() == 0).map(GradeQuota::getId).collect(Collectors.toSet()));
tableData = tableData.stream().sorted(Comparator.comparing(jsonObject -> StringNullUtil.isNotBlank((jsonObject).getString("id1Sort"))?(jsonObject).getInteger("id1Sort"):0)).collect(Collectors.toList());
//去不掉的空格
List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
tableData=tableData.stream().sorted(Comparator.comparing(jsonObject -> ((JSONObject) jsonObject).getInteger("id1"))).collect(Collectors.toList());


List<SysDept> deptAllList = deptMapper.selectList(Wrappers.<SysDept>query().lambda().eq(SysDept::getCityId,sysDept.getCityId()));
// 查询全部部门
// List<DeptTree> deptList = deptMapper.selectList(Wrappers.emptyWrapper()).stream().filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
// .sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
// DeptTree node = new DeptTree();
// node.setId(dept.getDeptId());
// node.setParentId(dept.getParentId());
// node.setName(dept.getName());
// return node;
// }).collect(Collectors.toList());
// 权限内部门
List<DeptTree> collect = deptAllList.stream().filter(dept -> dept.getDeptId().intValue() != dept.getParentId())
.sorted(Comparator.comparingInt(SysDept::getSort)).map(dept -> {
DeptTree node = new DeptTree();
node.setId(dept.getDeptId());
node.setParentId(dept.getParentId());
node.setName(dept.getName());
return node;
}).collect(Collectors.toList());

//java8 filter 用法
1.输出符合表达式的每一个对象
employees.stream().filter(p -> p.getAge() > 21).forEach(System.out::println);
//输出每一个对象
1
2
2.返回一个符合表达式的集合
Stream<Person> personStream = collection.stream().filter(new Predicate<Person>() {
@Override
public boolean test(Person person) {
return "男".equals(person.getGender());//只保留男性
}
});
collection = personStream.collect(Collectors.toList());//将Stream转化为List
System.out.println(collection.toString());//查看结果


String str = Joiner.on(",").join(ids);

UpdateWrapper<GradeSystem> uw = new UpdateWrapper<GradeSystem>();
uw.lambda().set(GradeSystem::getDelFlag,1);
uw.lambda().in(GradeSystem::getId,ids);
this.update(uw);


int num=1;
if(list.size()>0){
// 获取最大值
Optional<GradeQuotaRuleCustom> gradeVersions = list.stream().max(Comparator.comparingDouble(GradeQuotaRuleCustom::getRuleSort));
GradeQuotaRuleCustom gq = gradeVersions.get();
num = gq.getRuleSort()+1;
}
前面有数据 后面为空

这是权限 加上注解后前端判断
@PreAuthorize("@pms.hasPermission('sys_user_del')")

如何控制菜单权限控制
在后台菜单管理中给指定菜单添加 按钮节点 需要指定 权限标志

例如: sys_file_add、sys_file_del、sys_file_edit
前端CRUD 会自定生成关联按钮,只需要在 computed 生命周期注入对应的权限标识。
若扩展菜单 (非增删改查),则使用vuex保存用户的权限信息,然后通过v-if 判断是否有权限,如果有权限就渲染这个dom元素。 例如:ext_btn


public void doGet(HttpServletRequest request, HttpServletResponse response)
15 throws ServletException, IOException {
16 /**
17 * 1.获得客户机信息
18 */
19 String requestUrl = request.getRequestURL().toString();//得到请求的URL地址
20 String requestUri = request.getRequestURI();//得到请求的资源
21 String queryString = request.getQueryString();//得到请求的URL地址中附带的参数
22 String remoteAddr = request.getRemoteAddr();//得到来访者的IP地址
23 String remoteHost = request.getRemoteHost();
24 int remotePort = request.getRemotePort();
25 String remoteUser = request.getRemoteUser();
26 String method = request.getMethod();//得到请求URL地址时使用的方法
27 String pathInfo = request.getPathInfo();
28 String localAddr = request.getLocalAddr();//获取WEB服务器的IP地址
29 String localName = request.getLocalName();//获取WEB服务器的主机名
30 response.setCharacterEncoding("UTF-8");//设置将字符以"UTF-8"编码输出到客户端浏览器
31 //通过设置响应头控制浏览器以UTF-8的编码显示数据,如果不加这句话,那么浏览器显示的将是乱码
32 response.setHeader("content-type", "text/html;charset=UTF-8");
33 PrintWriter out = response.getWriter();
!<%=AccountShiroUtil.getCurrentUser().getId()%>==scope.row.dutyPerson


@PostMapping("reset")
public R reset(@Valid @RequestBody DemResetSdeptVo demResetSdept) {


let mainOrgName = this.orgName(mainOrg);
if (mainOrgName.length > 5) {
return mainOrgName.slice(0,5) + '...'
}

UserVO user=com.gov.dna.common.util.shiro.ShiroUtils.getCurrentUser();
/*if(permissionScopeService.hasPermission(GovStringUtils.removeBothEndsComma(user.getRoles()),"/view/grade/quotaManage/index","100")){
if (temp.getId().equals(user.getMainOrg())) {
deptTableList.add(tempObj);
}
} else {
deptTableList.add(tempObj);
}*/

搜大数据
else if("1".equals(AccountShiroUtil.getCurrentUser().getAuditManagement())&&isSelect&&isPerson){
//管理员权限只有全部才能查他部门下的
if(o.getSearchScope()!=null&&o.getSearchScope().intValue()==0){

}else{
o.setDutyCompanys(companyService.companyChildren(AccountShiroUtil.getCurrentUser().getCompanyId()));
if(o.getSearchScope()!=null&&(o.getSearchScope().intValue()==3||o.getSearchScope().intValue()==2)){
o.setDutyPerson(String.valueOf(AccountShiroUtil.getCurrentUser().getId()));
}
}
}

posted @   全琪俊  阅读(381)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!
点击右上角即可分享
微信分享提示