大家好,我是除了网站啥都不会做的开酱,今天做一个记事本网站。
第一步:准备工具
idea
mysql
java
墨刀
第二步:画原型
第三步:数据库设计
#创建数据库 CREATE SCHEMA `kj_note_website` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin ; #用户注册与登录用表 create table `kj_note_website`.`user_list`( `id` int not null auto_increment, `account` varchar(100) not null,#账号 `password` varchar(1000) not null,#密码 `create_time` varchar(20) not null,#注册时间 primary key (id) ); #记事本存储用表 create table `kj_note_website`.`note_list`( `id` int not null auto_increment, `account` varchar(100) not null,#账号 `note_content` varchar(1000) not null,#记事内容 `create_time` varchar(20) not null,#记事时间 primary key (id) )
第四步:前端页面代码实现
index.html 首页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- 手机端-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link type="text/css" rel="stylesheet" href="../bootstrap/css/bootstrap.css">
<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
<script>
//检查登录
if(window.localStorage.getItem("account")!=null){
}else{
window.location.href='login.html';
}
</script>
<title>开酱的记事本网站</title>
<style>
.head{
width:100%;
height:60px;
background-color: darkred;
position: fixed;
}
.title_div{
width:80%;
height:60px;
float: left;
/*background-color: #4cae4c;*/
/*上下左右居中*/
display: flex;
align-items:center;
justify-content: center;
font-size: 30px;
color: white;
}
.user_div{
width:20%;
height:60px;
float: left;
/*background-color: #eb9316;*/
/*上下左右居中*/
display: flex;
align-items:center;
justify-content: center;
}
.user_img{
width:30px;
height:30px;
}
.space_head{
width:100%;
height: 60px;
}
.note_list{
padding: 20px;
padding-bottom:60px ;
}
.input_bottom_div{
position: fixed;
bottom: 0;
width: 100%;
height: 60px;
z-index: 1000;
background-color: white;
/*background-color: darkred;*/
}
.input_div{
width: 80%;
height: 60px;
float: left;
/*background-color: #eb9316;*/
/*上下左右居中*/
display: flex;
align-items:center;
justify-content: center;
}
.submit_div{
width: 20%;
height: 60px;
float: left;
/*background-color: #ec1c1c;*/
/*上下左右居中*/
display: flex;
align-items:center;
justify-content: center;
}
.note_input{
width:90%;
height:50px;
}
.submit_btn{
width: 90%;
height:50px;
background-color: darkred;
color: white;
}
.note_content{
width:100%;
color: white;
font-size: 25px;
}
.note_create_time{
width:100%;
text-align:right;
color: white;
}
.content_div{
padding: 10px;
background-color: darkred;
}
.share_img{
width:25px;
height:25px;
}
.delete_img{
width:25px;
height:25px;
}
.notice{
margin: 20px;
text-align: center;
}
</style>
</head>
<body>
<!-- 头部[固定]-->
<div class="head">
<!--标题存放区域-->
<div class="title_div">
开酱的记事本网站
</div>
<!--个人中心图标放区域-->
<div class="user_div">
<img onclick="window.location.href='login.html'" class="user_img" src="../img/user-fill.png">
</div>
</div>
<!-- space-->
<div class="space_head"></div>
<!--note_list-->
<div class="note_list" id="note_list">
<h5 class="notice" id="notice">提示:暂无记事</h5>
<!-- <div class="content_div">-->
<!-- <div class="note_content">快乐的一天,哈哈哈,nice</div>-->
<!-- <div class="note_create_time">2022-11-05 00:00:00</div>-->
<!-- <div class="delete_and_share">-->
<!-- <img class="delete_img" src="../img/delete.png">-->
<!-- -->
<!-- <img class="share_img" src="../img/share-3.png">-->
<!-- </div>-->
<!-- </div>-->
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
load_note_list(this.responseText.toString());
}
};
xhttp.open("GET", "http://192.168.1.5/get_note_list?account="+window.localStorage.getItem("account"), true);
xhttp.send();
//加载记事内容
//加载企业官网列表
function load_note_list(list_response){
var list=JSON.parse(list_response);
var note_list=document.getElementById("note_list");
note_list.innerHTML="";//清空div
// var list=[{"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"},
// {"id":1,"note_content":"快乐的一天,哈哈哈,nice","create_time":"2022-11-05 00:00:00"}
// ];
for (var i in list ) {
let note_list=document.getElementById("note_list");
var html_list=" <div class=\"content_div\">\n" +
" <div class=\"note_content\">"+list[i].note_content+"</div>\n" +
" <div class=\"note_create_time\">"+list[i].create_time+"</div>\n" +
" <div class=\"delete_and_share\">\n" +
" <img class=\"delete_img\" src=\"../img/delete.png\">\n" +
" \n" +
" <img class=\"share_img\" src=\"../img/share-3.png\">\n" +
" </div>\n" +
" </div>"+"<br>";
note_list.innerHTML+=html_list;
}
}
</script>
</div>
<!--底部记事输入框-->
<div class="input_bottom_div">
<div class="input_div">
<input class="note_input" id="note_content" placeholder="在此记事....">
</div>
<div class="submit_div">
<button class="submit_btn" id="submit_btn" onclick="note_submit()">记事</button>
<script>
function note_submit(){
//禁用按钮
document.getElementById("submit_btn").disabled="true";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if(this.responseText=="note_submit_success"){
alert("记事成功,正在同步...");
window.location.reload();//重载页面
}else{
alert(this.responseText);
//启用用按钮
document.getElementById("submit_btn").disabled="flase";
}
}
};
xhttp.open("GET", "http://192.168.1.5/note_submit?account="+window.localStorage.getItem("account")+"¬e_content="+document.getElementById("note_content").value, true);
xhttp.send();
}
</script>
</div>
</div>
</body>
</html>
register.html 注册页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- 手机端-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link type="text/css" rel="stylesheet" href="../bootstrap/css/bootstrap.css">
<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
<title>注册账号</title>
<style>
body{
width: 100%;
height: 100%;
background-color: darkred;
}
.body{
width:100%;
height: 100%;
background-color: darkred;
padding:20px;
}
.title{
width:100%;
height:30px;
text-align: center;
font-size: 25px;
color:white
}
.register_title{
width:100%;
height:30px;
text-align: center;
font-size: 25px;
color:white;
margin-left: -50px;
}
.input_account_div{
width:100%;
height:30px;
text-align: center;
color:white;
margin-left: -25px;
}
.input_password_div{
width:100%;
height:30px;
text-align: center;
color:white;
margin-left: -25px;
}
.submit_div{
width:100%;
height:30px;
text-align: center;
margin-left: -80px;
}
.password{
color: black;
}
.account{
color: black;
}
</style>
</head>
<body>
<div class="body">
<div class="title">开酱的记事本网站</div>
<br><br>
<div class="register_title">注册账号</div>
<br><br>
<div class="input_account_div">
<input id="account" class="account" placeholder="设置账号"/>
</div>
<br>
<div class="input_password_div">
<input id="password" type="password" class="password" placeholder="设置密码"/>
</div>
<br>
<div class="submit_div">
<button onclick="register()">注册</button>
<br><br><br>
<a href="login.html">登录</a><br><br><br>
<a href="index.html">返回首页</a><br><br><br>
<script>
function register(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if(this.responseText=="register_success"){
alert("注册成功,请前往登录");
window.location.href='login.html';
}else{
alert(this.responseText);
}
}
};
xhttp.open("GET", "http://192.168.1.5/register?account="+document.getElementById("account").value+"&password="+document.getElementById("password").value, true);
xhttp.send();
}
</script>
</div>
</div>
</body>
</html>
login.html 登录页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- 手机端-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link type="text/css" rel="stylesheet" href="../bootstrap/css/bootstrap.css">
<script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
<title>登录</title>
<style>
body{
width: 100%;
height: 100%;
background-color: darkred;
}
.body{
width:100%;
height: 100%;
background-color: darkred;
padding:20px;
}
.title{
width:100%;
height:30px;
text-align: center;
font-size: 25px;
color:white
}
.register_title{
width:100%;
height:30px;
text-align: center;
font-size: 25px;
color:white;
margin-left: -80px;
}
.input_account_div{
width:100%;
height:30px;
text-align: center;
color:white;
margin-left: -25px;
}
.input_password_div{
width:100%;
height:30px;
text-align: center;
color:white;
margin-left: -25px;
}
.submit_div{
width:100%;
height:30px;
text-align: center;
margin-left: -80px;
}
.password{
color: black;
}
.account{
color: black;
}
</style>
</head>
<body>
<div class="body">
<div class="title">开酱的记事本网站</div>
<br><br>
<div class="register_title">登录</div>
<br><br>
<div class="input_account_div">
<input class="account" type="text" id="account" placeholder="账号" />
</div>
<br>
<div class="input_password_div">
<input id="password" type="password" class="password" placeholder="密码"/>
</div>
<br>
<div class="submit_div">
<button onclick="register()">登录</button>
<a href="register.html">注册</a><br><br><br>
<a href="index.html">返回首页</a><br><br><br>
<script>
function register(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if(this.responseText=="login_success"){
alert("登录成功");
window.localStorage.setItem("account",document.getElementById("account").value)
window.location.href='index.html';
}else{
alert(this.responseText);
}
}
};
xhttp.open("GET", "http://192.168.1.5/login?account="+document.getElementById("account").value+"&password="+document.getElementById("password").value, true);
xhttp.send();
}
</script>
</div>
</div>
</body>
</html>
第五步:写后端代码(spring boot controller)
请看文件夹结构
CheckAccount.java
package com.example.xmkjstudio.check;
import com.example.xmkjstudio.databases.MySqlConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
/**
* @author 温国强
* @date 2022年11月06日 1:41 PM
*/
public class CheckAccount {
public static boolean check_account(String account){
//查询账号
//链接到数据库
Connection conn=null;
conn= MySqlConnection.getConnection(conn);
//查询数据表tb_user是否存在phone
ResultSet rs;
try {
Statement stmt=conn.createStatement();
rs = stmt.executeQuery("select*from user_list where account='"+account+"'");
if(rs.next()) {
conn.close();
return true;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}
}
CheckAccountWithPassword.java
package com.example.xmkjstudio.check;
import com.example.xmkjstudio.databases.MySqlConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
/**
* @author 温国强
* @date 2022年11月06日 1:32 PM
*/
public class CheckAccountWithPassword {
public static boolean check_account_with_password(String account,String password){
//查询账号
//链接到数据库
Connection conn=null;
conn= MySqlConnection.getConnection(conn);
//查询数据表tb_user是否存在phone
ResultSet rs;
try {
Statement stmt=conn.createStatement();
rs = stmt.executeQuery("select*from user_list where account='"+account+"'and password='"+password+"' ");
if(rs.next()) {
conn.close();
return true;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}
}
FileStorageConfig.java(这个不用,单纯为了追求完美copy过来,防止有人说我不完整!!!!😂)
package com.example.xmkjstudio.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//解决图片刷新载入不及时的问题
@Configuration
public class FileStorageConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/static/img/**").addResourceLocations("file:/root/");
registry.addResourceHandler("/static/**").addResourceLocations("file:/root/");
// registry.addResourceHandler("/**").addResourceLocations("file:/root/");
//下面这行代码解决生成html文件访问404 的问题
// registry.addResourceHandler("/**").addResourceLocations("file:/Users/wenguoqiang/Downloads/kj_chat/src/main/resources/static/");
}
}
GetNoteListController.java (controller不懂的去学下spring boot ,很简单的,又好用)
package com.example.xmkjstudio.controller;
import com.example.xmkjstudio.check.CheckAccountWithPassword;
import com.example.xmkjstudio.select.GetNoteList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author 温国强
* @date 2022年11月06日 1:27 PM
*/
@Controller
@CrossOrigin
public class GetNoteListController {
@ResponseBody
@RequestMapping("get_note_list")
public String login(String account){
System.out.println(GetNoteList.get_note_list(account));
return GetNoteList.get_note_list(account);
}
}
LoginController.java 代码很简单,都无需注释呀
package com.example.xmkjstudio.controller;
import com.example.xmkjstudio.check.CheckAccountWithPassword;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author 温国强
* @date 2022年11月06日 1:19 PM
*/
@Controller
@CrossOrigin
public class LoginController {
@ResponseBody
@RequestMapping("login")
public String login(String account,String password){
if(CheckAccountWithPassword.check_account_with_password(account,password)){
return "login_success";
}else{
return "login_fail";
}
}
}
RegisterController.java
package com.example.xmkjstudio.controller;
import com.example.xmkjstudio.check.CheckAccount;
import com.example.xmkjstudio.check.CheckAccountWithPassword;
import com.example.xmkjstudio.insert.Register;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author 温国强
* @date 2022年11月06日 1:27 PM
*/
@Controller
@CrossOrigin
public class RegisterController {
@ResponseBody
@RequestMapping("register")
public String login(String account,String password){
if(CheckAccount.check_account(account)){
return "the account is exit";
}else{
if(Register.register(account,password)){
return "register_success";
}else{
return "register_fail";
}
}
}
}
SaveNoteController.java
package com.example.xmkjstudio.controller;
import com.example.xmkjstudio.check.CheckAccount;
import com.example.xmkjstudio.insert.Register;
import com.example.xmkjstudio.insert.SaveNote;
import com.example.xmkjstudio.select.GetNoteList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @author 温国强
* @date 2022年11月06日 2:13 PM
*/
@Controller
@CrossOrigin
public class SaveNoteController {
@ResponseBody
@RequestMapping("note_submit")
public String login(String account,String note_content){
System.out.println(note_content);
if(SaveNote.save_note(account,note_content)){
return "note_submit_success";
}else{
return "note_submit_fail";
}
}
}
MySqlConnection.java 数据库操作公共类(里面的密码自己用自己的数据库哈)
package com.example.xmkjstudio.databases;
import java.sql.Connection;
import java.sql.DriverManager;
/**
* 数据库连接类
* 注意:与引入java连接mysql的驱动文件>>>>>在pom.xml 文件中添加依赖
* **/
public class MySqlConnection {
public static Connection getConnection(Connection conn) {
//数据库名字
String database_name="kj_note_website";
//
String url="jdbc:mysql://localhost:3306/"+database_name+"?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
//服务器mysql 用户名和密码 root zcoykMpn
//本地测试环境 数据库登录账号和密码
String user="root";
String pwd="";
//服务端mysql 登录账号和密码
String user_server="root";
String pwd_server="";
try {
Class.forName("com.mysql.cj.jdbc.Driver");//Java连接mysql固定格式
// conn=DriverManager.getConnection(url, user_server, pwd_server);//部署服务器
conn=DriverManager.getConnection(url, user, pwd);//对应上面定义的参数(本地测试)
}catch(Exception e) {
e.printStackTrace();
}
return conn;
}
//测试连接
public static void main(String[] args) {
Connection conn=null;
System.out.println(getConnection(conn));
}
}
NoteList.java 对象实体类
package com.example.xmkjstudio.entity;
/**
* @author 温国强
* @date 2022年11月06日 2:00 PM
*/
public class NoteList {
private int id;
private String account;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getNote_content() {
return note_content;
}
public void setNote_content(String note_content) {
this.note_content = note_content;
}
public String getCreate_time() {
return create_time;
}
public void setCreate_time(String create_time) {
this.create_time = create_time;
}
private String note_content;
private String create_time;
@Override
public String toString() {
return "Entity [id=" + id+ ",account=" +account + ",note_content=" +note_content+ ", create_time=" +create_time +"]";
}
}
Dao.java 这个类就是把数据库和实体类关联,取出数据转成json,另外需要在po m.xml文件中引入gson依赖
package com.example.xmkjstudio.entity_to_json;
import com.example.xmkjstudio.databases.MySqlConnection;
import com.example.xmkjstudio.entity.NoteList;
import com.google.gson.Gson;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class Dao {
//查询所有picture的所有信息
public List<NoteList> findPicture(String account){
String sql="select * from note_list where account='"+account+"' order by id desc ";
Connection conn=null;
conn = MySqlConnection.getConnection(conn);
ResultSet rs;
PreparedStatement ps;
List<NoteList> list = new ArrayList<NoteList>();
try {
ps = conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
NoteList p= new NoteList();
p.setId(rs.getInt(1));
p.setAccount(rs.getString(2));
p.setNote_content(rs.getString(3));
p.setCreate_time(rs.getString(4));
list.add(p);
}
conn.close();
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
// test
public static void main(String[] args) {
Dao dao = new Dao();
List<NoteList> i=dao.findPicture("1");
Gson gson = new Gson();
//在这里转化成json
String json =gson.toJson(i);
System.out.println(json);
}
}
Register.java
package com.example.xmkjstudio.insert;
import com.example.xmkjstudio.databases.MySqlConnection;
import com.example.xmkjstudio.time.GetNowTime;
import java.sql.Connection;
import java.sql.PreparedStatement;
/**
* @author 温国强
* @date 2022年11月06日 1:44 PM
*/
public class Register {
public static boolean register(String account,String password){
//链接到数据库
Connection conn=null;
conn= MySqlConnection.getConnection(conn);
//注册到用户注册登录表
PreparedStatement ps;
try {
ps=conn.prepareStatement("insert into user_list (account,password,create_time) values(?,?,?)");
ps.setString(1,account );
ps.setString(2,password);
ps.setString(3, GetNowTime.getNowTime());
ps.executeUpdate();
conn.close();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
SaveNote.java
package com.example.xmkjstudio.insert;
import com.example.xmkjstudio.databases.MySqlConnection;
import com.example.xmkjstudio.time.GetNowTime;
import java.sql.Connection;
import java.sql.PreparedStatement;
/**
* @author 温国强
* @date 2022年11月06日 1:44 PM
*/
public class Register {
public static boolean register(String account,String password){
//链接到数据库
Connection conn=null;
conn= MySqlConnection.getConnection(conn);
//注册到用户注册登录表
PreparedStatement ps;
try {
ps=conn.prepareStatement("insert into user_list (account,password,create_time) values(?,?,?)");
ps.setString(1,account );
ps.setString(2,password);
ps.setString(3, GetNowTime.getNowTime());
ps.executeUpdate();
conn.close();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
GetNoteList.java
package com.example.xmkjstudio.select;
import com.example.xmkjstudio.entity.NoteList;
import com.example.xmkjstudio.entity_to_json.Dao;
import com.google.gson.Gson;
import java.util.List;
/**
* @author 温国强
* @date 2022年11月06日 2:20 PM
*/
public class GetNoteList {
public static String get_note_list(String account){
Dao dao = new Dao();
List<NoteList> i=dao.findPicture(account);
Gson gson = new Gson();
//在这里转化成json
String json =gson.toJson(i);
return json;
}
}
GetNoTime.java 转时间格式的一个工具类
package com.example.xmkjstudio.time;
import java.text.SimpleDateFormat;
import java.util.Date;
public class GetNowTime {
public static String getNowTime() {
Date d=new Date();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=df.format(d);
return time;
}
}
ok,完整代码已经抛出了。
我们来个短视频看看效果吧(算了,审核太慢了,不等了,嘿嘿,等了会儿,通过了,看视频哈)
记事本网站
来个狠点的,我直接部署到服务器供大家学习使用了!!!!!!!