日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

java 云笔记_简单的云笔记项目源码(含数据库脚本,适合新手)

發(fā)布時間:2024/3/12 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 云笔记_简单的云笔记项目源码(含数据库脚本,适合新手) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

【實例簡介】簡單的云筆記項目,登錄、注冊、發(fā)布云筆記、查詢云筆記等基本功能

【實例截圖】

【核心代碼】

package cn.tedu.userdiary.controller;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import cn.tedu.userdiary.entity.Content;

import cn.tedu.userdiary.entity.User;

import cn.tedu.userdiary.service.UserService;

import cn.tedu.userdiary.util.JsonResult;

@RequestMapping("users")

@RestController

public class UserController {

private final Integer OK=5000;

@Autowired

private UserService userService;

//用戶注冊

@PostMapping("reg")

public JsonResult getReg(User user){

System.out.println("UserController.getReg()");

//用戶數(shù)據(jù)注冊

userService.reg(user);

return new JsonResult<>(OK);

}

//用戶登錄

@PostMapping("login")

public JsonResult login(User user,HttpSession session){

System.err.println("UserController.login()");

//用戶數(shù)據(jù)登錄

User data=userService.login(user);

session.setAttribute("uid", data.getUid());

session.setAttribute("username", data.getUsername());

return new JsonResult<>(OK);

}

//用戶添加內(nèi)容

@PostMapping("add")

public JsonResult addcontent(HttpSession session,Content content){

Integer uid = Integer.valueOf(session.getAttribute("uid").toString());

System.err.println("uid=" uid);

userService.addcontents(content, uid);

return new JsonResult(OK);

}

//http://localhost:8080/users/getContent?keyword='55'

//根據(jù)用戶輸入的關(guān)鍵字匹配查詢

@GetMapping("getContent")

public JsonResult> content(String keyword,HttpSession session){

System.err.println("UserController.content()");

Integer pages;

List content=userService.findKeyword(keyword);

session.setAttribute("content", content);

if(content.size()<=10) {

return new JsonResult<>(OK,content);

}

if(content.size()%10!=0) {

pages=content.size()/10 1;

}else {

pages=content.size()/10;

}

System.err.println("pages=" pages);

Map> contentMap=new HashMap>();

Integer nbs=10;

Integer index=0;

for (int j = 0; j < pages; j ) {

List list=new ArrayList();

contentMap.put("page" j, list);

for (int i = 0; i < nbs; i ) {

if(j 1==pages) {

System.err.println("這是最后一頁");

if(content.size()%10!=0) {

System.err.println("最后一頁裝載");

nbs=content.size()%10;

System.err.println("nbs=" nbs);

}

}

Content contents=content.get(index);

list.add(contents);

index ;

}

}

session.setAttribute("contentMap", contentMap);

//將總頁數(shù)存儲在第一個數(shù)據(jù)中

content.get(0).setPages(pages);

//默認(rèn)發(fā)送前10條數(shù)據(jù)

List contents=new ArrayList();

for (int i = 0; i < 10; i ) {

contents.add(content.get(i));

}

return new JsonResult<>(OK,contentMap.get("page0"));

}

//根據(jù)發(fā)送過來的頁數(shù),返回相應(yīng)的數(shù)據(jù)

@GetMapping("paging")

public JsonResult> paging(Integer page,HttpSession session){

System.out.println("UserController.paging()");

Map> contentMap=(Map>)session.getAttribute("contentMap");

return new JsonResult<>(OK,contentMap.get("page" (page-1)));

}

@PostMapping("getContent")

public JsonResult getContents(Integer page,Integer k,HttpSession session){

System.out.println("UserController.getContent()");

Map> contentMap=(Map>)session.getAttribute("contentMap");

Content content=contentMap.get("page" (page-1)).get(k);

return new JsonResult<>(OK,content);

}

}

總結(jié)

以上是生活随笔為你收集整理的java 云笔记_简单的云笔记项目源码(含数据库脚本,适合新手)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。