mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
纯粹的图床网站
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package cn.hellohao;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@SpringBootApplication
|
||||
@Configuration
|
||||
public class TbedApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TbedApplication.class, args);
|
||||
|
||||
}
|
||||
/**
|
||||
* 文件上传配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public MultipartConfigElement multipartConfigElement() {
|
||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
// 单个数据大小
|
||||
factory.setMaxFileSize("102400KB"); // KB,MB
|
||||
/// 总上传数据大小
|
||||
factory.setMaxRequestSize("102400KB");
|
||||
return factory.createMultipartConfig();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package cn.hellohao.controller;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.pojo.vo.PageResultBean;
|
||||
import cn.hellohao.service.ImgService;
|
||||
import cn.hellohao.service.KeysService;
|
||||
import cn.hellohao.service.UserService;
|
||||
import cn.hellohao.service.impl.ImgServiceImpl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admin")
|
||||
public class AdminController {
|
||||
|
||||
@Autowired
|
||||
private ImgService imgService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
// 进入后台页面
|
||||
@RequestMapping(value = "/admin.do")
|
||||
public String goadmin(HttpSession session, Model model, HttpServletRequest request) {
|
||||
Integer storageType1 = (Integer) session.getAttribute("storageType");
|
||||
Integer storageType = keysService.selectKeysType();
|
||||
Keys key = keysService.selectKeys(storageType);
|
||||
User u = (User) session.getAttribute("user");
|
||||
if(u.getLevel()>1) {
|
||||
model.addAttribute("counts", imgService.counts(null));
|
||||
model.addAttribute("getUserTotal", userService.getUserTotal());
|
||||
}else {
|
||||
model.addAttribute("counts", imgService.countimg(u.getId()));
|
||||
}
|
||||
model.addAttribute("username", u.getUsername());
|
||||
model.addAttribute("level", u.getLevel());
|
||||
model.addAttribute("email", u.getEmail());
|
||||
model.addAttribute("loginid", 100);
|
||||
//key信息
|
||||
model.addAttribute("AccessKey", key.getAccessKey());
|
||||
model.addAttribute("AccessSecret", key.getAccessSecret());
|
||||
model.addAttribute("Endpoint", key.getEndpoint());
|
||||
model.addAttribute("Bucketname", key.getBucketname());
|
||||
model.addAttribute("RequestAddress", key.getRequestAddress());
|
||||
model.addAttribute("StorageType", storageType);
|
||||
model.addAttribute("text_foot", "<li><a href=\"http://www.hellohao.cn/\" target=\"_blank\">Hellohao ©</a></li><li>切勿上传违反中华人民共和国互联网法律条约资源</li>");
|
||||
if (u.getLevel() > 1) {
|
||||
model.addAttribute("htgl",
|
||||
"<input id=\"isadmin\" onclick=\"openLoginModal();\" class=\"btn btn-default\" type=\"button\" value=\"后台管理\">");
|
||||
}
|
||||
return "admin/table";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/selecttable.do")
|
||||
@ResponseBody
|
||||
public PageResultBean<Images> selectByFy(HttpSession session, Integer pageNum, Integer pageSize) {
|
||||
User u = (User) session.getAttribute("user");
|
||||
// 使用Pagehelper传入当前页数和页面显示条数会自动为我们的select语句加上limit查询
|
||||
// 从他的下一条sql开始分页
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<Images> images = null;
|
||||
if(u.getLevel()>1){ //根据用户等级查询管理员查询所有的信息
|
||||
images = imgService.selectimg(null);// 这是我们的sql
|
||||
}else{
|
||||
images = imgService.selectimg(u.getId());// 这是我们的sql
|
||||
}
|
||||
// 使用pageInfo包装查询
|
||||
PageInfo<Images> rolePageInfo = new PageInfo<>(images);//
|
||||
return new PageResultBean<>(rolePageInfo.getTotal(), rolePageInfo.getList());
|
||||
}
|
||||
|
||||
@PostMapping("/updatekey.do")
|
||||
@ResponseBody
|
||||
public String updatekey(Keys key) {
|
||||
Integer ret = keysService.updateKey(key);
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.add(ret);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
@PostMapping("/deleimg.do")
|
||||
@ResponseBody
|
||||
public String deleimg(HttpSession session,Integer id) {
|
||||
Integer storageType = (Integer) session.getAttribute("storageType");
|
||||
Images images = imgService.selectByPrimaryKey(id);
|
||||
Keys key = keysService.selectKeys(storageType);
|
||||
ImgServiceImpl de = new ImgServiceImpl();
|
||||
de.delect(key, images.getImgname());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Integer ret = imgService.deleimg(id);
|
||||
jsonArray.add(ret);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
//修改资料
|
||||
@PostMapping("/change.do")
|
||||
@ResponseBody
|
||||
public String change(HttpSession session,User user) {
|
||||
System.out.println(user.getUsername());
|
||||
Integer count = userService.checkUsername(user.getUsername());
|
||||
User u = (User) session.getAttribute("user");
|
||||
user.setEmail(u.getEmail());
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
if(count==0) {
|
||||
Integer ret = userService.change(user);
|
||||
jsonArray.add(ret);
|
||||
if(u.getEmail()!=null&&u.getPassword()!=null) {
|
||||
session.removeAttribute("user");
|
||||
//刷新view
|
||||
session.invalidate();
|
||||
}
|
||||
|
||||
}else {
|
||||
jsonArray.add("-1");
|
||||
}
|
||||
// -1 用户名重复
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/images/{id}")
|
||||
@ResponseBody
|
||||
public Images selectByFy(@PathVariable("id") Integer id) {
|
||||
return imgService.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package cn.hellohao.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.KeysService;
|
||||
import cn.hellohao.service.UserService;
|
||||
import cn.hellohao.service.impl.NOSImageupload;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
|
||||
@Controller
|
||||
public class UpdateImgController {
|
||||
@Autowired
|
||||
private NOSImageupload nOSImageupload;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private KeysService keysService;
|
||||
|
||||
|
||||
public static String getSubString(String text, String left, String right) {
|
||||
String result = "";
|
||||
int zLen;
|
||||
if (left == null || left.isEmpty()) {
|
||||
zLen = 0;
|
||||
} else {
|
||||
zLen = text.indexOf(left);
|
||||
if (zLen > -1) {
|
||||
zLen += left.length();
|
||||
} else {
|
||||
zLen = 0;
|
||||
}
|
||||
}
|
||||
int yLen = text.indexOf(right, zLen);
|
||||
if (yLen < 0 || right == null || right.isEmpty()) {
|
||||
yLen = text.length();
|
||||
}
|
||||
result = text.substring(zLen, yLen);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping({"/","/index.do"})
|
||||
public String indexImg(Model model,HttpServletRequest request,HttpSession httpSession){
|
||||
Integer storageType = keysService.selectKeysType();
|
||||
System.out.println("类型=========="+storageType);
|
||||
Keys key = keysService.selectKeys(storageType);
|
||||
nOSImageupload.Initialize(key);
|
||||
//查询哪种对象存储
|
||||
httpSession.setAttribute("storageType", storageType);
|
||||
|
||||
model.addAttribute("text_foot", "<li><a href=\"http://www.hellohao.cn/\" target=\"_blank\">Hellohao ©</a></li><li>切勿上传违反中华人民共和国互联网法律条约资源</li>");
|
||||
User u = (User) httpSession.getAttribute("user");
|
||||
String email = (String) httpSession.getAttribute("email");
|
||||
String pass = (String) httpSession.getAttribute("pass");
|
||||
if(email!=null && pass!=null) {
|
||||
//登陆成功
|
||||
Integer ret = userService.login(u.getEmail(), u.getPassword());
|
||||
if(ret>0) {
|
||||
User user = userService.getUsers(u.getEmail());
|
||||
model.addAttribute("username",user.getUsername());
|
||||
model.addAttribute("level",user.getLevel());
|
||||
model.addAttribute("loginid",100);
|
||||
model.addAttribute("imgcount",3);
|
||||
model.addAttribute("fileSize",5120);
|
||||
|
||||
}else {
|
||||
model.addAttribute("loginid",-1);
|
||||
model.addAttribute("imgcount",1);
|
||||
}
|
||||
}else {
|
||||
model.addAttribute("loginid",-2);
|
||||
model.addAttribute("imgcount",1);
|
||||
model.addAttribute("imgcount",1);
|
||||
model.addAttribute("fileSize",3072);
|
||||
|
||||
}
|
||||
return "index";
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value="/upimg.do")
|
||||
@ResponseBody
|
||||
public String exit(HttpServletRequest request,HttpServletResponse response,HttpSession session
|
||||
,@RequestParam(value = "file", required = false) MultipartFile[] file,String filename) throws Exception{
|
||||
long stime = System.currentTimeMillis();
|
||||
User u = (User) session.getAttribute("user");
|
||||
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Map<String, MultipartFile> map = new HashMap<>();
|
||||
for (MultipartFile multipartFile : file) {
|
||||
//获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
String lastname = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
if (!multipartFile.isEmpty()) { //判断文件是否为空
|
||||
map.put(lastname, multipartFile);
|
||||
//multipartFile.getOriginalFilename(); //文件名
|
||||
//multipartFile.getSize(); //文件大小
|
||||
}
|
||||
}
|
||||
Map<String, Integer> m =nOSImageupload.Imageupload(map);
|
||||
Images img = new Images();
|
||||
// for (String string : m) {
|
||||
// jsonArray.add(string);
|
||||
// System.out.println("文件名字:==="+string);
|
||||
// if(userid!=null) {
|
||||
// //img.setImgname(imgname);//图片名字
|
||||
// img.setImgurl(string);//图片链接
|
||||
// img.setUserid(userid);//用户id
|
||||
// userService.insertimg(img);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
for (Map.Entry<String, Integer> entry : m.entrySet()) {
|
||||
jsonArray.add(entry.getKey());
|
||||
if(u!=null) {
|
||||
//img.setImgname(imgname);//图片名字
|
||||
|
||||
img.setImgurl(entry.getKey());//图片链接
|
||||
img.setUserid(u.getId());//用户id
|
||||
img.setSizes((entry.getValue())/1024);
|
||||
img.setImgname(getSubString(entry.getKey(), "hellohao.nos-eastchina1.126.net/", ""));
|
||||
userService.insertimg(img);
|
||||
long etime = System.currentTimeMillis();
|
||||
System.out.println("上传图片所用时长:"+String.valueOf(etime-stime)+"ms");
|
||||
}
|
||||
}
|
||||
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.hellohao.controller;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.UserService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@RequestMapping("/register.do")
|
||||
@ResponseBody
|
||||
public String Register(User user) {
|
||||
//取当前时间
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
|
||||
String birthder = df.format(new Date());// new Date()为获取当前系统时间
|
||||
user.setLevel(1);
|
||||
user.setBirthder(birthder);
|
||||
Integer ret = userService.register(user);
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.add(ret);
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
@RequestMapping("/login.do")
|
||||
@ResponseBody
|
||||
public String login(HttpServletRequest request,HttpSession httpSession,String email,String password) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
|
||||
Integer ret = userService.login(email, password);
|
||||
if(ret>0) {
|
||||
jsonArray.add(1);
|
||||
User user = userService.getUsers(email);
|
||||
httpSession.setAttribute("user",user);
|
||||
httpSession.setAttribute("email",user.getEmail());
|
||||
httpSession.setAttribute("pass",user.getPassword());
|
||||
|
||||
//登录成功之后把账号密码存入session
|
||||
|
||||
}else {
|
||||
jsonArray.add(0);
|
||||
}
|
||||
return jsonArray.toString();
|
||||
}
|
||||
//退出
|
||||
@RequestMapping(value="/exit.do")
|
||||
@ResponseBody
|
||||
public String exit(Model model,HttpServletRequest request,HttpSession session){
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//注销,移除session
|
||||
User user = (User) session.getAttribute("user");
|
||||
if(user.getEmail()!=null&&user.getPassword()!=null) {
|
||||
session.removeAttribute(user.getEmail());
|
||||
session.removeAttribute(user.getPassword());
|
||||
//刷新view
|
||||
session.invalidate();
|
||||
jsonObject.put("exit", 1);
|
||||
}
|
||||
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.hellohao.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
|
||||
@Mapper
|
||||
public interface ImgMapper {
|
||||
|
||||
List<Images> selectimg(@Param("userid") Integer userid);
|
||||
Integer countimg(@Param("userid") Integer userid);
|
||||
Integer deleimg(@Param("id") Integer id);
|
||||
Images selectByPrimaryKey(@Param("id") Integer id);
|
||||
Integer counts(@Param("userid") Integer userid);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.hellohao.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
|
||||
@Mapper
|
||||
public interface KeysMapper {
|
||||
//查询密钥
|
||||
Keys selectKeys(@Param("storageType") Integer storageType);
|
||||
//查询key类型
|
||||
Integer selectKeysType();
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.hellohao.dao;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.User;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
//注册
|
||||
Integer register(User user);
|
||||
//登录
|
||||
Integer login(@Param("email") String email,@Param("password") String password);
|
||||
//获取用户信息
|
||||
User getUsers(@Param("email") String email);
|
||||
//插入图片
|
||||
Integer insertimg(Images img);
|
||||
//修改资料
|
||||
Integer change(User user);
|
||||
//检查用户名是否重复
|
||||
Integer checkUsername(@Param("username") String username);
|
||||
Integer getUserTotal();
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.hellohao.interceptor;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
@Component
|
||||
public class InterceptorConfig implements HandlerInterceptor{
|
||||
//private static final Logger log = LoggerFactory.getLogger(InterceptorConfig.class);
|
||||
|
||||
/**
|
||||
* 进入controller层之前拦截请求
|
||||
*/
|
||||
//这个方法是在访问接口之前执行的,我们只需要在这里写验证登陆状态的业务逻辑,就可以在用户调用指定接口之前验证登陆状态了
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
//每一个项目对于登陆的实现逻辑都有所区别,我这里使用最简单的Session提取User来验证登陆。
|
||||
HttpSession session = request.getSession();
|
||||
//这里的User是登陆时放入session的
|
||||
String email = (String) session.getAttribute("email");
|
||||
//如果session中没有user,表示没登陆
|
||||
if (email == null){
|
||||
//这个方法返回false表示忽略当前请求,如果一个用户调用了需要登陆才能使用的接口,如果他没有登陆这里会直接忽略掉
|
||||
//当然你可以利用response给用户返回一些提示信息,告诉他没登陆
|
||||
System.out.println("没有登录权限");
|
||||
request.getRequestDispatcher("/index.do").forward(request,response);
|
||||
return false;
|
||||
}else {
|
||||
System.out.println("进入成功");
|
||||
return true; //如果session里有user,表示该用户已经登陆,放行,用户即可继续调用自己需要的接口
|
||||
}
|
||||
}
|
||||
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
|
||||
}
|
||||
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.hellohao.interceptor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class WebAppConfig implements WebMvcConfigurer {
|
||||
|
||||
|
||||
@Autowired
|
||||
private InterceptorConfig interceptorConfig;
|
||||
|
||||
|
||||
// 这个方法是用来配置静态资源的,比如html,js,css,等等
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
}
|
||||
|
||||
// 这个方法用来注册拦截器,我们自己写好的拦截器需要通过这里添加注册才能生效
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
||||
// addPathPatterns("/**") 表示拦截所有的请求,
|
||||
// excludePathPatterns("/login", "/register") 表示除了登陆与注册之外,因为登陆注册不需要登陆也可以访问
|
||||
//registry.addInterceptor(interceptorConfig).addPathPatterns("admin/**").excludePathPatterns("/login", "/register");
|
||||
registry.addInterceptor(interceptorConfig).addPathPatterns("/admin/**");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
public class Images {
|
||||
// 默认的时间字符串格式
|
||||
|
||||
//id, imgname, imgurl, userid
|
||||
private Integer id;
|
||||
private String imgname;
|
||||
private String imgurl;
|
||||
private Integer userid;
|
||||
private Integer sizes=0;
|
||||
private Date updatetime;
|
||||
private Integer storageType;
|
||||
|
||||
|
||||
public Images() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public Images(Integer id, String imgname, String imgurl, Integer userid, Integer sizes, Date updatetime,
|
||||
Integer storageType) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.imgname = imgname;
|
||||
this.imgurl = imgurl;
|
||||
this.userid = userid;
|
||||
this.sizes = sizes;
|
||||
this.updatetime = updatetime;
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getImgname() {
|
||||
return imgname;
|
||||
}
|
||||
|
||||
|
||||
public void setImgname(String imgname) {
|
||||
this.imgname = imgname;
|
||||
}
|
||||
|
||||
|
||||
public String getImgurl() {
|
||||
return imgurl;
|
||||
}
|
||||
|
||||
|
||||
public void setImgurl(String imgurl) {
|
||||
this.imgurl = imgurl;
|
||||
}
|
||||
|
||||
|
||||
public Integer getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
|
||||
public void setUserid(Integer userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
|
||||
public Integer getSizes() {
|
||||
return sizes;
|
||||
}
|
||||
|
||||
|
||||
public void setSizes(Integer sizes) {
|
||||
this.sizes = sizes;
|
||||
}
|
||||
|
||||
|
||||
public Date getUpdatetime() {
|
||||
return updatetime;
|
||||
}
|
||||
|
||||
|
||||
public void setUpdatetime(Date updatetime) {
|
||||
this.updatetime = updatetime;
|
||||
}
|
||||
|
||||
|
||||
public Integer getStorageType() {
|
||||
|
||||
return storageType;
|
||||
}
|
||||
|
||||
|
||||
public void setStorageType(Integer storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class Keys {
|
||||
private Integer id;
|
||||
private String AccessKey;
|
||||
private String AccessSecret;
|
||||
private String Endpoint;
|
||||
private String Bucketname;
|
||||
private String RequestAddress;
|
||||
private Integer storageType;
|
||||
|
||||
public Keys() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Keys(Integer id, String accessKey, String accessSecret, String endpoint, String bucketname,
|
||||
String requestAddress, Integer storageType) {
|
||||
super();
|
||||
this.id = id;
|
||||
AccessKey = accessKey;
|
||||
AccessSecret = accessSecret;
|
||||
Endpoint = endpoint;
|
||||
Bucketname = bucketname;
|
||||
RequestAddress = requestAddress;
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAccessKey() {
|
||||
return AccessKey;
|
||||
}
|
||||
|
||||
public void setAccessKey(String accessKey) {
|
||||
AccessKey = accessKey;
|
||||
}
|
||||
|
||||
public String getAccessSecret() {
|
||||
return AccessSecret;
|
||||
}
|
||||
|
||||
public void setAccessSecret(String accessSecret) {
|
||||
AccessSecret = accessSecret;
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return Endpoint;
|
||||
}
|
||||
|
||||
public void setEndpoint(String endpoint) {
|
||||
Endpoint = endpoint;
|
||||
}
|
||||
|
||||
public String getBucketname() {
|
||||
return Bucketname;
|
||||
}
|
||||
|
||||
public void setBucketname(String bucketname) {
|
||||
Bucketname = bucketname;
|
||||
}
|
||||
|
||||
public String getRequestAddress() {
|
||||
return RequestAddress;
|
||||
}
|
||||
|
||||
public void setRequestAddress(String requestAddress) {
|
||||
RequestAddress = requestAddress;
|
||||
}
|
||||
|
||||
public Integer getStorageType() {
|
||||
return storageType;
|
||||
}
|
||||
|
||||
public void setStorageType(Integer storageType) {
|
||||
this.storageType = storageType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package cn.hellohao.pojo;
|
||||
|
||||
public class User {
|
||||
private Integer id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
private String birthder;
|
||||
private Integer level;
|
||||
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public User(Integer id, String username, String password, String email, String birthder, Integer level,
|
||||
Integer keyId) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.birthder = birthder;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
|
||||
public String getBirthder() {
|
||||
return birthder;
|
||||
}
|
||||
|
||||
|
||||
public void setBirthder(String birthder) {
|
||||
this.birthder = birthder;
|
||||
}
|
||||
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.hellohao.pojo.vo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PageResultBean<T> {
|
||||
private long total;
|
||||
private List<T> rows;
|
||||
|
||||
public PageResultBean(long total, List<T> rows) {
|
||||
this.total = total;
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<T> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(List<T> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cn.hellohao.service;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
|
||||
public interface ImgService {
|
||||
List<Images> selectimg(Integer id);
|
||||
Integer deleimg(Integer id);
|
||||
Integer countimg(Integer userid);
|
||||
Images selectByPrimaryKey(Integer id);
|
||||
Integer counts(Integer userid);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cn.hellohao.service;
|
||||
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
|
||||
public interface KeysService {
|
||||
//查询密钥
|
||||
Keys selectKeys(Integer storageType);
|
||||
//查询key类型
|
||||
Integer selectKeysType();
|
||||
//修改key
|
||||
Integer updateKey(Keys key);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.hellohao.service;
|
||||
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.User;
|
||||
|
||||
public interface UserService {
|
||||
//注册
|
||||
Integer register(User user);
|
||||
//登录
|
||||
Integer login(String email,String password);
|
||||
//获取用户信息
|
||||
User getUsers(String email);
|
||||
//插入图片
|
||||
Integer insertimg(Images img);
|
||||
//修改资料
|
||||
Integer change(User user);
|
||||
//检查用户名是否重复
|
||||
Integer checkUsername(String username);
|
||||
|
||||
Integer getUserTotal();
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.netease.cloud.auth.BasicCredentials;
|
||||
import com.netease.cloud.auth.Credentials;
|
||||
import com.netease.cloud.services.nos.NosClient;
|
||||
import com.netease.cloud.services.nos.model.Bucket;
|
||||
import com.netease.cloud.services.nos.model.CannedAccessControlList;
|
||||
import com.netease.cloud.services.nos.transfer.TransferManager;
|
||||
|
||||
import cn.hellohao.dao.ImgMapper;
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.service.ImgService;
|
||||
|
||||
@Service
|
||||
public class ImgServiceImpl implements ImgService {
|
||||
@Autowired
|
||||
private ImgMapper imgMapper;
|
||||
|
||||
@Override
|
||||
public List<Images> selectimg(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.selectimg(userid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleimg(Integer id) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.deleimg(id);
|
||||
}
|
||||
|
||||
|
||||
public Images selectByPrimaryKey(Integer id) {
|
||||
return imgMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
//删除对象存储的图片文件
|
||||
public void delect(Keys key,String fileName) {
|
||||
// 初始化
|
||||
Credentials credentials = new BasicCredentials(key.getAccessKey(), key.getAccessSecret());
|
||||
NosClient nosClient = new NosClient(credentials);
|
||||
nosClient.setEndpoint(key.getEndpoint());
|
||||
// 初始化TransferManager
|
||||
TransferManager transferManager = new TransferManager(nosClient);
|
||||
|
||||
//列举桶
|
||||
ArrayList bucketList = new ArrayList();
|
||||
String tname = "";
|
||||
for (Bucket bucket : nosClient.listBuckets()) {
|
||||
bucketList.add(bucket.getName());
|
||||
}
|
||||
for (Object object : bucketList) {
|
||||
System.out.println("桶名:"+object.toString());
|
||||
tname = object.toString();
|
||||
//查看桶的ACL
|
||||
CannedAccessControlList acl = nosClient.getBucketAcl(object.toString());
|
||||
// bucket权限
|
||||
System.out.println("这个桶的权限是:"+acl.toString());
|
||||
}
|
||||
//这是删除文件的方法
|
||||
boolean isExist = nosClient.doesObjectExist(tname,fileName,null);
|
||||
System.out.println("文件是否存在:"+isExist);
|
||||
|
||||
nosClient.deleteObject(tname,fileName);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer counts(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.counts(userid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer countimg(Integer userid) {
|
||||
// TODO Auto-generated method stub
|
||||
return imgMapper.countimg(userid);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import cn.hellohao.dao.KeysMapper;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.service.KeysService;
|
||||
|
||||
@Service
|
||||
public class KeysServiceImpl implements KeysService {
|
||||
|
||||
@Autowired
|
||||
private KeysMapper keysMapper;
|
||||
|
||||
@Override
|
||||
public Keys selectKeys(Integer storageType) {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.selectKeys(storageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer selectKeysType() {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.selectKeysType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateKey(Keys key) {
|
||||
// TODO Auto-generated method stub
|
||||
return keysMapper.updateKey(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.netease.cloud.auth.BasicCredentials;
|
||||
import com.netease.cloud.auth.Credentials;
|
||||
import com.netease.cloud.services.nos.NosClient;
|
||||
import com.netease.cloud.services.nos.model.Bucket;
|
||||
import com.netease.cloud.services.nos.model.GeneratePresignedUrlRequest;
|
||||
import com.netease.cloud.services.nos.transfer.TransferManager;
|
||||
|
||||
import cn.hellohao.pojo.Keys;
|
||||
|
||||
@Service
|
||||
public class NOSImageupload {
|
||||
//直接读取properties文件的值
|
||||
// @Value("${AccessKey}")
|
||||
// private String AccessKey;
|
||||
// @Value("${AccessSecret}")
|
||||
// private String AccessSecret;
|
||||
// @Value("${Endpoint}")
|
||||
// private String Endpoint;
|
||||
// @Value("${Bucketname}")
|
||||
// private String Bucketname;
|
||||
// @Value("${RequestAddress}")
|
||||
// private String RequestAddress;
|
||||
static String BarrelName;
|
||||
static NosClient nosClient;
|
||||
static Keys key;
|
||||
|
||||
public Map<String, Integer> Imageupload(Map<String, MultipartFile> fileMap) throws Exception {
|
||||
// 要上传文件的路径
|
||||
Map<String, Integer> ImgUrl = new HashMap<>();
|
||||
for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
|
||||
//System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
|
||||
File file = changeFile(entry.getValue());
|
||||
try {
|
||||
nosClient.putObject(BarrelName, uuid + "." + entry.getKey(), file);
|
||||
ImgUrl.put(key.getRequestAddress() + "/" + uuid + "." + entry.getKey(), (int) (entry.getValue().getSize()));
|
||||
} catch (Exception e) {
|
||||
System.out.println("上传报错==" + e.getMessage());
|
||||
}
|
||||
}
|
||||
return ImgUrl;
|
||||
}
|
||||
|
||||
// 转换文件方法
|
||||
private File changeFile(MultipartFile multipartFile) throws Exception {
|
||||
// 获取文件名
|
||||
String fileName = multipartFile.getOriginalFilename();
|
||||
// 获取文件后缀
|
||||
String prefix = fileName.substring(fileName.lastIndexOf("."));
|
||||
// todo 修改临时文件文件名
|
||||
File file = File.createTempFile(fileName, prefix);
|
||||
// MultipartFile to File
|
||||
multipartFile.transferTo(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
//初始化对象存储
|
||||
public static void Initialize(Keys k){
|
||||
// 初始化
|
||||
Credentials credentials = new BasicCredentials(k.getAccessKey(), k.getAccessSecret());
|
||||
nosClient = new NosClient(credentials);
|
||||
nosClient.setEndpoint(k.getEndpoint());
|
||||
// 初始化TransferManager
|
||||
TransferManager transferManager = new TransferManager(nosClient);
|
||||
// 列举桶
|
||||
ArrayList bucketList = new ArrayList();
|
||||
for (Bucket bucket : nosClient.listBuckets()) {
|
||||
bucketList.add(bucket.getName());
|
||||
}
|
||||
for (Object object : bucketList) {
|
||||
if (object.toString().equals(k.getBucketname())) {
|
||||
BarrelName = object.toString();
|
||||
}
|
||||
}
|
||||
key = k;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package cn.hellohao.service.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import cn.hellohao.dao.UserMapper;
|
||||
import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.User;
|
||||
import cn.hellohao.service.UserService;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public Integer register(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
return userMapper.register(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer login(String email, String password) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.login(email, password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUsers(String email) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.getUsers(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer insertimg(Images img) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.insertimg(img);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer change(User user) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.change(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer checkUsername(String username) {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.checkUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getUserTotal() {
|
||||
// TODO Auto-generated method stub
|
||||
return userMapper.getUserTotal();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package cn.hellohao.test;␍␍import com.alibaba.fastjson.JSONObject;␍␍import java.io.BufferedReader;␍import java.io.IOException;␍import java.io.InputStreamReader;␍import java.net.MalformedURLException;␍import java.net.URL;␍import java.net.URLConnection;␍import java.util.*;␍␍/** ␍ * ␍ * 于第一种方式相比,优势 1>当启动和去取消任务时可以控制 2>第一次执行任务时可以指定你想要的delay时间 ␍ * ␍ * 在实现时,Timer类可以调度任务,TimerTask则是通过在run()方法里实现具体任务。 Timer实例可以调度多任务,它是线程安全的。 ␍ * 当Timer的构造器被调用时,它创建了一个线程,这个线程可以用来调度任务。 下面是代码: ␍ * ␍ * @author GT ␍ * ␍ */ ␍public class Task2 {␍ public static void main(String[] args) {␍␍ TimerTask task = new TimerTask() {␍ Map<String, Integer> map = new HashMap<String, Integer>();␍ @Override␍ public void run() {␍ // task to run goes here ␍ //System.out.println("Hello !!!");␍ String url = "http://ip.360.cn/IPShare/info";␍ String json = loadJSON(url);␍ //System.out.println(json);␍␍ JSONObject pa=JSONObject.parseObject(json);␍ //System.out.println(pa.getString("ip"));␍ map.put(pa.getString("ip"),5);␍ List<Map.Entry<Object, Object>> li = getKeyBySameValue(map);␍ Integer count = 0;␍ for (int i = 0;i<li.size();i++){␍ System.out.println(li.get(i).getKey());␍ Integer a = Integer.parseInt(String.valueOf(li.get(i).getKey()));␍ count = count+a;␍ if (count>30){␍ System.out.println("您已经被限制!");␍ }␍␍ }␍ }␍ }; ␍ Timer timer = new Timer(); ␍ long delay = 0; ␍ long intevalPeriod = 5 * 1000;␍ // schedules the task to be run in an interval ␍ timer.scheduleAtFixedRate(task, delay, intevalPeriod); ␍ } // end of main␍␍␍ //获取本机ip␍ public static String loadJSON(String url) {␍ StringBuilder json = new StringBuilder();␍ try {␍ URL oracle = new URL(url);␍ URLConnection yc = oracle.openConnection();␍ BufferedReader in = new BufferedReader(new InputStreamReader(␍ yc.getInputStream(),"utf-8"));//防止乱码␍ String inputLine = null;␍ while ((inputLine = in.readLine()) != null) {␍ json.append(inputLine);␍ }␍ in.close();␍ } catch (MalformedURLException e) {␍ e.printStackTrace();␍ } catch (IOException e) {␍ e.printStackTrace();␍ }␍ return json.toString();␍ }␍␍␍ public static List<Map.Entry<Object, Object>> getKeyBySameValue(Map map){␍ Map values = new HashMap();␍ List list;␍ Iterator iterator = map.keySet().iterator();␍ while (iterator.hasNext()) {␍ Object key = iterator.next();␍ Object value = map.get(key);␍ if (map.containsValue(value)) {␍ if (values.containsKey(value)) {␍ list = (List) values.get(value);␍ } else {␍ list = new ArrayList();␍ }␍ list.add(key);␍ values.put(value, list);␍ }␍ }␍ iterator = values.keySet().iterator();␍ Map<Object,Object> newMap = new HashMap<>();␍ while (iterator.hasNext()) {␍ Object value = iterator.next();␍ List result = (List) values.get(value);␍ if (result.size() > 1) {␍ System.out.println("value :" + value + " -> keys:"␍ + result.toString());␍ }␍ newMap.put(value,result.toString());␍ }␍ List<Map.Entry<Object, Object>> returnList = new ArrayList<>(newMap.entrySet());␍ return returnList;␍ }␍␍␍␍}
|
||||
@@ -0,0 +1 @@
|
||||
package cn.hellohao.test;␍␍import java.io.IOException;␍import java.util.Scanner;␍␍public class asdf {␍ public static void main(String[] args) {␍// TODO Auto-generated method stub␍ try {long start = System.currentTimeMillis();Process process = Runtime.getRuntime().exec(new String[] {"wmic","cpu","get","ProcessorId"});process.getOutputStream().close();Scanner sc = new Scanner(process.getInputStream());String property = sc.next();String serial = sc.next();System.out.println(property +":"+ serial);System.out.println("time:"+ (System.currentTimeMillis() - start));␍ } catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();␍ }␍ }␍␍␍}␍
|
||||
Reference in New Issue
Block a user