首页
友链
关于
免责声明
Search
1
王者营地战绩数据王者荣耀查询网页源码
6,258 阅读
2
群晖Active Backup for Business套件备份Linux服务器教程
4,387 阅读
3
影视分享
4,319 阅读
4
(亲测)Jrebel激活破解方式2019-08-21
4,293 阅读
5
centos7 安装及卸载 jekenis
3,576 阅读
日常
文章
后端
前端
Linux
异常
Flutter
分享
群辉
登录
Search
标签搜索
docker
springboot
Spring Boot
java
linux
Shiro
Graphics2D
图片
游戏账号交易
Mybatis
Spring Cloud
centos
脚本
Web Station
群辉
王者营地
战绩查询
平台对接
Spring Cloud Alibaba
nacos
绿林寻猫
累计撰写
249
篇文章
累计收到
26
条评论
首页
栏目
日常
文章
后端
前端
Linux
异常
Flutter
分享
群辉
页面
友链
关于
免责声明
搜索到
237
篇与
文章
的结果
2021-12-08
JAVA swing组件一些修饰方法
//修改表模式,使其不能双击修改内容 //常规写法DefaultTableModel() dtm = new DefaultTableModel();//修改后DefaultTableModel() dtm = new DefaultTableModel(){ /* (non-Javadoc)* @see javax.swing.table.DefaultTableModel#isCellEditable(int, int)*/@Overridepublic boolean isCellEditable(int row, int column) { // TODO Auto-generated method stubreturn false;}};//表JTable jtt = new JTable();//表头长宽jtt.getTableHeader().setPreferredSize(new Dimension(100,80)); //表头字体、颜色jtt.getTableHeader().setFont(ff1); jtt.getTableHeader().setForeground(Color.black);//表头背景色jtt.getTableHeader().setBackground(Color.white); //内容居中DefaultTableCellHeaderRenderer cr = new DefaultTableCellHeaderRenderer();jtt.setDefaultRenderer(Object.class, cr);//表格高度jtt.setRowHeight(70); 单选框变量名.setContentAreaFilled(false); //组键透明文本框变量名.setEnabled(false); //设置失效按钮变量名.setFocusPainted(false);//取消文字选中
2021年12月08日
89 阅读
0 评论
0 点赞
2021-12-08
JAVA 基础无限极分类
package com.ui;import java.util.List;import com.dao.WxjflDao;import com.entity.Wxjfl;/** * 类描述:无限极分类----输出 * @author 绿街猫 * @date 2017年11月23日上午10:37:08 * @version : */public class Infinity { public static void main(String[] args) { //从数据库表里得到级别为1的数据信息,放入集合 List<Wxjfl> li = WxjflDao.get("and jb = 1"); //调用递归的方法,把集合放进去 recursion(li); } /** * 递归 * @param List<Wxjfl> li */ public static void recursion(List<Wxjfl> li){ / /遍历接收的集合 for (Wxjfl w : li) { //for循环只是为了打印出来有层次感,在一级一级往下推时,前面添加空格 for (int i = 0; i <w.getJb()-1; i++) { System.out.print(" "); } //打印输出对象信息,分别对应数据库表四个列 System.out.println(w.getWid()+" "+w.getWname()+" "+w.getFid()+" "+w.getJb()); //再次查询第一个级别所对应的下面级别的信息;如第一级查完,继续查第二级,以此类推 List<Wxjfl> ll = WxjflDao.get("and fid = "+w.getWid()); //再次调用这个递归方法,把这个集合放进去继续查 //当最后所接受的集合信息为null时,调用这个方法时,遍历也就不会运行。依次可以查询每一集下面对应的数据,直至最后无数据可查 recursion(ll); }//------------------for (Wxjfl w : li) 结尾----------------------------- }//-------------------recursion结尾-----------------------------}//----------------------Infinity结尾-----------------------------
2021年12月08日
123 阅读
0 评论
0 点赞
2021-12-08
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.
([Ljava
搭建spring cloud,启动时报错:java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V这个是版本兼容原因 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>改: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
2021年12月08日
844 阅读
0 评论
0 点赞
2021-12-08
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).原因如下:@Select("select count(*) from pro_mac where id like'%#{val}%' or mac like'%#{val}%'")在where id like'%#{val}%' or mac like'%#{val}%'"中#{val}是带‘’的,显示结果可能为where id like'%‘123’%' 所以改为${val}就好了@Select("select count(*) from pro_mac where id like'%${val}%' or mac like'%${val}%'")
2021年12月08日
248 阅读
0 评论
0 点赞
2021-12-08
java.sql.SQLException: null, message from server: "Host 'xxx.xxx.xxx.xxx' is not allowed to connect
其实道理很简单,也就是说,远程的机器B不允许机器A访问他的数据库。一:打开mysql控制台#use mysql; #show tables; 二:输入#select host from user; #update user set host ='%' where user ='root'; 三:使用 service 启动#service mysqld restart 然后再访问就没有问题了
2021年12月08日
200 阅读
0 评论
0 点赞
2021-12-08
JAVA爬虫模拟执行页面点击事件
所需依赖: <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>com.springsource.com.gargoylesoftware.htmlunit</artifactId> <version>2.6.0</version> </dependency>代码示例import java.io.IOException; import java.net.MalformedURLException; import java.util.List; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * 模拟点击,动态获取页面信息 * @Author: Uncle liu * @Date: 2019-10-07 15:39 */ public class JsoupHttpClient { private static class innerWebClient{ private static final WebClient webClient = new WebClient(); } /** * 获取指定网页实体 * @param url * @return */ public static HtmlPage getHtmlPage(String url){ //调用此方法时加载WebClient WebClient webClient = innerWebClient.webClient; // 取消 JS 支持 webClient.setJavaScriptEnabled(false); // 取消 CSS 支持 webClient.setCssEnabled(false); HtmlPage page=null; try{ // 获取指定网页实体 page = (HtmlPage) webClient.getPage(url); }catch (MalformedURLException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); } return page; } public static void main(String[] args) throws Exception { // 获取指定网页实体 HtmlPage page = getHtmlPage("https://www.baidu.com/"); System.out.println(page.asText()); //asText()是以文本格式显示 System.out.println(page.asXml()); //asXml()是以xml格式显示 // 获取搜索输入框 HtmlInput input = page.getHtmlElementById("kw"); // 往输入框 “填值” input.setValueAttribute("绿林寻猫"); // 获取搜索按钮 HtmlInput btn = page.getHtmlElementById("su"); // “点击” 搜索 HtmlPage page2 = btn.click(); // 选择元素 List<HtmlElement> spanList=(List<HtmlElement>)page2.getByXPath("//h3[@class='t']/a"); for(int i=0;i<spanList.size();i++) { // 输出新页面的文本 System.out.println(i+1+"、"+spanList.get(i).asText()); } } }结果:
2021年12月08日
413 阅读
0 评论
0 点赞
2021-12-08
Java连接mqtt服务器(发送、订阅)
<dependency> <groupId>org.eclipse.paho</groupId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId> <version>1.2.2</version> </dependency>1.模拟客户端接收消息import java.util.concurrent.ScheduledExecutorService; import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttTopic; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; /** * 模拟一个客户端接收消息 * * @author Unclue_liu */ public class ClientMQTT { public static final String HOST = "tcp://192.168.1.77:1883"; public static final String TOPIC1 = "pos_message_all"; private static final String clientid = "12345678"; private MqttClient client; private MqttConnectOptions options; private String userName = "mqtt"; //非必须 private String passWord = "mqtt"; //非必须 private ScheduledExecutorService scheduler; private void start() { try { // host为主机名,clientid即连接MQTT的客户端ID,一般以唯一标识符表示,MemoryPersistence设置clientid的保存形式,默认为以内存保存 client = new MqttClient(HOST, clientid, new MemoryPersistence()); // MQTT的连接设置 options = new MqttConnectOptions(); // 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,设置为true表示每次连接到服务器都以新的身份连接 options.setCleanSession(false); // 设置连接的用户名 options.setUserName(userName); // 设置连接的密码 options.setPassword(passWord.toCharArray()); // 设置超时时间 单位为秒 options.setConnectionTimeout(10); // 设置会话心跳时间 单位为秒 服务器会每隔1.5*20秒的时间向客户端发送个消息判断客户端是否在线,但这个方法并没有重连的机制 options.setKeepAliveInterval(20); //设置断开后重新连接 options.setAutomaticReconnect(true); // 设置回调 client.setCallback(new PushCallback()); MqttTopic topic = client.getTopic(TOPIC1); //setWill方法,如果项目中需要知道客户端是否掉线可以调用该方法。设置最终端口的通知消息 //遗嘱 options.setWill(topic, "close".getBytes(), 1, true); client.connect(options); //订阅消息 int[] Qos = {1};//0:最多一次 、1:最少一次 、2:只有一次 String[] topic1 = {TOPIC1}; client.subscribe(topic1, Qos); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { ClientMQTT client = new ClientMQTT(); client.start(); }2.模拟服务端发送消息import org.eclipse.paho.client.mqttv3.MqttClient; import org.eclipse.paho.client.mqttv3.MqttConnectOptions; import org.eclipse.paho.client.mqttv3.MqttDeliveryToken; import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttPersistenceException; import org.eclipse.paho.client.mqttv3.MqttTopic; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; /** * Title:Server 这是发送消息的服务端 * Description: 服务器向多个客户端推送主题,即不同客户端可向服务器订阅相同主题 * @author Unclue_liu */ public class ServerMQTT { //tcp://MQTT安装的服务器地址:MQTT定义的端口号 public static final String HOST = "tcp://192.168.1.77:1883"; //定义一个主题 public static final String TOPIC = "pos_message_all"; //定义MQTT的ID,可以在MQTT服务配置中指定 private static final String clientid = "server11"; private MqttClient client; private static MqttTopic topic11; // private String userName = "mqtt"; //非必须 // private String passWord = "mqtt"; //非必须 private static MqttMessage message; /** * 构造函数 * @throws MqttException */ public ServerMQTT() throws MqttException { // MemoryPersistence设置clientid的保存形式,默认为以内存保存 client = new MqttClient(HOST, clientid, new MemoryPersistence()); connect(); } /** * 用来连接服务器 */ private void connect() { MqttConnectOptions options = new MqttConnectOptions(); options.setCleanSession(false); // options.setUserName(userName); // options.setPassword(passWord.toCharArray()); // 设置超时时间 options.setConnectionTimeout(10); // 设置会话心跳时间 options.setKeepAliveInterval(20); try { client.setCallback(new PushCallback()); client.connect(options); topic11 = client.getTopic(TOPIC); } catch (Exception e) { e.printStackTrace(); } } /** * * @param topic * @param message * @throws MqttPersistenceException * @throws MqttException */ public static void publish(MqttTopic topic , MqttMessage message) throws MqttPersistenceException, MqttException { MqttDeliveryToken token = topic.publish(message); token.waitForCompletion(); System.out.println("message is published completely! " + token.isComplete()); } public static void sendMessage(String clieId,String msg)throws Exception{ ServerMQTT server = new ServerMQTT(); server.message = new MqttMessage(); server.message.setQos(1); //保证消息能到达一次 server.message.setRetained(true); String str ="{\"clieId\":\""+clieId+"\",\"mag\":\""+msg+"\"}"; server.message.setPayload(str.getBytes()); try{ publish(server.topic11 , server.message); //断开连接 // server.client.disconnect(); }catch (Exception e){ e.printStackTrace(); } } /** * 启动入口 * @param args * @throws MqttException */ public static void main(String[] args) throws Exception { sendMessage("123444","哈哈"); } }3.发布消息回调类import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; import org.eclipse.paho.client.mqttv3.MqttCallback; import org.eclipse.paho.client.mqttv3.MqttMessage; /** * 发布消息的回调类 * * 必须实现MqttCallback的接口并实现对应的相关接口方法CallBack 类将实现 MqttCallBack。 * 每个客户机标识都需要一个回调实例。在此示例中,构造函数传递客户机标识以另存为实例数据。 * 在回调中,将它用来标识已经启动了该回调的哪个实例。 * 必须在回调类中实现三个方法: * * public void messageArrived(MqttTopic topic, MqttMessage message)接收已经预订的发布。 * * public void connectionLost(Throwable cause)在断开连接时调用。 * * public void deliveryComplete(MqttDeliveryToken token)) * 接收到已经发布的 QoS 1 或 QoS 2 消息的传递令牌时调用。 * 由 MqttClient.connect 激活此回调。 * */ public class PushCallback implements MqttCallback { public void connectionLost(Throwable cause) { // 连接丢失后,一般在这里面进行重连 System.out.println("连接断开,可以做重连"); } public void deliveryComplete(IMqttDeliveryToken token) { System.out.println("deliveryComplete---------" + token.isComplete()); } public void messageArrived(String topic, MqttMessage message) throws Exception { // subscribe后得到的消息会执行到这里面 System.out.println("接收消息主题 : " + topic); System.out.println("接收消息Qos : " + message.getQos()); System.out.println("接收消息内容 : " + new String(message.getPayload())); } }
2021年12月08日
55 阅读
0 评论
0 点赞
2021-12-08
java 根据html模板生成html文件
1.代码部分import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.io.FileInputStream; import java.io.FileOutputStream; @RunWith(SpringRunner.class) @SpringBootTest public class PdfApplicationTests { @Test public void contextLoads() { String filePath = "D:\\WorkSpace\\IdeaProjects\\pdf\\src\\main\\resources\\templates\\index.html"; String text ="哈哈"; String disrPath = "D:\\WorkSpace\\IdeaProjects\\pdf\\src\\main\\resources\\templates"; String fileName = "t"; MakeHtml(filePath,text,disrPath,fileName); } /** * @Title: MakeHtml * @Description: 创建html * @param filePath 设定模板文件 * @param text 添加的内容 * @param disrPath 生成html的存放路径 * @param fileName 生成html名字 * @return void 返回类型 * @throws */ public static void MakeHtml(String filePath,String text,String disrPath,String fileName ){ try { String title = "<h2>"+text+"</h2>"; System.out.print(filePath); String templateContent = ""; FileInputStream fileinputstream = new FileInputStream(filePath);// 读取模板文件 int lenght = fileinputstream.available(); byte bytes[] = new byte[lenght]; fileinputstream.read(bytes); fileinputstream.close(); templateContent = new String(bytes); System.out.print(templateContent); //把模板页面上的 ###text### 替换成 title 里的内容 templateContent = templateContent.replaceAll("###text###", title); System.out.print(templateContent); String fileame = fileName + ".html"; fileame = disrPath+"/" + fileame;// 生成的html文件保存路径。 FileOutputStream fileoutputstream = new FileOutputStream(fileame);// 建立文件输出流 System.out.print("文件输出路径:"); System.out.print(fileame); byte tag_bytes[] = templateContent.getBytes(); fileoutputstream.write(tag_bytes); fileoutputstream.close(); } catch (Exception e) { System.out.print(e.toString()); } } } 2.模板页<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"/> <title>Title</title> </head> </head> <body> ###text### </body> </html>3.生成的html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"/> <title>Title</title> </head> </head> <body> <h2>哈哈</h2> </body> </html>
2021年12月08日
229 阅读
0 评论
0 点赞
2021-12-08
java根据xml模板生成word(编辑内容)
1.使用的依赖 <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.25-incubating</version> </dependency>2.Servicepackage com.hj.test; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.net.URL; import java.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import freemarker.cache.URLTemplateLoader; import freemarker.core.ParseException; import freemarker.template.Configuration; import freemarker.template.MalformedTemplateNameException; import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.TemplateNotFoundException; import javax.servlet.http.HttpServletRequest; @Service public class DynamicallyGeneratedWordService { private static Configuration freemarkerConfig; @Autowired HttpServletRequest req; static { freemarkerConfig = new Configuration(Configuration.VERSION_2_3_22); freemarkerConfig.setEncoding(Locale.getDefault(), "UTF-8"); } /** * 生成word文档 * @param filePath * @throws TemplateNotFoundException * @throws MalformedTemplateNameException * @throws ParseException * @throws IOException * @throws TemplateException */ public void genWordFile(String filePath) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{ Map<String,Object> result = new HashMap<String,Object>(); result.put("topic", "基于Java模板技术动态生成Word文档"); freemarkerConfig.setTemplateLoader(new URLTemplateLoader() { @Override protected URL getURL(String arg0) { //此处访问的地址是项目target/classes文件夹 //输出的类似:E:/software/idea/aa/target/classes/6.xm return DynamicallyGeneratedWordService.class.getResource("/6.xml"); } }); Template temp = freemarkerConfig.getTemplate("6.xml"); File targetFile = new File(filePath); Writer out = new OutputStreamWriter(new FileOutputStream(targetFile),"UTF-8"); //执行模板替换 temp.process(result, out); out.flush(); } } xml地址:3.Controllerpackage com.hj.test; import java.io.IOException; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.hj.test.Student; import com.hj.test.DynamicallyGeneratedWordService; import freemarker.core.ParseException; import freemarker.template.MalformedTemplateNameException; import freemarker.template.TemplateException; import freemarker.template.TemplateNotFoundException; /** * @author Solin * 基于Java模板技术动态生成Word文档 */ @Controller public class DynamicallyGeneratedWordController { @Autowired private DynamicallyGeneratedWordService dynamicallyGeneratedWordService; @ResponseBody @RequestMapping("/getStudentList") public String getStudentList(){ String result = "成功"; try { dynamicallyGeneratedWordService.genWordFile("d://stu.doc"); } catch (TemplateNotFoundException e) { result = "失败"; e.printStackTrace(); } catch (MalformedTemplateNameException e) { result = "失败"; e.printStackTrace(); } catch (ParseException e) { result = "失败"; e.printStackTrace(); } catch (IOException e) { result = "失败"; e.printStackTrace(); } catch (TemplateException e) { result = "失败"; e.printStackTrace(); } return result; } } 编辑xml文件:(xml模板可编辑word文档使用wps另存为xml格式) 参考:https://blog.csdn.net/qq_32786873/article/details/52535845
2021年12月08日
138 阅读
0 评论
0 点赞
2021-12-08
Java跨域
mport org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 跨域 */ @Component public class CorsFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; response.setHeader("Access-Control-Allow-Origin", request.getHeader("origin")); // response.setHeader("Access-Control-Allow-Origin", "*");//允许跨域访问的域 response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");//允许使用的请求方法,以逗号隔开 response.setHeader("Access-Control-Max-Age", "3600");// 缓存此次请求的秒数 //允许使用的请求方法,以逗号隔开 response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Cache-Control,Pragma,Content-Type,Token"); response.setHeader("Access-Control-Allow-Credentials","true");//是否允许请求带有验证信息 filterChain.doFilter(servletRequest, servletResponse); } @Override public void destroy() { } }
2021年12月08日
79 阅读
0 评论
0 点赞
1
...
16
17
18
...
24