项目简介及技术栈介绍
cms是一种为内容的创作、编辑、发布等量身定制的内容管理系统。
他的优势在于利用标签和后台管理能够使得前端的网页更好的、有条理的搭建起来。
涉及技术:
架构体系:分布式多模块
后端开发:SpringBoot
权限管理:Spring Security
单点登录:JWT
数据库:MySQL-8.0
缓存系统 :Redis
持久层框架 :Mybatis-plus
定时任务:Quartz
pc端前台开发:vue+FreeMarker
项目主要功能
项目中遇到的一些问题
1.前端利用vue集成ueditor
ueditor中的接口对返回数据的格式都有具体要求,请求不同的接口时会携带不同的action参数。
加载ueditor的时候携带的action参数为config返回cofig所有信息,刚刚渲染ueditor的时候就会执行
上传图片的时候携带的action为uploadimg 要求返回格式为
{ "state": "SUCCESS",
"url": "upload/demo.jpg",
"title": "demo.jpg",
"original": "demo.jpg" }
2.导出excel表格
public ResponseEntity<byte[]> exportStanding(@PathVariable Long formId) throws IOException {
//signupUserinfoService.exportExcel(signupId);
SmartForm byId = smartFormService.getById(formId);
QueryWrapper<FormData> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("form_id",formId);
List<Map<String, Object>> mapLists = formDataService.select(formId);
// 创建工作薄
HSSFWorkbook workbook = new HSSFWorkbook();
// 创建用户工作表
HSSFSheet sheet = workbook.createSheet("用户");
HSSFRow rows = sheet.createRow(0);
List<Map> mapList = new ArrayList<>();
HashMap<String, String> ha = new HashMap<>();
ha.put("form_title","用户名");
mapList.add(ha);
HashMap<String, String> ha1 = new HashMap<>();
ha1.put("form_title","省份");
mapList.add(ha1);
HashMap<String, String> ha2 = new HashMap<>();
ha2.put("form_title","IP");
mapList.add(ha2);
HashMap<String, String> ha3 = new HashMap<>();
ha3.put("form_title","参与时间");
mapList.add(ha3);
HashMap<String, String> ha4 = new HashMap<>();
ha4.put("form_title","系统标识");
mapList.add(ha4);
// 第 n 行 的表头
int j=0;
for (Map map : mapList) {
//创建列
rows.createCell(j).setCellValue((String) map.get("form_title"));
j++;
}
j=1;
// 第 n 行的数据
for (Map<String,Object> maps : mapLists) {
HSSFRow rowss = sheet.createRow(j);
int i=0;
for (Map map:mapList) {
//创建列
rowss.createCell(i).setCellValue((String)maps.get(map.get("form_title")));
i++;
}
j++;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
workbook.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
} finally {
outputStream.close();
}
HttpHeaders httpHeaders = new HttpHeaders();
String name = byId.getTitle()+".xls";
String fileName = new String(name.getBytes("UTF-8"), "iso-8859-1");
httpHeaders.setContentDispositionFormData("attachment", fileName);
httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
ResponseEntity<byte[]> filebyte = new ResponseEntity<byte[]>(outputStream.toByteArray(), httpHeaders, HttpStatus.CREATED);
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
outputStream.close();
}
return filebyte;
}
3.获取ip以及根据ip获取地址
public static String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
if (ip.equals("0:0:0:0:0:0:0:1")) {
ip = "本地";
}
return ip;
}
public String getAddresses(String content, String encodingString)
throws UnsupportedEncodingException {
// 这里调用接口
String urlStr = "http://whois.pconline.com.cn/ip.jsp";
// 从http://whois.pconline.com.cn取得IP所在的省市区信息
String returnStr = this.getResult(urlStr, content, encodingString);
if (returnStr != null) {
// 处理返回的省市区信息
String[] temp = returnStr.split(" ");
if(temp.length<2){
return "0";//无效IP
}String region = temp[0];
if(StringUtils.isEmpty(region) || region.trim().equals("")){
region = temp[1];
}
return region;
}
return "未知";
}
private String getResult(String urlStr, String content, String encoding) {
URL url = null;
HttpURLConnection connection = null;
try {
url = new URL(urlStr);
connection = (HttpURLConnection) url.openConnection();// 新建连接实例
connection.setConnectTimeout(2000);// 设置连接超时时间,单位毫秒
connection.setReadTimeout(2000);// 设置读取数据超时时间,单位毫秒
connection.setDoOutput(true);// 是否打开输出流 true|false
connection.setDoInput(true);// 是否打开输入流true|false
connection.setRequestMethod("POST");// 提交方法POST|GET
connection.setUseCaches(false);// 是否缓存true|false
connection.connect();// 打开连接端口
DataOutputStream out = new DataOutputStream(connection
.getOutputStream());// 打开输出流往对端服务器写数据
out.writeBytes(content);// 写数据,也就是提交你的表单 name=xxx&pwd=xxx
out.flush();// 刷新
out.close();// 关闭输出流
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream(), encoding));// 往对端写完数据对端服务器返回数据
// ,以BufferedReader流来读取
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
reader.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();// 关闭连接
}
}
return null;
}
4.一些细节
JSONObject json = (JSONObject) JSON.toJSON(one)
Iterator iter = jsonInfo.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
System.out.println(entry.getKey().toString());
System.out.println(entry.getValue().toString());
}
User user = new User();
user.setName("校长");
user.setAge(3);
user.setSalary(new BigDecimal("123456789.0123"));
/*对象转map*/
String jsonString1 = JSON.toJSONString(user);
Map map = JSON.parseObject(jsonString1, Map.class);
System.out.println("map = " + map);
// map = {name=校长, salary=123456789.0123, age=3}
String jsonString = JSON.toJSONString(map);
User user1 = JSON.parseObject(jsonString, User.class);
//json转对象
System.out.println("user1 = " + user1);
//user1 = User{name='校长', age=3, salary=123456789.0123}
- 如何自定义标签