Java项目云笔记管理系统(java+uni-app+SpringBoot+Mybatis(MybatisPlus)+Maven+Mysql)
项目运行
环境配置:
Jdk1.8 + Tomcat(SpringBoot内置) + Mysql8 + HBuilderX(Webstorm也行)+IDEA(IntelliJ IDEA, Eclispe,MyEclispe,Sts都支持)。
项目技术:
JAVA + mybatis+spring + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
1. 后端:JAVA mybatis SpringBoot SpringMVC
2. 前端:uni-app,css,html
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
3.管理员账号:root 密码:123456
4.开发环境为Eclipse/idea,数据库为mysql 使用java语言开发。
5.运行NoteServiceApplication.java 即可打开首页
6.数据库连接src\main\resources\application.yml中修改
7.后台路径地址:localhost:8070
数据库设计
数据库名称为note_manager
![](https://i-blog.csdnimg.cn/blog_migrate/f2887a566fcf191d8b82035fd60ff351.png)
新建SpringBoot项目
![](https://i-blog.csdnimg.cn/blog_migrate/6a5df4adca9032598858d32381c1c3bb.png)
![](https://i-blog.csdnimg.cn/blog_migrate/c268b793a3eb02c11f58e1525b91e9ab.png)
导入pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.9</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.lps</groupId>
<artifactId>note-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>note-service</name>
<description>note-service</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <optional>true</optional>
</dependency>
<!-- mysql-connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.32</version>
</dependency>
<!-- mybatis-plus代码生成器 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
<!-- 文件上传:Begin -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- 文件上传:End -->
<!--跨服务器上传:Begin -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<!--跨服务器上传:End -->
<!-- mybatis-plus代码生成器 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml
server:
port: 8070
spring:
# 配置数据源信息
datasource:
# 配置数据源类型
type: com.zaxxer.hikari.HikariDataSource
# 配置连接数据库信息
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/note_manager?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: 123456
mybatis-plus:
type-aliases-package: com.lps.entity
configuration:
# 配置MyBatis日志,执行sql的时候,将sql打印到控制台
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
table-prefix: t_
id-type: assign_id
mapper-locations: classpath:mappers/*.xml
servlet:
multipart:
#设置单个文件的大小,-1表示不限制,单位MB
max-file-size: 100MB
#设置单次请求的文件总大小,-1表示不限制,单位MB
max-request-size: 1000MB
写入MyBatisPlus代码生成器类
package com.lps.generator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.Collections;
public class MyBatisPlusGenerator {
public static void main(String[] args) {
FastAutoGenerator.create("jdbc:mysql://localhost:3306/note_manager?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true", "root", "123456")
.globalConfig(builder -> {
builder.author("刘品水") // 设置作者
//.enableSwagger() // 开启 swagger 模式
.fileOverride() // 覆盖已生成文件
.outputDir("F:\\JavaPackage\\mybatisplusGenerator"); // 指定输出目录
})
.packageConfig(builder -> {
builder.parent("com") // 设置父包名
.moduleName("lps") // 设置父包模块名
.pathInfo(Collections.singletonMap(OutputFile.mapperXml,"F:\\JavaPackage\\mybatisplusGenerator")); // 设置mapperXml生成路径
})
.strategyConfig(builder -> {
builder.addInclude("t_channel", "t_note","t_comment","t_user") // 设置需要生成的表名,多张表可以传递多个String类型的参数
.addTablePrefix("t_","my_"); // 设置过滤表前缀
})
.templateEngine(new FreemarkerTemplateEngine())
// 使用Freemarker引擎模板,默认的是Velocity引擎模板
.execute();
}
}
将生成的四层架构导入即可
![](https://i-blog.csdnimg.cn/blog_migrate/9eedb6a5d0b29fa966eef56ded783fe1.png)
SpringBoot启动类
NoteServiceApplication.java
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@MapperScan("com.lps.mapper")
//映射扫描
public class NoteServiceApplication {
public static void main(String[] args) {
SpringApplication.run(NoteServiceApplication.class, args);
}
}
文件上传工具类
JesyFileUploadUtil.java
package com.lps.utils;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.Date;
import java.util.Random;
/**
* 跨服务器文件上传工具类
*
* @author 刘品水
*
*/
public class JesyFileUploadUtil {
/**
* 上传文件
*
* @param file --文件名
* @param serverUrl --服务器路径http://127.0.0.1:8080/ssm_image_server
* @return
* @throws IOException
*/
public static String uploadFile(MultipartFile file, String serverUrl) throws IOException {
//重新设置文件名
String newFileName = new Date().getTime()+""; //将当前时间获得的毫秒数拼接到新的文件名上
//随机生成一个3位的随机数
SecureRandom r = new SecureRandom();
for(int i=0; i<3; i++) {
newFileName += r.nextInt(10); //生成一个0-10之间的随机整数
}
//获取文件的扩展名
String orginalFilename = file.getOriginalFilename();
String suffix = orginalFilename.substring(orginalFilename.indexOf("."));
//创建jesy服务器,进行跨服务器上传
Client client = Client.create();
//把文件关联到远程服务器
//例如:http://127.0.0.1:8080/ssm_image_server/upload/123131312321.jpg
WebResource resource = client.resource(serverUrl+"/"+newFileName+suffix);
//上传
//获取文件的上传流
resource.put(String.class, file.getBytes());
//图片上传成功后要做的事儿
//1、ajax回调函数做图片回显(需要图片的完整路径)
//2、将图片的路径保存到数据库(需要图片的相对路径)
// String fullPath = serverUrl+"/upload/"+newFileName+suffix; //全路径
String relativePath = "/upload/"+newFileName+suffix; //相对路径
return relativePath;
}
}
实体类都生成了就不再介绍
这边新写一个实体类HttpResult.java
package com.lps.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data//导入Lombok依赖
@AllArgsConstructor
@NoArgsConstructor
public class HttpResult {
private int code;
private String msg;
private Object data;
private int total;
}
mapper层(目前就一个note要自己写mybatis 其他的用plus就好)
import com.lps.entity.Note;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author 刘品水
* @since 2023-03-05
*/
@Repository
public interface NoteMapper extends BaseMapper<Note> {
List<Note> selectByLimit(String title, Long cid, Integer pageIndex, Integer pageSize);
Integer count(String title, Long cid);
Note findById(Long id);
}
Mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lps.mapper.NoteMapper">
<resultMap id="noteMapper" type="Note">
<result column="id" property="id"></result>
<result column="title" property="title"></result>
<result column="publish_time" property="publishTime"></result>
<result column="cid" property="cid"></result>
<result column="content" property="content"></result>
<result column="attachment" property="attachment"></result>
<result column="logo" property="logo"></result>
<result column="is_delete" property="isDelete"></result>
<association property="channel" javaType="Channel">
<result column="id" property="id"></result>
<result column="channel_name" property="channelName"></result>
<result column="type" property="type"></result>
</association>
</resultMap>
<select id="findById" resultMap="noteMapper">
select * from t_note inner join t_channel on t_note.cid=t_channel.id where t_note.id=#{id};
</select>
<select id="selectByLimit" resultMap="noteMapper">
SELECT
t_note.*, t_channel.channel_name
FROM
t_note
LEFT JOIN
t_channel
ON
t_note.cid=t_channel.id
<where>
t_note.is_delete=0
<if test="title !='null' and title != ''">
AND t_note.title LIKE CONCAT('%', #{title}, '%')
</if>
<if test="cid !=null and cid != 0">
AND t_note.cid = #{cid}
</if>
</where>
ORDER BY
t_note.publish_time
DESC
LIMIT
#{pageIndex}, #{pageSize}
</select>
<select id="count" resultType="java.lang.Integer">
SELECT count(*) FROM t_note LEFT JOIN t_channel ON t_note.cid=t_channel.id
<where>
t_note.is_delete=0
<if test="cid !=null and cid != 0">
AND t_note.cid=#{cid}
</if>
<if test="title !='null' and title != ''">
AND t_note.title like CONCAT('%', #{title}, '%')
</if>
</where>
</select>
</mapper>
Service层
public interface IUserService {
HttpResult findAll();
HttpResult login(User user);
HttpResult remove(Long id);
}
public interface INoteService {
HttpResult findAll(String title, Long cid, Integer pageIndex, Integer pageSize);
HttpResult save(Note note);
HttpResult modify(Note note);
HttpResult remove(Long id);
HttpResult findById(Long id);
HttpResult findCount(String title, Long cid);
}
public interface IContentService {
HttpResult findAll(Long nid);
HttpResult save(Content content);
}
public interface IChannelService {
HttpResult add(Channel channel);
HttpResult delete(Long id);
HttpResult update(Channel channel);
HttpResult findAll();
HttpResult findById(Long id);
}
service层的实现类
package com.lps.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lps.entity.HttpResult;
import com.lps.entity.User;
import com.lps.mapper.UserMapper;
import com.lps.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author 刘品水
* @since 2023-03-06
*/
@Service
public class UserServiceImpl implements IUserService {
@Autowired(required = false)
private UserMapper userMapper;
@Override
public HttpResult findAll() {
HttpResult httpResult = null;
List<User> users = userMapper.selectList(null);
if (users != null && users.size() > 0) {
httpResult = new HttpResult(200, "数据ok的", users, 0);
} else {
httpResult = new HttpResult(500, "数据没有", null, 0);
}
return httpResult;
}
@Override
public HttpResult login(User user) {
HttpResult httpResult = null;
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
//连续的写
queryWrapper.eq("user_name", user.getUserName()).eq("passwd", user.getPasswd());
User users = userMapper.selectOne(queryWrapper);
if (users != null) {
httpResult = new HttpResult(200, "登陆成功", users, 0);
} else {
httpResult = new HttpResult(500, "登陆失败,账号或者密码有错!", null, 0);
}
return httpResult;
}
@Override
public HttpResult remove(Long id) {
HttpResult httpResult = null;
int cnt = userMapper.deleteById(id);
if (cnt > 0) {
httpResult = new HttpResult(200, "删除成功", "删除成功", 0);
} else {
httpResult = new HttpResult(500, "删除失败,联系管理员哈", "删除失败,联系管理员哈", 0);
}
return httpResult;
}
}
package com.lps.service.impl;
import com.lps.entity.HttpResult;
import com.lps.entity.Note;
import com.lps.mapper.NoteMapper;
import com.lps.service.INoteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author 刘品水
* @since 2023-03-05
*/
@Service
public class NoteServiceImpl implements INoteService {
@Autowired(required = false)
private NoteMapper noteMapper;
@Override
public HttpResult findAll(String title, Long cid, Integer pageIndex, Integer pageSize) {
List<Note> all = noteMapper.selectByLimit(title, cid, (pageIndex - 1) * pageSize, pageSize);
HttpResult result = null;
if(all != null && all.size() > 0){
result = new HttpResult(200, "查询成功", all, noteMapper.count(title, cid));
} else {
result = new HttpResult(500, "没有更多数据", null, 0);
}
return result;
}
@Override
public HttpResult save(Note note) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = format.format(new Date());
note.setPublishTime(dateStr);
int cnt = noteMapper.insert(note);
HttpResult result = null;
if(cnt > 0){
result = new HttpResult(200, "添加笔记成功", null, 0);
} else {
result = new HttpResult(500, "添加笔记失败", null, 0);
}
return result;
}
@Override
public HttpResult modify(Note note) {
int cnt = noteMapper.updateById(note);
HttpResult result = null;
if(cnt > 0){
result = new HttpResult(200, "修改笔记成功", null, 0);
} else {
result = new HttpResult(500, "修改笔记失败", null, 0);
}
return result;
}
@Override
public HttpResult remove(Long id) {
int cnt = noteMapper.deleteById(id);
HttpResult result = null;
if(cnt > 0){
result = new HttpResult(200, "删除笔记成功", null, 0);
} else {
result = new HttpResult(500, "删除笔记失败", null, 0);
}
return result;
}
@Override
public HttpResult findById(Long id) {
Note note = noteMapper.findById(id);
HttpResult result = null;
if(note != null){
result = new HttpResult(200, "查询成功", note, 0);
} else {
result = new HttpResult(500, "没有更多数据", null, 0);
}
return result;
}
@Override
public HttpResult findCount(String title, Long cid) {
int count= noteMapper.count(title,cid);
HttpResult result = null;
if(count >0){
result = new HttpResult(200, "查询成功", count, 0);
} else {
result = new HttpResult(500, "没有更多数据", null, 0);
}
return result;
}
}
package com.lps.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lps.entity.Content;
import com.lps.entity.HttpResult;
import com.lps.entity.Note;
import com.lps.mapper.ContentMapper;
import com.lps.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author 阿水
* @create 2023-03-08 14:31
*/
@Service
public class ContentServiceImpl implements IContentService {
@Autowired
private ContentMapper contentMapper;
@Override
public HttpResult findAll(Long nid) {
QueryWrapper<Content> qw = new QueryWrapper<>();
qw.eq("nid", nid);
List<Content> all = contentMapper.selectList(qw);
HttpResult result = null;
if(all != null && all.size() > 0){
result = new HttpResult(200, "查询成功", all, 0);
} else {
result = new HttpResult(500, "没有更多数据", null, 0);
}
return result;
}
@Override
public HttpResult save(Content content) {
int cnt = contentMapper.insert(content);
HttpResult result = null;
if(cnt > 0){
result = new HttpResult(200, "添加内容成功", null, 0);
} else {
result = new HttpResult(500, "添加内容失败", null, 0);
}
return result;
}
}
package com.lps.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lps.entity.Channel;
import com.lps.entity.HttpResult;
import com.lps.entity.User;
import com.lps.mapper.ChannelMapper;
import com.lps.service.IChannelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 栏目表 服务实现类
* </p>
*
* @author 刘品水
* @since 2023-03-06
*/
@Service
public class ChannelServiceImpl implements IChannelService {
@Autowired
private ChannelMapper channelMapper;
@Override
public HttpResult add(Channel channel) {
HttpResult httpResult = null;
int cnt = channelMapper.insert(channel);
if (cnt >0 ) {
httpResult = new HttpResult(200, "添加ok的", null, 0);
} else {
httpResult = new HttpResult(500, "失败", null, 0);
}
return httpResult;
}
@Override
public HttpResult delete(Long id) {
HttpResult httpResult = null;
int cnt = channelMapper.deleteById(id);
if (cnt >0 ) {
httpResult = new HttpResult(200, "删除ok的", null, 0);
} else {
httpResult = new HttpResult(500, "失败", null, 0);
}
return httpResult;
}
@Override
public HttpResult update(Channel channel) {
HttpResult httpResult = null;
int cnt = channelMapper.updateById(channel);
if (cnt >0 ) {
httpResult = new HttpResult(200, "更新ok的", null, 0);
} else {
httpResult = new HttpResult(500, "失败", null, 0);
}
return httpResult;
}
@Override
public HttpResult findAll() {
HttpResult httpResult = null;
List<Channel> users = channelMapper.selectList(null);
if (users != null && users.size() > 0) {
httpResult = new HttpResult(200, "查询全部ok的", users, 0);
} else {
httpResult = new HttpResult(500, "失败", null, 0);
}
return httpResult;
}
@Override
public HttpResult findById(Long id) {
HttpResult httpResult = null;
QueryWrapper<Channel> queryWrap = new QueryWrapper<>();
queryWrap.eq("id", id);
Channel users = channelMapper.selectOne(queryWrap);
if (users != null ) {
httpResult = new HttpResult(200, "数据ok的", users, 0);
} else {
httpResult = new HttpResult(500, "失败", null, 0);
}
return httpResult;
}
}
Controller层
package com.lps.controller;
import com.lps.entity.Channel;
import com.lps.entity.HttpResult;
import com.lps.service.IChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
/**
* <p>
* 栏目表 前端控制器
* </p>
*
* @author 刘品水
* @since 2023-03-06
*/
@RestController
@RequestMapping("/channel")
@CrossOrigin(origins = "*")
public class ChannelController {
@Autowired
private IChannelService channelService;
@PostMapping("/save")
public HttpResult add(@RequestBody Channel channel) {
return channelService.add(channel);
}
@GetMapping("/remove")
public HttpResult delete(Long id) {
return channelService.delete(id);
}
@PostMapping("/modify")
public HttpResult update(@RequestBody Channel channel) {
return channelService.update(channel);
}
@GetMapping("/list")
public HttpResult findAll() {
return channelService.findAll();
}
@GetMapping("/get")
public HttpResult findById(Long id) {
return channelService.findById(id);
}
}
package com.lps.controller;
import com.lps.entity.Channel;
import com.lps.entity.Content;
import com.lps.entity.HttpResult;
import com.lps.service.IChannelService;
import com.lps.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author 阿水
* @create 2023-03-08 14:39
*/
@RestController
@RequestMapping("/content")
@CrossOrigin(origins = "*")
public class ContentController {
@Autowired
private IContentService contentService;
@PostMapping("/save")
public HttpResult add(@RequestBody Content content) {
return contentService.save(content);
}
@GetMapping("/list")
public HttpResult findAll(Long nid) {
return contentService.findAll(nid);
}
}
package com.lps.controller;
import com.lps.entity.HttpResult;
import com.lps.entity.Note;
import com.lps.service.INoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
/**
* <p>
* 前端控制器
* </p>
*
* @author 刘品水
* @since 2023-03-05
*/
@RestController
@RequestMapping("/note")
@CrossOrigin(origins = "*")
public class NoteController {
@Autowired
private INoteService noticeService;
@PostMapping("/save")
public HttpResult savePaper(@RequestBody Note paper){
return noticeService.save(paper);
}
@PostMapping("/modify")
public HttpResult modifyPaper(@RequestBody Note paper){
return noticeService.modify(paper);
}
@GetMapping("/remove")
public HttpResult remove(Long id){
return noticeService.remove(id);
}
@GetMapping("/list")
public HttpResult findAll(String title, Long cid, Integer pageIndex, Integer pageSize){
return noticeService.findAll(title, cid, pageIndex, pageSize);
}
@GetMapping("/get")
public HttpResult findById(Long id){
return noticeService.findById(id);
}
@GetMapping("/test")
public String test(){
System.out.println("ok");
return "test方法被访问啦 哈哈嗨";
}
}
package com.lps.controller;
import com.lps.utils.JesyFileUploadUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.MulticastSocket;
/**
* @author 阿水
* @create 2023-03-07 10:04
*/
@RestController
@RequestMapping("/upload")
@CrossOrigin(origins = "*")
public class UploadController {
@PostMapping("/file")
public String uploadFile(MultipartFile fileName){
String path="";
try {
path=JesyFileUploadUtil.uploadFile(fileName, "http://localhost:8060/upload");
} catch (IOException e) {
throw new RuntimeException(e);
}
return path;
}
}
package com.lps.controller;
import com.lps.entity.HttpResult;
import com.lps.entity.User;
import com.lps.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
/**
* <p>
* 前端控制器
* </p>
*
* @author 刘品水
* @since 2023-03-06
*/
@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "*")
public class UserController {
@Autowired
private IUserService userService;
@GetMapping("/list")
public HttpResult findAll(){
return userService.findAll();
};
@PostMapping("/login")
public HttpResult login(@RequestBody User user){
return userService.login(user);
};
@GetMapping("/remove")
public HttpResult remove(Long id){
return userService.remove(id);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/54f6fa15eef3a406dfa1dd1c3cc03fc4.png)
启动tomcat的文件服务器(设置端口为8060)
conf的web.xml和service.xml进行修改
![](https://i-blog.csdnimg.cn/blog_migrate/a0a36fb90b2238870d99696ebc55aad9.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f406d964db0017030564e9469befa77d.png)
![](https://i-blog.csdnimg.cn/blog_migrate/2e6113dd5541aea9141f2a439b956cd1.png)
输入startup.bat运行(需系统环境变量设置好jdk的路径)
![](https://i-blog.csdnimg.cn/blog_migrate/b75c921a139049ee35cd80055ae6d50c.png)
后端就OK啦