SpringBoot-单例中使用AutoWired

对于一个单例类按照平时的注解方式添加,启动时会报空指针异常,因为static类对象是创建对象后,内存中还没有注入Bean信息,且无法初始化Bean实例,这里的解决办法是利用@PostConstruct来对单例类中对象的注入。 @Component public class DBManager {     private static DBManager instance = new DBManager();     @Autowired     public UserServiceImpl userService;     private DBManager() {     }     public static DBManager getInstance() {         return instance;     }     @PostConstruct     public void init() {         instance = this;         instance.userService = this.userService;     } }

Mybatis批量插入或更新

1 批量更新 <foreach collection=”attendingUsrList” item=”model” separator=”;”> UPDATE parties SET attending_user_count = #{model.attending_count} WHERE fb_party_id = #{model.eid} </foreach> 2 批量插入 <insert id=”insertAccountabilityUsers” parameterType=”AccountabilityUsersModel” useGeneratedKeys=”false”> INSERT INTO accountability_users ( accountability_user_id, accountability_id, to_username, record_status, created_by, created_at, updated_by, updated_at ) VALUES <foreach collection=”usersList” item=”model” separator=”,”> ( #{model.accountabilityUserId}, #{model.accountabilityId}, #{model.toUsername}, ‘A’, #{model.createdBy}, #{model.createdAt}, #{model.updatedBy}, #{model.updatedAt} ) </foreach> </insert>

jQuery图表插件 jqPlot实现饼状图

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html lang=”en”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″> <title>饼状图demo</title> <!–[if IE]><script language=”javascript” type=”text/javascript” src=”excanvas.js” ></script><![endif]–> <link rel=”stylesheet” type=”text/css” href=”jquery.jqplot.css” /> <script language=”javascript” type=”text/javascript” src=”jquery-1.4.2.min.js” ></script> <script language=”javascript” type=”text/javascript” src=”jquery.jqplot.js” ></script> <script language=”javascript” type=”text/javascript” src=”plugins/jqplot.pieRenderer.js” ></script> <script type=”text/javascript” language=”javascript”> $(document).ready(function(){ line1 = [[‘李开复’, 3], [‘周鸿祎’, 7], [‘李彦宏’, 2.5], [‘马化腾’, … Read more

jquery设置cookie、删除cookie、获取cookie

1.引入两个js 去bootcdn搜索就行。 jquery.js <script src=”https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js”></script> jquery cookie <script src=”https://cdn.bootcdn.net/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js”></script> 2.设置cookie $.cookie(“key”,“value”); 如: $.cookie(“love”,“唱跳rap篮球”); //设置了一个值为”唱跳rap篮球的cookie,cookie的名字是love 3.给cookie设置时长 $.cookie(“key”,“value”,{expires: 7}) ;设置为7天 4.设置cookie的域名 在不同网页中是不能访问同一个cookie的,所以可以设置cookie的域名,让cookie在这个域名下都能访问。 $.cookie(“key”,“value”,{domain:“icyakuya.website”}) 5.设置cookie的路径 可以结合域名一起使用,在本地文件运行也能使用。 $.cookie(“key”,“value”,{domain:“icyakuya”,path:“xxx/”} path可以用过window.location.pathname 获取,这个获取到的是全路径包括文件名 所以需要做个截取: function getPath(){ var path = window.location.pathname; //获取的是文件路径全名包括路径 var pos = path.lastIndexOf(“/”); //去除文件名 path = path.substring(0, pos); return path; } 6.删除cookie $.removeCookie(‘key’,{path:”/”}) ;//删除该路径下所有名为key的cookie $.removeCookie(“key”,null,{path:”/”}) 将key的值设置为空,实际上相当于删除 7.获取cookie $.cookie(“name”) 注意: cookie的域名和路径都很重要,如果没有设置成一致,则会有不同域名下或者不同路径下的同名cookie,为了避免这种情况,建议在设置cookie和删除cookie的时候,配置路径和域名。 … Read more

JFinal框架

JFinal 是基于 Java 语言的极速 WEB + ORM 框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥… 官网: https://jfinal.com/

java高效读取大文件

BufferReader 我们可以使用 BufferReader#readLine 逐行读取数据。 try (BufferedReader fileBufferReader = new BufferedReader(new FileReader(“temp/test.txt”))) {      String fileLineContent;      while ((fileLineContent = fileBufferReader.readLine()) != null) {          // process the line.      }  } catch (FileNotFoundException e) {      e.printStackTrace();  } catch (IOException e) {      e.printStackTrace();  }  Apache Commons IOCommon-IO 中有一个方法 FileUtils#lineIterator可以实现逐行读取方式,使用代码如下:   Stopwatch stopwatch = Stopwatch.createStarted();  LineIterator fileContents = FileUtils.lineIterator(new File(“temp/test.txt”), StandardCharsets.UTF_8.name());  while (fileContents.hasNext()) {      fileContents.nextLine();      //  pass  }  logMemory();  fileContents.close();  stopwatch.stop();  System.out.println(“read all lines spend ” + stopwatch.elapsed(TimeUnit.SECONDS) + ” s”); Java8 stream Java8 Files 类新增了一个 lines,可以返回 Stream我们可以逐行处理数据。   Stopwatch stopwatch = Stopwatch.createStarted();  // lines(Path path, Charset cs)  try (Stream<String> inputStream = Files.lines(Paths.get(“temp/test.txt”), StandardCharsets.UTF_8)) {      inputStream              .filter(str -> str.length() > 5)// 过滤数据              .forEach(o -> {                  // pass do sample logic              });  }  logMemory();  stopwatch.stop();  System.out.println(“read all lines spend ” + stopwatch.elapsed(TimeUnit.SECONDS) + ” s”);  使用这个方法有个好处在于,我们可以方便使用 Stream 链式操作,做一些过滤操作。 注意:这里我们使用 try-with-resources … Read more

el-table 表格头部和单元格字体样式等

el-table 表格头部和单元格字体样式等 <el-table :cell-style=”{color: ‘#666’, fontFamily: ‘Arial’,fontSize:’15px’}” :data=”filteredProductData” :header-cell-style=”{background:’#f0f9eb’, fontFamily:’Helvetica’,fontSize:’14px’}” style=”width: 100%”>