My Creation Day - 512

chance

Unexpectedly, I have been writing on CSDN for 512 days without knowing it. I thought that I just wanted to take notes on CSDN at the beginning, and now I have become a small blogger. I have met many like-minded partners. I was lazy and gave up in the middle of the creation. But I re-created again and again. Although I only started to understand programmers when I was in college and became a programmer (maybe I am not yet qualified), I want to leave something in the process to prove that I have also worked hard. Pass. But now it has gradually become a habit, I get used to it, and I can't change it.


reward

Tips: What are the gains in the process of creation
For example:

  1. Gained the attention of 6383 followers
  2. Received 3565 likes, 3556 comments, 149176 readings, etc.
  3. Knowing Bai Lao , Shanhe also greeted , Xiaoji , etc. There are many excellent people, some of them may have just chatted briefly on CSDN, some have added contact information and communicated frequently, but the memory cannot be dissipated all at once, maybe in the future Will forget, but I still remember now!
  4. And many, many other gains

 Always believe that hard work will pay off


daily

Tip: What is the relationship between the current creation and your work and study
? For example:

  1. Is creation already a part of your life: Yes.
  2. With limited energy, how to balance creation and learning: beyond learning is creation, and beyond creation is learning. In other words, creation is another kind of learning.

Achievement

Prompt: What's the best piece of code you've written in the past? Please post it with a code block

Use JDBC+javafx to write a simple and fully functional library management system_javafx library management system_Leng Xixue's Blog-CSDN Blog

package com.hk.sky.bookmanager;
 
import com.hk.sky.bookmanager.bean.Admin;
import com.hk.sky.bookmanager.controller.LoginController;
import com.hk.sky.bookmanager.dao.AdminDao;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
 
import java.io.IOException;
 
 
public class BookManagerApplication extends Application {
    AdminDao adminDao=new AdminDao();
    //获取上一次用户登录的信息
    Admin admin=adminDao.getLast();
    @Override
    public void start(Stage stage) throws IOException {
        //登录页面的资源文件为login/login.fxml
        FXMLLoader fxmlLoader = new FXMLLoader(BookManagerApplication.class.getResource("login/login.fxml"));
        //设置登录窗口的长和宽
        Scene scene = new Scene(fxmlLoader.load(), 290, 240);
        stage.setTitle("管理员登录");
        stage.setScene(scene);
        LoginController loginController=fxmlLoader.getController();
        //如果admin不是为null,则说明上一次有用户登录,则直接在登录页面显示账号和密码
        if (admin!=null)
            loginController.set(admin.getAccount(),admin.getPassword());
        stage.show();
    }
    //启动
    public static void main(String[] args) {
        launch();
    }
}
package com.hk.sky.bookmanager.utils;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
 
/**
 * 封装数据连接,关闭的工具类
 */
public class DBUtils {
 
    private static String url;
    private static String username;
    private static String password;
 
    // 读取配置文件
    static {
        Properties prop = new Properties();
 
        try {
            // DBUtils.class.getClassLoader().getResourceAsStream()方法可以从类路径中读取资源文件
            prop.load(DBUtils.class.getClassLoader().getResourceAsStream("db.properties"));
 
            // 通过key获取value
            url = prop.getProperty("jdbc.url");
            username = prop.getProperty("jdbc.username");
            password = prop.getProperty("jdbc.password");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
 
    // 将创建连接的方法封装成静态方法,方便调用
    // 如何将url、username、password放到配置文件当中,然后读取出来
    public static Connection getConnection() {
        // 创建连接的时候,有会异常:SQLException,不建议抛出,建立捕获
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(
                    url,
                    username,
                    password
            );
        } catch (SQLException e) {
            e.printStackTrace();
        }
 
        return conn;
    }
    
    // 将关闭连接的方法封装成静态方法,方便调用
    public static void close(ResultSet rs, PreparedStatement pStmt, Connection conn) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (pStmt != null) {
            try {
                pStmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

Spring + Spring MVC + MyBatis_Leng Xixue's Blog-CSDN Blog 

package com.example.springbootdemo;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication//SpringBoot项目的入口 启动注解
public class SpringBootdemoApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(SpringBootdemoApplication.class, args);
    }
 
}
package com.example.springbootdemo;
 
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
@Controller//当前类为控制器
@ResponseBody//返回的是数据,而非页面
/*@RestController*/ //复合注解 = @Controller+@ResponseBody
public class TestController {
    //请求映射 url 路由注册
    @RequestMapping("hi")
    public String sayHi(String s){
        //为空为null 默认值处理
        //if (s==null||s.equals("")){}   正常写法
        if(!StringUtils.hasLength(s)){  //Spring中更简单的写法 判断是否有长度
            s="张三";
        }
 
        return "你好"+s;
    }
}

Eight major sorts [super detailed] (motion picture + code optimization) this article is enough - Leng Xixue's Blog - CSDN Blog 

    public static void bubbleSort(int[] arr) {
        int len = arr.length;
        for (int i = 0; i < len - 1; i++) {
            for (int j = 0; j < len - 1 - i; j++) {
                if (arr[j] > arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
import java.util.Arrays;
 
public class Main {
    public static void bubbleSort(int[] arr) {
        int len = arr.length;
        for (int i = 0; i < len - 1; i++) {
            for (int j = 0; j < len - 1 - i; j++) {
                if (arr[j] > arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
                System.out.print("第 "+(i+1)+" 趟,第 "+(j+1)+" 次比较后的结果:");
                System.out.println(Arrays.toString(arr));
            }
        }
    }
    public static void main(String[] args) {
        int[] arr={2,9,7,15,49,10};
        System.out.println(Arrays.toString(arr));
        bubbleSort(arr);
    }
}

look forward to

The future may be infinite, first improve yourself, and hope to eat the rice of a programmer. At the same time, I hope to make more like-minded partners to cheer together.

 

Guess you like

Origin blog.csdn.net/m0_63951142/article/details/131268429