├── 项目截图 ├── 首页.png ├── 功能图.png ├── 后台登录.png ├── 用户列表.jpg ├── 用户注册.png ├── 用户留言.png ├── 留言列表.png ├── 美食活动.png ├── 美食照片.png ├── 节日美食.png ├── 项目文件.png ├── 首页推荐.png ├── 首页管理.png ├── 美食活动后台.png ├── 美食照片后台.png └── 节日美食1.png ├── foodmanagement ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── design │ │ │ └── foodmanagement │ │ │ └── FoodmanagementApplicationTests.java │ └── main │ │ ├── java │ │ └── com │ │ │ └── design │ │ │ └── foodmanagement │ │ │ ├── pojo │ │ │ ├── res │ │ │ │ ├── Code.java │ │ │ │ └── RestFulBean.java │ │ │ ├── Message.java │ │ │ ├── Users.java │ │ │ ├── Image.java │ │ │ ├── FestivalFood.java │ │ │ ├── MainMenu.java │ │ │ └── Submenu.java │ │ │ ├── FoodmanagementApplication.java │ │ │ ├── util │ │ │ ├── PageUtil.java │ │ │ ├── TimeUtil.java │ │ │ ├── FileUtil.java │ │ │ └── RedisUtil.java │ │ │ ├── mapper │ │ │ ├── SubmenuMapper.java │ │ │ ├── UsersMapper.java │ │ │ ├── MessageMapper.java │ │ │ ├── ImageMapper.java │ │ │ ├── FestivalFoodMapper.java │ │ │ └── MainMenuMapper.java │ │ │ ├── config │ │ │ ├── WebConfig.java │ │ │ └── RedisConfig.java │ │ │ ├── controller │ │ │ ├── OpenController.java │ │ │ ├── SubmenuController.java │ │ │ ├── UsersController.java │ │ │ ├── MessageController.java │ │ │ ├── ImageController.java │ │ │ ├── MainMenuController.java │ │ │ └── FestivalFoodController.java │ │ │ ├── service │ │ │ ├── SubmenuService.java │ │ │ ├── UsersService.java │ │ │ ├── MessageService.java │ │ │ ├── ImageService.java │ │ │ ├── MainMenuService.java │ │ │ ├── FestivalFoodService.java │ │ │ └── impl │ │ │ │ ├── SubmenuServiceImpl.java │ │ │ │ ├── MessageServiceImpl.java │ │ │ │ ├── UsersServiceImpl.java │ │ │ │ ├── ImageServiceImpl.java │ │ │ │ ├── MainMenuServiceImpl.java │ │ │ │ └── FestivalFoodServiceImpl.java │ │ │ ├── dto │ │ │ └── Page.java │ │ │ └── exception │ │ │ └── GlobalExceptionHandler.java │ │ └── resources │ │ ├── application.yml │ │ └── mapper │ │ ├── MessageMapper.xml │ │ ├── ImageMapper.xml │ │ ├── UsersMapper.xml │ │ ├── MainMenuMapper.xml │ │ ├── SubmenuMapper.xml │ │ └── FestivalFoodMapper.xml ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw └── README.md /项目截图/首页.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/首页.png -------------------------------------------------------------------------------- /项目截图/功能图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/功能图.png -------------------------------------------------------------------------------- /项目截图/后台登录.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/后台登录.png -------------------------------------------------------------------------------- /项目截图/用户列表.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/用户列表.jpg -------------------------------------------------------------------------------- /项目截图/用户注册.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/用户注册.png -------------------------------------------------------------------------------- /项目截图/用户留言.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/用户留言.png -------------------------------------------------------------------------------- /项目截图/留言列表.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/留言列表.png -------------------------------------------------------------------------------- /项目截图/美食活动.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/美食活动.png -------------------------------------------------------------------------------- /项目截图/美食照片.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/美食照片.png -------------------------------------------------------------------------------- /项目截图/节日美食.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/节日美食.png -------------------------------------------------------------------------------- /项目截图/项目文件.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/项目文件.png -------------------------------------------------------------------------------- /项目截图/首页推荐.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/首页推荐.png -------------------------------------------------------------------------------- /项目截图/首页管理.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/首页管理.png -------------------------------------------------------------------------------- /项目截图/美食活动后台.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/美食活动后台.png -------------------------------------------------------------------------------- /项目截图/美食照片后台.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/美食照片后台.png -------------------------------------------------------------------------------- /项目截图/节日美食1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/项目截图/节日美食1.png -------------------------------------------------------------------------------- /foodmanagement/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huoming123/foodmanagement/HEAD/foodmanagement/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /foodmanagement/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /foodmanagement/src/test/java/com/design/foodmanagement/FoodmanagementApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FoodmanagementApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/res/Code.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo.res; 2 | 3 | public enum Code { 4 | SUCCESS(2000), 5 | // 请求参数错误 6 | BAD_REQUEST(4000), 7 | // 未授权 8 | UNAUTHORIZED(4001), 9 | // 未登入 10 | NOT_lOG_IN(4022), 11 | // 错误 12 | ERROR(5000), 13 | // 数据库错误 14 | DATABASE_ERROR(5005), 15 | Null_Pointer(5010); 16 | 17 | int code; 18 | Code(int code){this.code = code;} 19 | } 20 | -------------------------------------------------------------------------------- /foodmanagement/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/FoodmanagementApplication.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.ComponentScan; 7 | 8 | @SpringBootApplication 9 | @MapperScan("com.design.foodmanagement.mapper") 10 | @ComponentScan(value="com.design") 11 | public class FoodmanagementApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(FoodmanagementApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/util/PageUtil.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.util; 2 | 3 | 4 | import com.design.foodmanagement.dto.Page; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class PageUtil { 10 | public static Map pagingPrepare(Page page, int count) throws Exception { 11 | Map map = new HashMap<>(); 12 | if (page.getPageNum() <= 0 || page.getPageSize()<= 0 ) { 13 | throw new Exception("页数和数量不正确"); 14 | } 15 | int i = count / page.getPageSize(); 16 | i = count-(page.getPageSize()*i) == 0? i:++i; 17 | i = i == 0 ? 1 : i; 18 | map.put("pageNum", i); //最大有多少页 19 | map.put("total", count); //总条数 20 | return map; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/mapper/SubmenuMapper.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.mapper; 2 | 3 | import com.design.foodmanagement.pojo.Submenu; 4 | import java.util.List; 5 | import org.apache.ibatis.annotations.Param; 6 | /** 7 | * (Submenu)表数据库访问层 8 | * 9 | * @author makejava 10 | * @since 2022-07-02 09:07:08 11 | */ 12 | public interface SubmenuMapper { 13 | 14 | 15 | /** 16 | * 通过主键删除数据 17 | * 18 | * @param id 主键 19 | * @return 影响行数 20 | */ 21 | int deleteById(Integer id); 22 | 23 | void addMenu(Submenu submenu); 24 | 25 | void updateMenu(Submenu submenu); 26 | 27 | List getSubMenu(); 28 | 29 | List getByMainId(Integer id); 30 | 31 | Submenu queryById(Integer id); 32 | 33 | void insert(Submenu submenu); 34 | 35 | void update(Submenu submenu); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/config/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.config; 2 | import org.springframework.context.annotation.Configuration; 3 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 4 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 5 | 6 | @Configuration 7 | public class WebConfig implements WebMvcConfigurer { 8 | @Override 9 | public void addCorsMappings(CorsRegistry registry) { 10 | registry.addMapping("/**") 11 | .exposedHeaders("content-disposition") 12 | //解决前后端跨域问题 13 | .allowedOriginPatterns("http://localhost:8081","http://localhost:8080","http://localhost:8082") 14 | .allowCredentials(true) 15 | .allowedMethods("GET", "POST", "DELETE", "PUT") 16 | .maxAge(3600); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/controller/OpenController.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.controller; 2 | import com.design.foodmanagement.pojo.Users; 3 | import com.design.foodmanagement.pojo.res.RestFulBean; 4 | import com.design.foodmanagement.service.UsersService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.PostMapping; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.Map; 11 | 12 | @RestController 13 | public class OpenController { 14 | 15 | @Autowired 16 | private UsersService userService; 17 | /** 18 | * 19 | * @param Users 需要teachNo和password 20 | * @return data token 21 | */ 22 | @PostMapping("/login") 23 | public RestFulBean login(@RequestBody Users Users) throws Exception { 24 | return userService.login(Users); 25 | } 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/SubmenuService.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service; 2 | 3 | import com.design.foodmanagement.pojo.Submenu; 4 | import com.design.foodmanagement.pojo.res.RestFulBean; 5 | /** 6 | * (Submenu)表服务接口 7 | * 8 | * @author makejava 9 | * @since 2022-07-02 09:07:08 10 | */ 11 | public interface SubmenuService { 12 | 13 | /** 14 | * 通过ID查询单条数据 15 | * 16 | * @param id 主键 17 | * @return 实例对象 18 | */ 19 | RestFulBean queryById(Integer id); 20 | 21 | 22 | /** 23 | * 新增数据 24 | * 25 | * @param submenu 实例对象 26 | * @return 实例对象 27 | */ 28 | RestFulBean insert(Submenu submenu); 29 | 30 | /** 31 | * 修改数据 32 | * 33 | * @param submenu 实例对象 34 | * @return 实例对象 35 | */ 36 | RestFulBean update(Submenu submenu); 37 | 38 | /** 39 | * 通过主键删除数据 40 | * 41 | * @param id 主键 42 | * @return 是否成功 43 | */ 44 | RestFulBean deleteById(Integer id); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/UsersService.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service; 2 | 3 | import com.design.foodmanagement.dto.Page; 4 | import com.design.foodmanagement.pojo.Users; 5 | import com.design.foodmanagement.pojo.res.RestFulBean; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * (Users)表服务接口 11 | * 12 | * @author makejava 13 | * @since 2022-08-30 10:36:43 14 | */ 15 | public interface UsersService { 16 | 17 | /** 18 | * 通过ID查询单条数据 19 | * 20 | * @param id 主键 21 | * @return 实例对象 22 | */ 23 | RestFulBean queryById(Integer id); 24 | 25 | 26 | /** 27 | * 新增数据 28 | * 29 | * @param users 实例对象 30 | * @return 实例对象 31 | */ 32 | RestFulBean insert(Users users); 33 | 34 | /** 35 | * 修改数据 36 | * 37 | * @param users 实例对象 38 | * @return 实例对象 39 | */ 40 | RestFulBean update(Users users); 41 | 42 | /** 43 | * 通过主键删除数据 44 | * 45 | * @param id 主键 46 | * @return 是否成功 47 | */ 48 | RestFulBean deleteById(Integer id); 49 | 50 | RestFulBean login(Users users); 51 | 52 | RestFulBean getList(Page page) throws Exception; 53 | } 54 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/mapper/UsersMapper.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.mapper; 2 | 3 | import com.design.foodmanagement.dto.Page; 4 | import com.design.foodmanagement.pojo.Users; 5 | import org.apache.ibatis.annotations.Param; 6 | import java.util.List; 7 | 8 | /** 9 | * (Users)表数据库访问层 10 | * 11 | * @author makejava 12 | * @since 2022-08-30 10:36:44 13 | */ 14 | public interface UsersMapper { 15 | 16 | /** 17 | * 通过ID查询单条数据 18 | * 19 | * @param id 主键 20 | * @return 实例对象 21 | */ 22 | Users queryById(Integer id); 23 | 24 | 25 | /** 26 | * 新增数据 27 | * 28 | * @param users 实例对象 29 | * @return 影响行数 30 | */ 31 | int insert(Users users); 32 | 33 | 34 | /** 35 | * 修改数据 36 | * 37 | * @param users 实例对象 38 | * @return 影响行数 39 | */ 40 | int update(Users users); 41 | 42 | /** 43 | * 通过主键删除数据 44 | * 45 | * @param id 主键 46 | * @return 影响行数 47 | */ 48 | int deleteById(Integer id); 49 | 50 | Users getByEmailAndRole(String email); 51 | 52 | List getPageListByCondition(@Param("page") Page page); 53 | 54 | Integer getPageListCount(@Param("page")Page page); 55 | 56 | Users getByEmail(String email); 57 | } 58 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/MessageService.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service; 2 | 3 | import com.design.foodmanagement.pojo.Message; 4 | import com.design.foodmanagement.pojo.res.RestFulBean; 5 | import com.design.foodmanagement.dto.Page; 6 | import java.io.IOException; 7 | import java.util.Map; 8 | /** 9 | * (Message)表服务接口 10 | * 11 | * @author makejava 12 | * @since 2022-09-03 10:51:47 13 | */ 14 | public interface MessageService { 15 | 16 | /** 17 | * 分页查找数据 18 | * 19 | * @param //前端传来的参数 20 | * @return 实例对象 21 | */ 22 | RestFulBean getList(Page page)throws Exception; 23 | /** 24 | * 通过ID查询单条数据 25 | * 26 | * @param id 主键 27 | * @return 实例对象 28 | */ 29 | RestFulBean queryById(Integer id); 30 | 31 | 32 | /** 33 | * 新增数据 34 | * 35 | * @param message 实例对象 36 | * @return 实例对象 37 | */ 38 | RestFulBean insert(Message message); 39 | 40 | /** 41 | * 修改数据 42 | * 43 | * @param message 实例对象 44 | * @return 实例对象 45 | */ 46 | RestFulBean update(Message message); 47 | 48 | /** 49 | * 通过主键删除数据 50 | * 51 | * @param id 主键 52 | * @return 是否成功 53 | */ 54 | RestFulBean deleteById(Integer id); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/Message.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo; 2 | 3 | import java.util.Date; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * (Message)实体类 8 | * 9 | * @author makejava 10 | * @since 2022-09-03 10:51:47 11 | */ 12 | public class Message implements Serializable { 13 | private static final long serialVersionUID = 760001032978659388L; 14 | 15 | private Integer id; 16 | /** 17 | * 邮箱账号 18 | */ 19 | private String email; 20 | /** 21 | * 留言 22 | */ 23 | private String message; 24 | /** 25 | * 留言时间 26 | */ 27 | private Date createdAt; 28 | 29 | 30 | public Integer getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Integer id) { 35 | this.id = id; 36 | } 37 | 38 | public String getEmail() { 39 | return email; 40 | } 41 | 42 | public void setEmail(String email) { 43 | this.email = email; 44 | } 45 | 46 | public String getMessage() { 47 | return message; 48 | } 49 | 50 | public void setMessage(String message) { 51 | this.message = message; 52 | } 53 | 54 | public Date getCreatedAt() { 55 | return createdAt; 56 | } 57 | 58 | public void setCreatedAt(Date createdAt) { 59 | this.createdAt = createdAt; 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/mapper/MessageMapper.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.mapper; 2 | 3 | import com.design.foodmanagement.pojo.Message; 4 | import java.util.List; 5 | import com.design.foodmanagement.dto.Page; 6 | import org.apache.ibatis.annotations.Param; 7 | /** 8 | * (Message)表数据库访问层 9 | * 10 | * @author makejava 11 | * @since 2022-09-03 10:51:47 12 | */ 13 | public interface MessageMapper { 14 | 15 | /** 16 | * 通过ID查询单条数据 17 | * 18 | * @param id 主键 19 | * @return 实例对象 20 | */ 21 | Message queryById(Integer id); 22 | 23 | /** 24 | * 分页查询数据 25 | * 26 | * @param 27 | * @return 实例对象 28 | */ 29 | List getPageListByCondition(@Param("page") Page page); 30 | /** 31 | * 分页查询数据 查询总条数 32 | * 33 | * @param 34 | * @return 实例对象 35 | */ 36 | Integer getPageListCount(@Param("page") Page page); 37 | 38 | 39 | /** 40 | * 新增数据 41 | * 42 | * @param message 实例对象 43 | * @return 影响行数 44 | */ 45 | int insert(Message message); 46 | 47 | 48 | 49 | 50 | /** 51 | * 修改数据 52 | * 53 | * @param message 实例对象 54 | * @return 影响行数 55 | */ 56 | int update(Message message); 57 | 58 | /** 59 | * 通过主键删除数据 60 | * 61 | * @param id 主键 62 | * @return 影响行数 63 | */ 64 | int deleteById(Integer id); 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/ImageService.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service; 2 | 3 | import com.design.foodmanagement.pojo.Image; 4 | import com.design.foodmanagement.pojo.res.RestFulBean; 5 | import com.design.foodmanagement.dto.Page; 6 | import java.io.IOException; 7 | import java.util.List; 8 | import java.util.Map; 9 | /** 10 | * (Image)表服务接口 11 | * 12 | * @author makejava 13 | * @since 2022-08-31 20:40:52 14 | */ 15 | public interface ImageService { 16 | 17 | /** 18 | * 分页查找数据 19 | * 20 | * @param //前端传来的参数 21 | * @return 实例对象 22 | */ 23 | RestFulBean getList(Page page)throws Exception; 24 | /** 25 | * 通过ID查询单条数据 26 | * 27 | * @param id 主键 28 | * @return 实例对象 29 | */ 30 | RestFulBean queryById(Integer id); 31 | 32 | 33 | /** 34 | * 新增数据 35 | * 36 | * @param image 实例对象 37 | * @return 实例对象 38 | */ 39 | RestFulBean insert(Image image); 40 | 41 | /** 42 | * 修改数据 43 | * 44 | * @param image 实例对象 45 | * @return 实例对象 46 | */ 47 | RestFulBean update(Image image); 48 | 49 | /** 50 | * 通过主键删除数据 51 | * 52 | * @param id 主键 53 | * @return 是否成功 54 | */ 55 | RestFulBean deleteById(Integer id); 56 | 57 | RestFulBean> getSlideshow(); 58 | 59 | RestFulBean> getFoodImage(); 60 | } 61 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/mapper/ImageMapper.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.mapper; 2 | 3 | import com.design.foodmanagement.pojo.Image; 4 | import java.util.List; 5 | import com.design.foodmanagement.dto.Page; 6 | import org.apache.ibatis.annotations.Param; 7 | /** 8 | * (Image)表数据库访问层 9 | * 10 | * @author makejava 11 | * @since 2022-08-31 20:40:52 12 | */ 13 | public interface ImageMapper { 14 | 15 | /** 16 | * 通过ID查询单条数据 17 | * 18 | * @param id 主键 19 | * @return 实例对象 20 | */ 21 | Image queryById(Integer id); 22 | 23 | /** 24 | * 分页查询数据 25 | * 26 | * @param 27 | * @return 实例对象 28 | */ 29 | List getPageListByCondition(@Param("page") Page page); 30 | /** 31 | * 分页查询数据 查询总条数 32 | * 33 | * @param 34 | * @return 实例对象 35 | */ 36 | Integer getPageListCount(@Param("page") Page page); 37 | 38 | 39 | /** 40 | * 新增数据 41 | * 42 | * @param image 实例对象 43 | * @return 影响行数 44 | */ 45 | int insert(Image image); 46 | 47 | 48 | 49 | 50 | /** 51 | * 修改数据 52 | * 53 | * @param image 实例对象 54 | * @return 影响行数 55 | */ 56 | int update(Image image); 57 | 58 | /** 59 | * 通过主键删除数据 60 | * 61 | * @param id 主键 62 | * @return 影响行数 63 | */ 64 | int deleteById(Integer id); 65 | 66 | List getSlideshow(); 67 | 68 | List getFoodImage(); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/Users.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo; 2 | 3 | import java.util.Date; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * (Users)实体类 8 | * 9 | * @author makejava 10 | * @since 2022-08-30 10:36:44 11 | */ 12 | public class Users implements Serializable { 13 | private static final long serialVersionUID = 837099144191836816L; 14 | 15 | private Integer id; 16 | /** 17 | * 密码 18 | */ 19 | private String password; 20 | /** 21 | * 注册时间 22 | */ 23 | private Date createdAt; 24 | /** 25 | * 账号 26 | */ 27 | private String email; 28 | /** 29 | * 角色 30 | */ 31 | private String role; 32 | 33 | 34 | public Integer getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Integer id) { 39 | this.id = id; 40 | } 41 | 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | public void setPassword(String password) { 47 | this.password = password; 48 | } 49 | 50 | public Date getCreatedAt() { 51 | return createdAt; 52 | } 53 | 54 | public void setCreatedAt(Date createdAt) { 55 | this.createdAt = createdAt; 56 | } 57 | 58 | public String getEmail() { 59 | return email; 60 | } 61 | 62 | public void setEmail(String email) { 63 | this.email = email; 64 | } 65 | 66 | public String getRole() { 67 | return role; 68 | } 69 | 70 | public void setRole(String role) { 71 | this.role = role; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/dto/Page.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.dto; 2 | 3 | import java.io.Serializable; 4 | import java.sql.Timestamp; 5 | 6 | public class Page implements Serializable { 7 | private String query; 8 | private Integer pageSize; 9 | private Integer pageNum; 10 | //mysql limit 分页从第几条开始 11 | private Integer startNum; 12 | private T key; 13 | private Timestamp startTime; 14 | private Timestamp endTime; 15 | 16 | public Integer getStartNum() { 17 | return startNum; 18 | } 19 | 20 | public void setStartNum(Integer startNum) { 21 | this.startNum = startNum; 22 | } 23 | 24 | public Timestamp getStartTime() { 25 | return startTime; 26 | } 27 | 28 | public void setStartTime(Timestamp startTime) { 29 | this.startTime = startTime; 30 | } 31 | 32 | public Timestamp getEndTime() { 33 | return endTime; 34 | } 35 | 36 | public void setEndTime(Timestamp endTime) { 37 | this.endTime = endTime; 38 | } 39 | 40 | public String getQuery() { 41 | return query; 42 | } 43 | 44 | public void setQuery(String query) { 45 | this.query = query; 46 | } 47 | 48 | public Integer getPageSize() { 49 | return pageSize; 50 | } 51 | 52 | public void setPageSize(Integer pageSize) { 53 | this.pageSize = pageSize; 54 | } 55 | 56 | public Integer getPageNum() { 57 | return pageNum; 58 | } 59 | 60 | public void setPageNum(Integer pageNum) { 61 | this.pageNum = pageNum; 62 | } 63 | 64 | public T getKey() { 65 | return key; 66 | } 67 | 68 | public void setKey(T key) { 69 | this.key = key; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/mapper/FestivalFoodMapper.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.mapper; 2 | 3 | import com.design.foodmanagement.pojo.FestivalFood; 4 | import java.util.List; 5 | import com.design.foodmanagement.dto.Page; 6 | import org.apache.ibatis.annotations.Param; 7 | /** 8 | * (FestivalFood)表数据库访问层 9 | * 10 | * @author makejava 11 | * @since 2022-08-31 20:38:36 12 | */ 13 | public interface FestivalFoodMapper { 14 | 15 | /** 16 | * 通过ID查询单条数据 17 | * 18 | * @param id 主键 19 | * @return 实例对象 20 | */ 21 | FestivalFood queryById(Integer id); 22 | 23 | /** 24 | * 分页查询数据 25 | * 26 | * @param 27 | * @return 实例对象 28 | */ 29 | List getPageListByCondition(@Param("page") Page page); 30 | /** 31 | * 分页查询数据 查询总条数 32 | * 33 | * @param 34 | * @return 实例对象 35 | */ 36 | Integer getPageListCount(@Param("page") Page page); 37 | 38 | 39 | /** 40 | * 新增数据 41 | * 42 | * @param festivalFood 实例对象 43 | * @return 影响行数 44 | */ 45 | int insert(FestivalFood festivalFood); 46 | 47 | 48 | 49 | 50 | /** 51 | * 修改数据 52 | * 53 | * @param festivalFood 实例对象 54 | * @return 影响行数 55 | */ 56 | int update(FestivalFood festivalFood); 57 | 58 | /** 59 | * 通过主键删除数据 60 | * 61 | * @param id 主键 62 | * @return 影响行数 63 | */ 64 | int deleteById(Integer id); 65 | 66 | List getNewProduct(); 67 | 68 | List getRecommend(); 69 | 70 | List getFestivalFood(); 71 | 72 | void showIn(FestivalFood festivalFood); 73 | 74 | List getFoodActive(); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/MainMenuService.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service; 2 | 3 | import com.design.foodmanagement.pojo.MainMenu; 4 | import com.design.foodmanagement.pojo.Submenu; 5 | import com.design.foodmanagement.pojo.Users; 6 | import com.design.foodmanagement.pojo.res.RestFulBean; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * (MainMenu)表服务接口 13 | * 14 | * @author makejava 15 | * @since 2022-07-02 09:06:33 16 | */ 17 | public interface MainMenuService { 18 | 19 | /** 20 | * 通过ID查询单条数据 21 | * 22 | * @param id 主键 23 | * @return 实例对象 24 | */ 25 | RestFulBean queryById(Integer id); 26 | 27 | 28 | /** 29 | * 新增数据 30 | * 31 | * @param mainMenu 实例对象 32 | * @return 实例对象 33 | */ 34 | RestFulBean insert(MainMenu mainMenu); 35 | 36 | /** 37 | * 修改数据 38 | * 39 | * @param mainMenu 实例对象 40 | * @return 实例对象 41 | */ 42 | RestFulBean update(MainMenu mainMenu); 43 | 44 | /** 45 | * 通过主键删除数据 46 | * 47 | * @param id 主键 48 | * @return 是否成功 49 | */ 50 | RestFulBean deleteById(Integer id); 51 | /** 52 | * 获取系统菜单栏 53 | * 54 | * 55 | */ 56 | RestFulBean> getMenuTree() throws Exception; 57 | 58 | 59 | RestFulBean addMenu(Submenu submenu)throws Exception; 60 | 61 | RestFulBean addMainMenu(MainMenu mainMenu); 62 | 63 | RestFulBean updateMainMenu(MainMenu mainMenu); 64 | 65 | RestFulBean updateMenu(Submenu submenu); 66 | 67 | RestFulBean delMenu(Submenu submenu); 68 | 69 | RestFulBean delMainMenu(MainMenu mainMenu); 70 | } 71 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/FestivalFoodService.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service; 2 | 3 | import com.design.foodmanagement.pojo.FestivalFood; 4 | import com.design.foodmanagement.pojo.res.RestFulBean; 5 | import com.design.foodmanagement.dto.Page; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import java.io.IOException; 9 | import java.util.List; 10 | import java.util.Map; 11 | /** 12 | * (FestivalFood)表服务接口 13 | * 14 | * @author makejava 15 | * @since 2022-08-31 20:38:36 16 | */ 17 | public interface FestivalFoodService { 18 | 19 | /** 20 | * 分页查找数据 21 | * 22 | * @param //前端传来的参数 23 | * @return 实例对象 24 | */ 25 | RestFulBean getList(Page page)throws Exception; 26 | /** 27 | * 通过ID查询单条数据 28 | * 29 | * @param id 主键 30 | * @return 实例对象 31 | */ 32 | RestFulBean queryById(Integer id); 33 | 34 | 35 | /** 36 | * 新增数据 37 | * 38 | * @param festivalFood 实例对象 39 | * @return 实例对象 40 | */ 41 | RestFulBean insert(FestivalFood festivalFood); 42 | 43 | /** 44 | * 修改数据 45 | * 46 | * @param festivalFood 实例对象 47 | * @return 实例对象 48 | */ 49 | RestFulBean update(FestivalFood festivalFood); 50 | 51 | /** 52 | * 通过主键删除数据 53 | * 54 | * @param id 主键 55 | * @return 是否成功 56 | */ 57 | RestFulBean deleteById(Integer id); 58 | 59 | RestFulBean upload(MultipartFile coverFile); 60 | 61 | RestFulBean> getNewProduct(); 62 | 63 | RestFulBean> getRecommend(); 64 | 65 | RestFulBean> getFestivalFood(); 66 | 67 | RestFulBean showIn(FestivalFood festivalFood); 68 | 69 | RestFulBean> getFoodActive(); 70 | } 71 | -------------------------------------------------------------------------------- /foodmanagement/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | datasource: 4 | username: root 5 | password: root 6 | url: jdbc:mysql://localhost:3306/foodmanagement?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | type: com.alibaba.druid.pool.DruidDataSource 9 | #监控统计拦截的filters 10 | filters: stat,wall,log4j 11 | #druid配置 12 | #配置初始化大小/最小/最大 13 | initialSize: 5 14 | minIdle: 5 15 | maxActive: 20 16 | #获取连接等待超时时间 17 | maxWait: 60000 18 | #间隔多久进行一次检测,检测需要关闭的空闲连接 19 | timeBetweenEvictionRunsMillis: 60000 20 | #一个连接在池中最小生存的时间 21 | minEvictableIdleTimeMillis: 300000 22 | validationQuery: SELECT 1 FROM DUAL 23 | testWhileIdle: true 24 | testOnBorrow: false 25 | testOnReturn: false 26 | #打开PSCache,并指定每个连接上PSC ache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false 27 | poolPreparedStatements: false 28 | maxPoolPreparedStatementPerConnectionSize: 20 29 | # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 30 | connectionProperties: 31 | druid: 32 | stat: 33 | mergeSql: true 34 | slowSqlMillis: 5000 35 | 36 | redis: 37 | host: 127.0.0.1 38 | port: 6379 39 | 40 | google: 41 | keyFileLocation: google/fast-fire-302206-d09f05a462ba.json 42 | servlet: 43 | multipart: 44 | max-file-size: 200MB 45 | max-request-size: 200MB 46 | jackson: 47 | default-property-inclusion: non_null 48 | serialization: 49 | write-dates-as-timestamps: true 50 | time-zone: GMT+8 51 | server: 52 | port: 2026 53 | mybatis: 54 | mapper-locations: classpath*:mapper/*.xml 55 | type-aliases-package: com.design.foodmanagement.pojo 56 | configuration: 57 | map-underscore-to-camel-case: true 58 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/Image.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo; 2 | 3 | import java.io.Serializable; 4 | import java.sql.Timestamp; 5 | import java.util.Date; 6 | 7 | /** 8 | * (Image)实体类 9 | * 10 | * @author makejava 11 | * @since 2022-08-31 20:40:52 12 | */ 13 | public class Image implements Serializable { 14 | private static final long serialVersionUID = -81803598524952151L; 15 | 16 | private Integer id; 17 | /** 18 | * 图片 19 | */ 20 | private String images; 21 | /** 22 | * 图片路劲 用于前端显示 23 | */ 24 | private String imagesUrl; 25 | /** 26 | * 录入人 27 | */ 28 | private String createdBy; 29 | /** 30 | * 区别是轮播图还是 美食页面图片 31 | */ 32 | private String type; 33 | /** 34 | * 注册时间 35 | */ 36 | private Timestamp createdAt; 37 | 38 | public Integer getId() { 39 | return id; 40 | } 41 | 42 | public void setId(Integer id) { 43 | this.id = id; 44 | } 45 | 46 | public String getImages() { 47 | return images; 48 | } 49 | 50 | public void setImages(String images) { 51 | this.images = images; 52 | } 53 | 54 | public String getType() { 55 | return type; 56 | } 57 | 58 | public void setType(String type) { 59 | this.type = type; 60 | } 61 | 62 | public String getImagesUrl() { 63 | return imagesUrl; 64 | } 65 | 66 | public void setImagesUrl(String imagesUrl) { 67 | this.imagesUrl = imagesUrl; 68 | } 69 | 70 | public String getCreatedBy() { 71 | return createdBy; 72 | } 73 | 74 | public void setCreatedBy(String createdBy) { 75 | this.createdBy = createdBy; 76 | } 77 | 78 | public Timestamp getCreatedAt() { 79 | return createdAt; 80 | } 81 | 82 | public void setCreatedAt(Timestamp createdAt) { 83 | this.createdAt = createdAt; 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/mapper/MainMenuMapper.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.mapper; 2 | 3 | import com.design.foodmanagement.pojo.MainMenu; 4 | import java.util.List; 5 | 6 | import com.design.foodmanagement.pojo.Submenu; 7 | import org.apache.ibatis.annotations.Param; 8 | /** 9 | * (MainMenu)表数据库访问层 10 | * 11 | * @author makejava 12 | * @since 2022-07-02 09:06:34 13 | */ 14 | public interface MainMenuMapper { 15 | 16 | /** 17 | * 通过ID查询单条数据 18 | * 19 | * @param id 主键 20 | * @return 实例对象 21 | */ 22 | MainMenu queryById(Integer id); 23 | 24 | /** 25 | * 查询指定行数据 26 | * 27 | * @param offset 查询条件 28 | * @param limit 查询条数 29 | * @return 对象列表 30 | */ 31 | List queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit); 32 | 33 | /** 34 | * 统计总行数 35 | * 36 | * @param mainMenu 查询条件 37 | * @return 总行数 38 | */ 39 | long count(MainMenu mainMenu); 40 | 41 | /** 42 | * 新增数据 43 | * 44 | * @param mainMenu 实例对象 45 | * @return 影响行数 46 | */ 47 | int insert(MainMenu mainMenu); 48 | 49 | 50 | 51 | /** 52 | * 批量新增或按主键更新数据(MyBatis原生foreach方法) 53 | * 54 | * @param entities List 实例对象列表 55 | * @return 影响行数 56 | * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 57 | */ 58 | int insertOrUpdateBatch(@Param("entities") List entities); 59 | 60 | /** 61 | * 修改数据 62 | * 63 | * @param mainMenu 实例对象 64 | * @return 影响行数 65 | */ 66 | int update(MainMenu mainMenu); 67 | 68 | /** 69 | * 通过主键删除数据 70 | * 71 | * @param id 主键 72 | * @return 影响行数 73 | */ 74 | int deleteById(Integer id); 75 | 76 | 77 | void addMenu(MainMenu mainMenu); 78 | 79 | void updateMainMenu(MainMenu mainMenu); 80 | 81 | List getMainMenu(); 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/controller/SubmenuController.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.controller; 2 | 3 | import com.design.foodmanagement.pojo.Submenu; 4 | import com.design.foodmanagement.service.SubmenuService; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | import javax.annotation.Resource; 8 | import com.design.foodmanagement.pojo.res.RestFulBean; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | /** 12 | * (Submenu)表控制层 13 | * 14 | * @author makejava 15 | * @since 2022-07-02 09:07:08 16 | */ 17 | @RestController 18 | @RequestMapping("/submenu") 19 | public class SubmenuController { 20 | /** 21 | * 服务对象 22 | */ 23 | @Autowired 24 | private SubmenuService submenuService; 25 | 26 | /** 27 | * 通过主键查询单条数据 28 | * 29 | * @param id 主键 30 | * @return 单条数据 31 | */ 32 | @GetMapping("/{id}") 33 | public RestFulBean queryById(@PathVariable Integer id) { 34 | return this.submenuService.queryById(id); 35 | } 36 | 37 | /** 38 | * 新增数据 39 | * 40 | * @param submenu 实体 41 | * @return 新增结果 42 | */ 43 | @PostMapping("/add") 44 | public RestFulBean add(@RequestBody Submenu submenu) { 45 | return this.submenuService.insert(submenu); 46 | } 47 | 48 | /** 49 | * 编辑数据 50 | * 51 | * @param submenu 实体 52 | * @return 编辑结果 53 | */ 54 | @PostMapping("/update") 55 | public RestFulBean edit(@RequestBody Submenu submenu) { 56 | return this.submenuService.update(submenu); 57 | } 58 | 59 | /** 60 | * 删除数据 61 | * 62 | * @param id 主键 63 | * @return 删除是否成功 64 | */ 65 | @DeleteMapping 66 | public RestFulBean deleteById(Integer id) { 67 | return this.submenuService.deleteById(id); 68 | } 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/impl/SubmenuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service.impl; 2 | 3 | import com.design.foodmanagement.pojo.Submenu; 4 | import com.design.foodmanagement.mapper.SubmenuMapper; 5 | import com.design.foodmanagement.service.SubmenuService; 6 | import org.springframework.stereotype.Service; 7 | import javax.annotation.Resource; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import com.design.foodmanagement.pojo.res.RestFulBean; 10 | /** 11 | * (Submenu)表服务实现类 12 | * 13 | * @author makejava 14 | * @since 2022-07-02 09:07:08 15 | */ 16 | @Service("submenuService") 17 | public class SubmenuServiceImpl implements SubmenuService { 18 | @Autowired 19 | private SubmenuMapper submenuMapper; 20 | 21 | /** 22 | * 通过ID查询单条数据 23 | * 24 | * @param id 主键 25 | * @return 实例对象 26 | */ 27 | @Override 28 | public RestFulBean queryById(Integer id) { 29 | Submenu submenu=this.submenuMapper.queryById(id); 30 | return RestFulBean.succ(submenu); 31 | } 32 | 33 | /** 34 | * 新增数据 35 | * 36 | * @param submenu 实例对象 37 | * @return 实例对象 38 | */ 39 | @Override 40 | public RestFulBean insert(Submenu submenu) { 41 | this.submenuMapper.insert(submenu); 42 | return RestFulBean.succ("添加成功"); 43 | } 44 | 45 | /** 46 | * 修改数据 47 | * 48 | * @param submenu 实例对象 49 | * @return 实例对象 50 | */ 51 | @Override 52 | public RestFulBean update(Submenu submenu) { 53 | this.submenuMapper.update(submenu); 54 | return RestFulBean.succ("修改成功"); 55 | } 56 | 57 | /** 58 | * 通过主键删除数据 59 | * 60 | * @param id 主键 61 | * @return 是否成功 62 | */ 63 | @Override 64 | public RestFulBean deleteById(Integer id) { 65 | this.submenuMapper.deleteById(id); 66 | return RestFulBean.succ("删除成功"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.data.redis.connection.RedisConnectionFactory; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 8 | import org.springframework.data.redis.serializer.StringRedisSerializer; 9 | 10 | /** 11 | * redis配置类 12 | * @program: springbootdemo 13 | * @Date: 2019/1/25 15:20 14 | * @Author: Mr.Zheng 15 | * @Description: 16 | */ 17 | @Configuration 18 | public class RedisConfig { 19 | 20 | @Bean 21 | @SuppressWarnings("all") 22 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) { 23 | RedisTemplate template = new RedisTemplate(); 24 | template.setConnectionFactory(factory); 25 | Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); 26 | // ObjectMapper om = new ObjectMapper(); 27 | // om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 28 | // om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 29 | // jackson2JsonRedisSerializer.setObjectMapper(om); 30 | StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); 31 | // key采用String的序列化方式 32 | template.setKeySerializer(stringRedisSerializer); 33 | // hash的key也采用String的序列化方式 34 | template.setHashKeySerializer(stringRedisSerializer); 35 | // value序列化方式采用jackson 36 | template.setValueSerializer(jackson2JsonRedisSerializer); 37 | // hash的value序列化方式采用jackson 38 | template.setHashValueSerializer(jackson2JsonRedisSerializer); 39 | template.afterPropertiesSet(); 40 | System.out.println("init RedisTemplate"); 41 | return template; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/controller/UsersController.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.controller; 2 | 3 | import com.design.foodmanagement.dto.Page; 4 | import com.design.foodmanagement.pojo.Image; 5 | import com.design.foodmanagement.pojo.Users; 6 | import com.design.foodmanagement.service.UsersService; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.*; 9 | import javax.annotation.Resource; 10 | import com.design.foodmanagement.pojo.res.RestFulBean; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | 13 | import java.util.Map; 14 | 15 | /** 16 | * (Users)表控制层 17 | * 18 | * @author makejava 19 | * @since 2022-08-30 10:36:41 20 | */ 21 | @RestController 22 | @RequestMapping("/users") 23 | public class UsersController { 24 | /** 25 | * 服务对象 26 | */ 27 | @Autowired 28 | private UsersService usersService; 29 | 30 | /** 31 | * 分页查询 32 | * 33 | * @param //前端传来的参数 34 | * @return 单条数据 35 | */ 36 | @PostMapping("/get/page/list") 37 | public RestFulBean getList(@RequestBody Page page) throws Exception{ 38 | return this.usersService.getList(page); 39 | } 40 | /** 41 | * 通过主键查询单条数据 42 | * 43 | * @param id 主键 44 | * @return 单条数据 45 | */ 46 | @PostMapping("/get/by/id") 47 | public RestFulBean queryById(@RequestBody Users users) { 48 | return this.usersService.queryById(users.getId()); 49 | } 50 | 51 | /** 52 | * 新增数据 53 | * 54 | * @param 55 | * @return 新增结果 56 | */ 57 | @PostMapping("/add") 58 | public RestFulBean add(@RequestBody Users users) { 59 | return this.usersService.insert(users); 60 | } 61 | 62 | /** 63 | * 编辑数据 64 | * 65 | * @param 66 | * @return 编辑结果 67 | */ 68 | @PostMapping("/update") 69 | public RestFulBean edit(@RequestBody Users users) { 70 | return this.usersService.update(users); 71 | } 72 | 73 | /** 74 | * 删除数据 75 | * 76 | * @param id 主键 77 | * @return 删除是否成功 78 | */ 79 | @PostMapping("/delete") 80 | public RestFulBean deleteById(@RequestBody Users users) { 81 | return this.usersService.deleteById(users.getId()); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /foodmanagement/src/main/resources/mapper/MessageMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | insert into message(email, message, created_at) 25 | values (#{email}, #{message},now()) 26 | 27 | 28 | 36 | 37 | 40 | 41 | 42 | 43 | 44 | 45 | update message 46 | 47 | 48 | email = #{email}, 49 | 50 | 51 | message = #{message}, 52 | 53 | 54 | created_at = #{createdAt}, 55 | 56 | 57 | where id = #{id} 58 | 59 | 60 | 61 | 62 | delete from message where id = #{id} 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/controller/MessageController.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.controller; 2 | 3 | import com.design.foodmanagement.pojo.Message; 4 | import com.design.foodmanagement.service.MessageService; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | import javax.annotation.Resource; 8 | import com.design.foodmanagement.pojo.res.RestFulBean; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | import com.design.foodmanagement.dto.Page; 12 | import java.io.IOException; 13 | import java.util.Map; 14 | /** 15 | * (Message)表控制层 16 | * 17 | * @author makejava 18 | * @since 2022-09-03 10:51:47 19 | */ 20 | @RestController 21 | @RequestMapping("/message") 22 | public class MessageController { 23 | /** 24 | * 服务对象 25 | */ 26 | @Autowired 27 | private MessageService messageService; 28 | 29 | /** 30 | * 分页查询 31 | * 32 | * @param //前端传来的参数 33 | * @return 单条数据 34 | */ 35 | @PostMapping("/get/page/list") 36 | public RestFulBean getList(@RequestBody Pagepage) throws Exception{ 37 | return this.messageService.getList(page); 38 | } 39 | /** 40 | * 通过主键查询单条数据 41 | * 42 | * @param id 主键 43 | * @return 单条数据 44 | */ 45 | @PostMapping("/get/by/id") 46 | public RestFulBean queryById(@RequestBody Message message) { 47 | return this.messageService.queryById(message.getId()); 48 | } 49 | 50 | /** 51 | * 新增数据 52 | * 53 | * @param message 实体 54 | * @return 新增结果 55 | */ 56 | @PostMapping("/add") 57 | public RestFulBean add(@RequestBody Message message) { 58 | return this.messageService.insert(message); 59 | } 60 | 61 | /** 62 | * 编辑数据 63 | * 64 | * @param message 实体 65 | * @return 编辑结果 66 | */ 67 | @PostMapping("/update") 68 | public RestFulBean edit(@RequestBody Message message) { 69 | return this.messageService.update(message); 70 | } 71 | 72 | /** 73 | * 删除数据 74 | * 75 | * @param id 主键 76 | * @return 删除是否成功 77 | */ 78 | @PostMapping("/delete") 79 | public RestFulBean deleteById(@RequestBody Message message) { 80 | return this.messageService.deleteById(message.getId()); 81 | } 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/res/RestFulBean.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo.res; 2 | 3 | public class RestFulBean { 4 | 5 | private int status; 6 | private T data; 7 | private String msg; 8 | 9 | public static RestFulBean error(Code code, String message) { 10 | return RestFulBean.error(code.code,message); 11 | } 12 | 13 | public int getStatus() { 14 | return status; 15 | } 16 | 17 | public void setStatus(int status) { 18 | this.status = status; 19 | } 20 | 21 | public T getData() { 22 | return data; 23 | } 24 | 25 | public void setData(T data) { 26 | this.data = data; 27 | } 28 | 29 | public String getMsg() { 30 | return msg; 31 | } 32 | 33 | public void setMsg(String msg) { 34 | this.msg = msg; 35 | } 36 | 37 | public static RestFulBean succ(String msg, R data) { 38 | RestFulBean rest = new RestFulBean<>(); 39 | rest.setData(data); 40 | rest.setStatus(2000); 41 | return rest; 42 | } 43 | 44 | public static RestFulBean succ(R data) { 45 | return succ("", data); 46 | } 47 | public static RestFulBean succ(Code code,String message) { 48 | RestFulBean rest = new RestFulBean<>(); 49 | rest.setMsg(message); 50 | rest.setData(null); 51 | rest.setStatus(code.code); 52 | return rest; 53 | } 54 | 55 | 56 | public static RestFulBean error(Exception ex) { 57 | return RestFulBean.error("读出数据出错,错误为:" + ex.getLocalizedMessage()); 58 | } 59 | 60 | public static RestFulBean error(String msg) { 61 | return RestFulBean.error(5000, msg, null); 62 | } 63 | 64 | public static RestFulBean error(String msg, Object data) { 65 | return RestFulBean.error(5000, msg, data); 66 | } 67 | 68 | public static RestFulBean error(int code, String msg) { 69 | return RestFulBean.error(code, msg, null); 70 | } 71 | 72 | public static RestFulBean error(Code code, String msg, Object data) { 73 | return RestFulBean.error(code.code,msg,data); 74 | } 75 | 76 | public static RestFulBean error(int code, String msg, Object data) { 77 | RestFulBean rest = new RestFulBean(); 78 | rest.setData(data); 79 | rest.setMsg(msg); 80 | rest.setStatus(code); 81 | return rest; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/FestivalFood.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo; 2 | 3 | import java.io.Serializable; 4 | import java.sql.Timestamp; 5 | import java.util.Date; 6 | 7 | /** 8 | * (FestivalFood)实体类 9 | * 10 | * @author makejava 11 | * @since 2022-08-31 20:46:14 12 | */ 13 | public class FestivalFood implements Serializable { 14 | private static final long serialVersionUID = 849941803291096211L; 15 | 16 | private Integer id; 17 | /** 18 | * 标题 19 | */ 20 | private String title; 21 | /** 22 | * 描述 23 | */ 24 | private String descb; 25 | /** 26 | * 图片 27 | */ 28 | private String images; 29 | /** 30 | * 图片路劲 用于前端显示 31 | */ 32 | private String imagesUrl; 33 | /** 34 | * 类型 是哪一个页面的图文信息 35 | */ 36 | private String type; 37 | /** 38 | * 注册时间 39 | */ 40 | private Timestamp createdAt; 41 | 42 | private Integer showIn; 43 | 44 | public String getImagesUrl() { 45 | return imagesUrl; 46 | } 47 | 48 | public void setImagesUrl(String imagesUrl) { 49 | this.imagesUrl = imagesUrl; 50 | } 51 | 52 | public Integer getShowIn() { 53 | return showIn; 54 | } 55 | 56 | public void setShowIn(Integer showIn) { 57 | this.showIn = showIn; 58 | } 59 | 60 | public Timestamp getCreatedAt() { 61 | return createdAt; 62 | } 63 | 64 | public void setCreatedAt(Timestamp createdAt) { 65 | this.createdAt = createdAt; 66 | } 67 | 68 | public Integer getId() { 69 | return id; 70 | } 71 | 72 | public void setId(Integer id) { 73 | this.id = id; 74 | } 75 | 76 | public String getTitle() { 77 | return title; 78 | } 79 | 80 | public void setTitle(String title) { 81 | this.title = title; 82 | } 83 | 84 | public String getDescb() { 85 | return descb; 86 | } 87 | 88 | public void setDescb(String descb) { 89 | this.descb = descb; 90 | } 91 | 92 | public String getImages() { 93 | return images; 94 | } 95 | 96 | public void setImages(String images) { 97 | this.images = images; 98 | } 99 | 100 | public String getType() { 101 | return type; 102 | } 103 | 104 | public void setType(String type) { 105 | this.type = type; 106 | } 107 | 108 | } 109 | 110 | -------------------------------------------------------------------------------- /foodmanagement/src/main/resources/mapper/ImageMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | insert into image(images, type,created_at,created_by) 25 | values (#{images}, #{type},now(),'admin') 26 | 27 | 28 | 39 | 40 | 46 | 47 | 48 | 49 | 50 | 51 | update image 52 | 53 | 54 | images = #{images}, 55 | 56 | 57 | type = #{type}, 58 | 59 | 60 | where id = #{id} 61 | 62 | 63 | 64 | 65 | delete from image where id = #{id} 66 | 67 | 70 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 基于JAVA的美食宣传网站 2 | 3 | #接计算机毕业设计(代码注释详细+做完会录制视频讲解 需要加微信13650154582) 4 | #b站代码视频讲解地址链接:https://www.bilibili.com/video/BV1KW4y1p7kN/?spm_id_from=333.337.search-card.all.click 5 | # 项目文件 6 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E9%A1%B9%E7%9B%AE%E6%96%87%E4%BB%B6.png) 7 | # 项目功能 8 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E5%8A%9F%E8%83%BD%E5%9B%BE.png) 9 | 各个模块具体功能如下: 10 | (1)首页:网站首页包括轮播图、最新发布、热门推荐。 11 | (2)节日美食:后台管理员录入节日美食之后,网站用户可以在这里进行查看。 12 | (3)美食活动:后台管理员录入美食活动信息之后,网站用户在这里查看美食活动信息。 13 | (4)美食图片:后台管理员录入美食照片之后,网站用户可以在这里查看美食照片。 14 | (5)留言反馈:用户输入邮箱、留言内容之后进行留言反馈。 15 | (6)首页数据管理:管理员对网站首页轮播图、最新发布的美食、热门推荐进行数据管理。 16 | (7)节日美食管理:管理员对节日美食进行增删查改操作,发布成功之后,选择上架,网站用户就可以浏览到管理员录入的节日美食信息。 17 | (8)美食活动管理:管理员对美食活动数据进行添加修改以及删除操作。 18 | (9)用户管理:网站注册的用户管理员可以在这里进行用户信息管理,管理员可以查看用户发布的留言信息。 19 | # 技术路线 20 | 本系统采用IDEA,JAVA,MySQL等相关的数据库并采用SpringBoot+Vue前后端分离的框架对系统进行开发。研究B/S的基本架构,搭建好IDEA开发环境,基于win10操作系统来搭建服务器,根据系统设计文档进行编程开发。从而实现美食宣传网站的主体功能。 21 | # 界面截图 22 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E9%A6%96%E9%A1%B5.png) 23 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E8%8A%82%E6%97%A5%E7%BE%8E%E9%A3%9F.png) 24 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E7%BE%8E%E9%A3%9F%E6%B4%BB%E5%8A%A8.png) 25 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E7%BE%8E%E9%A3%9F%E7%85%A7%E7%89%87.png) 26 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C.png) 27 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E7%94%A8%E6%88%B7%E7%95%99%E8%A8%80.png) 28 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E5%90%8E%E5%8F%B0%E7%99%BB%E5%BD%95.png) 29 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E9%A6%96%E9%A1%B5%E6%8E%A8%E8%8D%90.png) 30 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E8%8A%82%E6%97%A5%E7%BE%8E%E9%A3%9F1.png) 31 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E9%A6%96%E9%A1%B5%E7%AE%A1%E7%90%86.png) 32 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E7%BE%8E%E9%A3%9F%E7%85%A7%E7%89%87%E5%90%8E%E5%8F%B0.png) 33 | ![Image text](https://github.com/huoming123/foodmanagement/blob/main/%E9%A1%B9%E7%9B%AE%E6%88%AA%E5%9B%BE/%E7%94%A8%E6%88%B7%E5%88%97%E8%A1%A8.jpg) 34 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/util/TimeUtil.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.util; 2 | 3 | import java.sql.Timestamp; 4 | import java.text.ParseException; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Calendar; 7 | import java.util.Date; 8 | 9 | public class TimeUtil { 10 | /** 11 | * 根据格式转换毫秒数 12 | * @param format 13 | * @param date 14 | * @return 15 | * @throws ParseException 16 | */ 17 | public static long getMillisecond(String format,String date) throws ParseException { 18 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);//24小时制 19 | return simpleDateFormat.parse(date).getTime(); 20 | } 21 | 22 | /** 23 | * 根据时间格式转Timestamp 24 | * @param format 25 | * @param date 26 | * @return 27 | * @throws ParseException 28 | */ 29 | public static Timestamp getTimestamp(String format,String date) throws ParseException { 30 | return new Timestamp(getMillisecond(format,date)); 31 | } 32 | 33 | /** 34 | * 获取当前时间的timestamp 35 | * @return 36 | */ 37 | public static Timestamp getCurrentTimestamp() { 38 | return new Timestamp(new Date().getTime()); 39 | } 40 | 41 | /** 42 | * 获取指定时间戳 与 指定时间戳多少分钟后的相差数 43 | * @return 44 | */ 45 | public static long getDefineTimestamp(Timestamp time, int afterMinute) { 46 | // 获取到当前时间 47 | long currentTime = new Date().getTime(); 48 | 49 | // 起始时间 50 | // long startTime = new Date(time.getTime()).getTime(); 51 | 52 | // 过期的时间 53 | Date d1 = new Date(time.getTime()); 54 | Calendar cal = Calendar.getInstance(); 55 | cal.setTime(d1); 56 | cal.add(Calendar.MINUTE, afterMinute); 57 | long expeirdTime = cal.getTime().getTime(); 58 | 59 | // 过期时间与现在时间之差 60 | long interval = expeirdTime - currentTime; 61 | long i = interval / 1000; 62 | //对 i 做个判断 i<0 则不进行倒计时 63 | if(i<0){ 64 | return 0; 65 | }else{ 66 | return i; 67 | } 68 | } 69 | 70 | 71 | 72 | 73 | /** 74 | * 获取多少分钟后的时间点 75 | * @param expireNumber 多少分钟 76 | * @return 77 | */ 78 | public static String getDateTime(Integer expireNumber) { 79 | Integer defalut = 30; // 默认30分钟 80 | if(expireNumber != null) { 81 | defalut = expireNumber; 82 | } 83 | // 创建SimpleDateFormat类型对象、 "yyyy-MM-dd HH:mm:ss"是正则式,分别表示年月日时分秒 84 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); 85 | 86 | // 将两个String类型的时间转换为Date类型,从而计算差值、parse()方法的作用是将String类型的时间解析为Date类型 87 | Calendar cal = Calendar.getInstance(); 88 | cal.setTime(new Date()); 89 | cal.add(Calendar.MINUTE, defalut); 90 | 91 | Date afterDate = cal.getTime(); 92 | return df.format(afterDate); 93 | } 94 | 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/controller/ImageController.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.controller; 2 | 3 | import com.design.foodmanagement.pojo.Image; 4 | import com.design.foodmanagement.service.ImageService; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | import javax.annotation.Resource; 8 | import com.design.foodmanagement.pojo.res.RestFulBean; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | import com.design.foodmanagement.dto.Page; 12 | import java.io.IOException; 13 | import java.util.List; 14 | import java.util.Map; 15 | /** 16 | * (Image)表控制层 17 | * 18 | * @author makejava 19 | * @since 2022-08-31 20:40:52 20 | */ 21 | @RestController 22 | @RequestMapping("/image") 23 | public class ImageController { 24 | /** 25 | * 服务对象 26 | */ 27 | @Autowired 28 | private ImageService imageService; 29 | 30 | /** 31 | * 分页查询 32 | * 33 | * @param //前端传来的参数 34 | * @return 单条数据 35 | */ 36 | @PostMapping("/get/page/list") 37 | public RestFulBean getList(@RequestBody Pagepage) throws Exception{ 38 | return this.imageService.getList(page); 39 | } 40 | /** 41 | * 通过主键查询单条数据 42 | * 43 | * @param id 主键 44 | * @return 单条数据 45 | */ 46 | @PostMapping("/get/by/id") 47 | public RestFulBean queryById(@RequestBody Image image) { 48 | return this.imageService.queryById(image.getId()); 49 | } 50 | 51 | /** 52 | * 新增数据 53 | * 54 | * @param image 实体 55 | * @return 新增结果 56 | */ 57 | @PostMapping("/add") 58 | public RestFulBean add(@RequestBody Image image) { 59 | return this.imageService.insert(image); 60 | } 61 | 62 | /** 63 | * 编辑数据 64 | * 65 | * @param image 实体 66 | * @return 编辑结果 67 | */ 68 | @PostMapping("/update") 69 | public RestFulBean edit(@RequestBody Image image) { 70 | return this.imageService.update(image); 71 | } 72 | 73 | /** 74 | * 删除数据 75 | * 76 | * @param id 主键 77 | * @return 删除是否成功 78 | */ 79 | @PostMapping("/delete") 80 | public RestFulBean deleteById(@RequestBody Image image) { 81 | return this.imageService.deleteById(image.getId()); 82 | } 83 | /** 84 | * 获取网页轮播图 85 | * 86 | * @param 87 | * @return 88 | */ 89 | @PostMapping("/get/slideshow") 90 | public RestFulBean> getSlideshow() { 91 | return this.imageService.getSlideshow(); 92 | } 93 | /** 94 | * 获取美食页面图片 95 | * 96 | * @param 97 | * @return 98 | */ 99 | @PostMapping("/get/food/image") 100 | public RestFulBean> getFoodImage() { 101 | return this.imageService.getFoodImage(); 102 | } 103 | } 104 | 105 | -------------------------------------------------------------------------------- /foodmanagement/src/main/resources/mapper/UsersMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | insert into users(password, created_at, email, role) 26 | values (#{password},now(), #{email},'user') 27 | 28 | 29 | 30 | 31 | 32 | update users 33 | 34 | 35 | password = #{password}, 36 | 37 | 38 | created_at = #{createdAt}, 39 | 40 | 41 | email = #{email}, 42 | 43 | 44 | role = #{role}, 45 | 46 | 47 | where id = #{id} 48 | 49 | 50 | 51 | 52 | delete from users where id = #{id} 53 | 54 | 57 | 68 | 69 | 75 | 78 | 79 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/controller/MainMenuController.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.controller; 2 | 3 | import com.design.foodmanagement.pojo.MainMenu; 4 | import com.design.foodmanagement.pojo.Submenu; 5 | import com.design.foodmanagement.pojo.Users; 6 | import com.design.foodmanagement.service.MainMenuService; 7 | import org.springframework.web.bind.annotation.*; 8 | import com.design.foodmanagement.pojo.res.RestFulBean; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * (MainMenu)表控制层 16 | * 17 | * @author makejava 18 | * @since 2022-07-02 09:06:30 19 | */ 20 | @RestController 21 | @RequestMapping("/mainMenu") 22 | public class MainMenuController { 23 | /** 24 | * 服务对象 25 | */ 26 | @Autowired 27 | private MainMenuService mainMenuService; 28 | 29 | /** 30 | * 获取菜单 31 | * 32 | * @param user 用户id 查出 该用户是什么角色 进而显示不同的菜单 33 | * @return Map 34 | */ 35 | @PostMapping("/menu") 36 | public RestFulBean> getMenuTree() throws Exception { 37 | return mainMenuService.getMenuTree(); 38 | } 39 | 40 | /** 41 | * 新增一个子菜单 42 | * @param submenu 43 | * @return 44 | * @throws 45 | */ 46 | @PostMapping("/add/menu") 47 | public RestFulBean addMenu(@RequestBody Submenu submenu)throws Exception{ 48 | return mainMenuService.addMenu(submenu); 49 | } 50 | /** 51 | * 新增一个主菜单 52 | * @param mainMenu 53 | * @return 54 | * @throws 55 | */ 56 | @PostMapping("/add/mainMenu") 57 | public RestFulBean addMainMenu(@RequestBody MainMenu mainMenu)throws Exception{ 58 | return mainMenuService.addMainMenu(mainMenu); 59 | } 60 | /** 61 | * 修改主菜单 62 | * @param mainMenu 63 | * @return 64 | * @throws 65 | */ 66 | @PostMapping("/update/mainMenu") 67 | public RestFulBean updateMainMenu(@RequestBody MainMenu mainMenu)throws Exception{ 68 | return mainMenuService.updateMainMenu(mainMenu); 69 | } 70 | /** 71 | * 修改子菜单 72 | * @param submenu 73 | * @return 74 | * @throws 75 | */ 76 | @PostMapping("/update/menu") 77 | public RestFulBean updateMenu(@RequestBody Submenu submenu)throws Exception{ 78 | return mainMenuService.updateMenu(submenu); 79 | } 80 | /** 81 | * 删除子菜单 82 | * @param submenu 83 | * @return 84 | * @throws 85 | */ 86 | @PostMapping("/del/menu") 87 | public RestFulBean delMenu(@RequestBody Submenu submenu)throws Exception{ 88 | return mainMenuService.delMenu(submenu); 89 | } 90 | /** 91 | * 删除主菜单 92 | * @param mainMenu 93 | * @return 94 | * @throws 95 | */ 96 | @PostMapping("/del/mainMenu") 97 | public RestFulBean delMainMenu(@RequestBody MainMenu mainMenu)throws Exception{ 98 | return mainMenuService.delMainMenu(mainMenu); 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /foodmanagement/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.3 9 | 10 | 11 | com.design 12 | foodmanagement 13 | 0.0.1-SNAPSHOT 14 | foodmanagement 15 | Demo project for Spring Boot 16 | 17 | 1.8 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | 33 | org.mybatis.spring.boot 34 | mybatis-spring-boot-starter 35 | 2.1.4 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | mysql 45 | mysql-connector-java 46 | 8.0.28 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-jdbc 51 | 52 | 53 | 54 | com.alibaba 55 | druid-spring-boot-starter 56 | 1.1.18 57 | 58 | 59 | com.auth0 60 | java-jwt 61 | 3.10.3 62 | 63 | 64 | org.apache.commons 65 | commons-lang3 66 | 3.9 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-starter-data-redis 71 | 72 | 73 | com.alibaba 74 | fastjson 75 | 1.2.73 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-starter-validation 81 | 82 | 83 | 84 | 85 | 86 | org.springframework.boot 87 | spring-boot-maven-plugin 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/MainMenu.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo; 2 | 3 | import java.sql.Timestamp; 4 | import java.util.Date; 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | /** 9 | * (MainMenu)实体类 10 | * 11 | * @author makejava 12 | * @since 2022-07-02 09:06:34 13 | */ 14 | public class MainMenu implements Serializable { 15 | private static final long serialVersionUID = -49108938701091754L; 16 | 17 | private Integer id; 18 | /** 19 | * 菜单名 20 | */ 21 | private String mainName; 22 | /** 23 | * 创建人 24 | */ 25 | private String createdBy; 26 | /** 27 | * 创建时间 28 | */ 29 | private Timestamp createdAt; 30 | /** 31 | * 修改时间 32 | */ 33 | private Timestamp updatedAt; 34 | /** 35 | * 修改人 36 | */ 37 | private String updatedBy; 38 | /** 39 | * 删除人 40 | */ 41 | private String deletedBy; 42 | /** 43 | * 删除时间 44 | */ 45 | private Date deletedAt; 46 | /** 47 | * 序号 48 | */ 49 | private Integer seq; 50 | /** 51 | * 数据对象 52 | */ 53 | private List submenuList; 54 | 55 | public List getSubmenuList() { 56 | return submenuList; 57 | } 58 | 59 | public void setSubmenuList(List submenuList) { 60 | this.submenuList = submenuList; 61 | } 62 | 63 | public Integer getId() { 64 | return id; 65 | } 66 | 67 | public void setId(Integer id) { 68 | this.id = id; 69 | } 70 | 71 | public String getMainName() { 72 | return mainName; 73 | } 74 | 75 | public void setMainName(String mainName) { 76 | this.mainName = mainName; 77 | } 78 | 79 | public String getCreatedBy() { 80 | return createdBy; 81 | } 82 | 83 | public void setCreatedBy(String createdBy) { 84 | this.createdBy = createdBy; 85 | } 86 | 87 | public Timestamp getCreatedAt() { 88 | return createdAt; 89 | } 90 | 91 | public void setCreatedAt(Timestamp createdAt) { 92 | this.createdAt = createdAt; 93 | } 94 | 95 | public Timestamp getUpdatedAt() { 96 | return updatedAt; 97 | } 98 | 99 | public void setUpdatedAt(Timestamp updatedAt) { 100 | this.updatedAt = updatedAt; 101 | } 102 | 103 | public String getUpdatedBy() { 104 | return updatedBy; 105 | } 106 | 107 | public void setUpdatedBy(String updatedBy) { 108 | this.updatedBy = updatedBy; 109 | } 110 | 111 | public String getDeletedBy() { 112 | return deletedBy; 113 | } 114 | 115 | public void setDeletedBy(String deletedBy) { 116 | this.deletedBy = deletedBy; 117 | } 118 | 119 | public Date getDeletedAt() { 120 | return deletedAt; 121 | } 122 | 123 | public void setDeletedAt(Date deletedAt) { 124 | this.deletedAt = deletedAt; 125 | } 126 | 127 | public Integer getSeq() { 128 | return seq; 129 | } 130 | 131 | public void setSeq(Integer seq) { 132 | this.seq = seq; 133 | } 134 | 135 | } 136 | 137 | -------------------------------------------------------------------------------- /foodmanagement/src/main/resources/mapper/MainMenuMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | insert into main_menu(main_name, created_by, created_at, updated_at, updated_by, seq) 33 | values (#{mainName}, #{createdBy}, now(), now(), #{updatedBy}, #{seq}) 34 | 35 | 36 | 37 | 38 | update main_menu 39 | 40 | 41 | main_name = #{mainName}, 42 | 43 | 44 | created_by = #{createdBy}, 45 | 46 | 47 | created_at = #{createdAt}, 48 | 49 | 50 | 51 | deleted_by = #{deletedBy}, 52 | 53 | 54 | deleted_at = #{deletedAt}, 55 | 56 | 57 | seq = #{seq}, 58 | 59 | updated_at =now(), 60 | updated_by = 'developer' 61 | 62 | where id = #{id} 63 | 64 | 65 | 66 | 67 | delete from main_menu where id = #{id} 68 | 69 | 70 | 71 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /foodmanagement/src/main/resources/mapper/SubmenuMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | insert into submenu(main_id, seq, menu_name, menu_url, created_by, created_at, updated_by, updated_at,type) 29 | values (#{mainId}, #{seq}, #{menuName}, #{menuUrl}, #{createdBy}, #{createdAt}, #{updatedBy}, #{updatedAt},#{type}) 30 | 31 | 32 | 33 | 34 | update submenu 35 | 36 | 37 | main_id = #{mainId}, 38 | 39 | 40 | seq = #{seq}, 41 | 42 | 43 | menu_name = #{menuName}, 44 | 45 | 46 | menu_url = #{menuUrl}, 47 | 48 | 49 | created_by = #{createdBy}, 50 | 51 | 52 | created_at = #{createdAt}, 53 | 54 | 55 | deleted_by = #{deletedBy}, 56 | 57 | 58 | deleted_at = #{deletedAt}, 59 | 60 | 61 | type = #{type}, 62 | 63 | 64 | updated_by = 'developer', 65 | updated_at = now() 66 | 67 | where id = #{id} 68 | 69 | 70 | 71 | 72 | delete from submenu where id = #{id} 73 | 74 | 77 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/pojo/Submenu.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.pojo; 2 | 3 | import java.sql.Timestamp; 4 | import java.util.Date; 5 | import java.io.Serializable; 6 | 7 | /** 8 | * (Submenu)实体类 9 | * 10 | * @author makejava 11 | * @since 2022-07-02 09:07:08 12 | */ 13 | public class Submenu implements Serializable { 14 | private static final long serialVersionUID = 173132120328586407L; 15 | 16 | private Integer id; 17 | /** 18 | * 外键 main_menu 的主键 19 | */ 20 | private Integer mainId; 21 | /** 22 | * 序号 23 | */ 24 | private Integer seq; 25 | /** 26 | * 菜单名 27 | */ 28 | private String menuName; 29 | /** 30 | * 菜单路劲 31 | */ 32 | private String menuUrl; 33 | /** 34 | * 创建人 35 | */ 36 | private String createdBy; 37 | /** 38 | * 创建时间 39 | */ 40 | private Timestamp createdAt; 41 | /** 42 | * 修改人 43 | */ 44 | private String updatedBy; 45 | /** 46 | * 修改时间 47 | */ 48 | private Timestamp updatedAt; 49 | /** 50 | * 修改人 51 | */ 52 | private String deletedBy; 53 | /** 54 | * 删除时间 55 | */ 56 | private Timestamp deletedAt; 57 | /** 58 | * 用户角色 59 | */ 60 | private String type; 61 | 62 | public String getType() { 63 | return type; 64 | } 65 | 66 | public void setType(String type) { 67 | this.type = type; 68 | } 69 | 70 | public Integer getId() { 71 | return id; 72 | } 73 | 74 | public void setId(Integer id) { 75 | this.id = id; 76 | } 77 | 78 | public Integer getMainId() { 79 | return mainId; 80 | } 81 | 82 | public void setMainId(Integer mainId) { 83 | this.mainId = mainId; 84 | } 85 | 86 | public Integer getSeq() { 87 | return seq; 88 | } 89 | 90 | public void setSeq(Integer seq) { 91 | this.seq = seq; 92 | } 93 | 94 | public String getMenuName() { 95 | return menuName; 96 | } 97 | 98 | public void setMenuName(String menuName) { 99 | this.menuName = menuName; 100 | } 101 | 102 | public String getMenuUrl() { 103 | return menuUrl; 104 | } 105 | 106 | public void setMenuUrl(String menuUrl) { 107 | this.menuUrl = menuUrl; 108 | } 109 | 110 | public String getCreatedBy() { 111 | return createdBy; 112 | } 113 | 114 | public void setCreatedBy(String createdBy) { 115 | this.createdBy = createdBy; 116 | } 117 | 118 | 119 | 120 | public String getUpdatedBy() { 121 | return updatedBy; 122 | } 123 | 124 | public void setUpdatedBy(String updatedBy) { 125 | this.updatedBy = updatedBy; 126 | } 127 | 128 | 129 | 130 | public String getDeletedBy() { 131 | return deletedBy; 132 | } 133 | 134 | public void setDeletedBy(String deletedBy) { 135 | this.deletedBy = deletedBy; 136 | } 137 | 138 | public Timestamp getCreatedAt() { 139 | return createdAt; 140 | } 141 | 142 | public void setCreatedAt(Timestamp createdAt) { 143 | this.createdAt = createdAt; 144 | } 145 | 146 | public Timestamp getUpdatedAt() { 147 | return updatedAt; 148 | } 149 | 150 | public void setUpdatedAt(Timestamp updatedAt) { 151 | this.updatedAt = updatedAt; 152 | } 153 | 154 | public Timestamp getDeletedAt() { 155 | return deletedAt; 156 | } 157 | 158 | public void setDeletedAt(Timestamp deletedAt) { 159 | this.deletedAt = deletedAt; 160 | } 161 | } 162 | 163 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/impl/MessageServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service.impl; 2 | 3 | import com.design.foodmanagement.mapper.UsersMapper; 4 | import com.design.foodmanagement.pojo.Message; 5 | import com.design.foodmanagement.mapper.MessageMapper; 6 | import com.design.foodmanagement.pojo.Users; 7 | import com.design.foodmanagement.service.MessageService; 8 | import org.springframework.stereotype.Service; 9 | import javax.annotation.Resource; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import com.design.foodmanagement.pojo.res.RestFulBean; 12 | import java.util.List; 13 | import java.util.Map; 14 | import java.io.IOException; 15 | import com.design.foodmanagement.util.PageUtil; 16 | import com.design.foodmanagement.dto.Page; 17 | /** 18 | * (Message)表服务实现类 19 | * 20 | * @author makejava 21 | * @since 2022-09-03 10:51:47 22 | */ 23 | @Service("messageService") 24 | public class MessageServiceImpl implements MessageService { 25 | @Autowired 26 | private MessageMapper messageMapper; 27 | @Autowired 28 | private UsersMapper usersMapper; 29 | /** 30 | * 分页查询数据 31 | * 32 | * @param //前端传来的参数 33 | * @return 实例对象 34 | */ 35 | @Override 36 | public RestFulBean getList(Page page) throws Exception{ 37 | //前端传来的参数 第几页 38 | Integer pageNum =page.getPageNum(); 39 | //mysql从0开始算起 0 为第一页 所以要减1 startNum 值为从第几条开始拿 40 | Integer startNum =(pageNum-1)* page.getPageSize(); 41 | page.setStartNum(startNum); 42 | //根据前端传来的的条件进行查询 //分页查询 43 | List list= messageMapper.getPageListByCondition(page); 44 | //根据条件查询数据的条数 45 | Integer count = messageMapper.getPageListCount(page); 46 | //拿到总条数跟总页数 在前端渲染 47 | Map map = PageUtil.pagingPrepare(page, count); 48 | //讲查询的数据用map对象返回 49 | map.put("list",list); 50 | return RestFulBean.succ(map); 51 | } 52 | /** 53 | * 通过ID查询单条数据 54 | * 55 | * @param id 主键 56 | * @return 实例对象 57 | */ 58 | @Override 59 | public RestFulBean queryById(Integer id) { 60 | Message message=this.messageMapper.queryById(id); 61 | return RestFulBean.succ(message); 62 | } 63 | 64 | /** 65 | * 新增数据 66 | * 67 | * @param message 实例对象 68 | * @return 实例对象 69 | */ 70 | @Override 71 | public RestFulBean insert(Message message) { 72 | if(message.getEmail()==null){ 73 | return RestFulBean.error("邮箱不能为空"); 74 | } 75 | if(message.getMessage()==null){ 76 | return RestFulBean.error("留言不能为空"); 77 | } 78 | String email =message.getEmail().trim();//获取用户邮箱 79 | Users user =usersMapper.getByEmail(email);//判断邮箱是否注册 80 | if(user==null){ 81 | return RestFulBean.error("该邮箱还未注册"); 82 | } 83 | this.messageMapper.insert(message); 84 | return RestFulBean.succ("添加成功"); 85 | } 86 | 87 | /** 88 | * 修改数据 89 | * 90 | * @param message 实例对象 91 | * @return 实例对象 92 | */ 93 | @Override 94 | public RestFulBean update(Message message) { 95 | this.messageMapper.update(message); 96 | return RestFulBean.succ("修改成功"); 97 | } 98 | 99 | /** 100 | * 通过主键删除数据 101 | * 102 | * @param id 主键 103 | * @return 是否成功 104 | */ 105 | @Override 106 | public RestFulBean deleteById(Integer id) { 107 | this.messageMapper.deleteById(id); 108 | return RestFulBean.succ("删除成功"); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /foodmanagement/src/main/resources/mapper/FestivalFoodMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | insert into festival_food(title, descb, images, type,show_in,created_by,created_at) 27 | values (#{title}, #{descb}, #{images}, #{type},0,'admin',now()) 28 | 29 | 30 | 41 | 42 | 48 | 49 | 50 | 51 | 52 | 53 | update festival_food 54 | 55 | 56 | title = #{title}, 57 | 58 | 59 | descb = #{descb}, 60 | 61 | 62 | images = #{images}, 63 | 64 | 65 | type = #{type}, 66 | 67 | 68 | show_in = #{showIn}, 69 | 70 | 71 | where id = #{id} 72 | 73 | 74 | 75 | 76 | delete from festival_food where id = #{id} 77 | 78 | 81 | 84 | 87 | 88 | update festival_food set show_in=#{showIn} where id =#{id} 89 | 90 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/impl/UsersServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service.impl; 2 | 3 | import com.design.foodmanagement.dto.Page; 4 | import com.design.foodmanagement.pojo.Image; 5 | import com.design.foodmanagement.pojo.Users; 6 | import com.design.foodmanagement.mapper.UsersMapper; 7 | import com.design.foodmanagement.service.UsersService; 8 | import com.design.foodmanagement.util.PageUtil; 9 | import org.springframework.stereotype.Service; 10 | import com.design.foodmanagement.pojo.res.RestFulBean; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * (Users)表服务实现类 19 | * 20 | * @author makejava 21 | * @since 2022-08-30 10:36:43 22 | */ 23 | @Service("usersService") 24 | public class UsersServiceImpl implements UsersService { 25 | @Autowired 26 | private UsersMapper usersMapper; 27 | 28 | /** 29 | * 通过ID查询单条数据 30 | * 31 | * @param id 主键 32 | * @return 实例对象 33 | */ 34 | @Override 35 | public RestFulBean queryById(Integer id) { 36 | Users users=this.usersMapper.queryById(id); 37 | return RestFulBean.succ(users); 38 | } 39 | 40 | /** 41 | * 新增数据 42 | * 43 | * @param users 实例对象 44 | * @return 实例对象 45 | */ 46 | @Override 47 | public RestFulBean insert(Users users) { 48 | if(users.getEmail()==null){ 49 | return RestFulBean.error("邮箱不能为空"); 50 | } 51 | if(!users.getEmail().contains("@")) 52 | { 53 | return RestFulBean.error("请输入合法邮箱"); 54 | } 55 | this.usersMapper.insert(users); 56 | return RestFulBean.succ("添加成功"); 57 | } 58 | 59 | /** 60 | * 修改数据 61 | * 62 | * @param users 实例对象 63 | * @return 实例对象 64 | */ 65 | @Override 66 | public RestFulBean update(Users users) { 67 | this.usersMapper.update(users); 68 | return RestFulBean.succ("修改成功"); 69 | } 70 | 71 | /** 72 | * 通过主键删除数据 73 | * 74 | * @param id 主键 75 | * @return 是否成功 76 | */ 77 | @Override 78 | public RestFulBean deleteById(Integer id) { 79 | this.usersMapper.deleteById(id); 80 | return RestFulBean.succ("删除成功"); 81 | } 82 | 83 | @Override 84 | public RestFulBean login(Users users) { 85 | if(users.getEmail()==null) 86 | { 87 | return RestFulBean.error("账号不能为空"); 88 | } 89 | if(users.getPassword()==null) 90 | { 91 | return RestFulBean.error("密码不能为空"); 92 | } 93 | 94 | //new 一个map对象 用于返回数据给前端 95 | Map result =new HashMap<>(); 96 | String email=users.getEmail().trim(); 97 | Users user =usersMapper.getByEmailAndRole(email);//根据账号跟角色获取对应的用户账号 //后台只能管理员登录 98 | //用户不为空 99 | if (user!=null){ 100 | //密码跟数据库一样 101 | if(users.getPassword().equals(user.getPassword())) 102 | { 103 | return RestFulBean.succ("登录成功"); 104 | } 105 | else{ 106 | return RestFulBean.error("密码错误"); 107 | } 108 | 109 | } 110 | return RestFulBean.error("用户不存在"); 111 | } 112 | 113 | @Override 114 | public RestFulBean getList(Page page)throws Exception { 115 | //前端传来的参数 第几页 116 | Integer pageNum =page.getPageNum(); 117 | //mysql从0开始算起 0 为第一页 所以要减1 startNum 值为从第几条开始拿 118 | Integer startNum =(pageNum-1)* page.getPageSize(); 119 | page.setStartNum(startNum); 120 | //根据前端传来的的条件进行查询 //分页查询 121 | List list= usersMapper.getPageListByCondition(page); 122 | //根据条件查询数据的条数 123 | Integer count = usersMapper.getPageListCount(page); 124 | //拿到总条数跟总页数 在前端渲染 125 | Map map = PageUtil.pagingPrepare(page, count); 126 | //讲查询的数据用map对象返回 127 | map.put("list",list); 128 | return RestFulBean.succ(map); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/impl/ImageServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service.impl; 2 | 3 | import com.design.foodmanagement.pojo.FestivalFood; 4 | import com.design.foodmanagement.pojo.Image; 5 | import com.design.foodmanagement.mapper.ImageMapper; 6 | import com.design.foodmanagement.service.ImageService; 7 | import org.springframework.stereotype.Service; 8 | import javax.annotation.Resource; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import com.design.foodmanagement.pojo.res.RestFulBean; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.io.IOException; 14 | import com.design.foodmanagement.util.PageUtil; 15 | import com.design.foodmanagement.dto.Page; 16 | /** 17 | * (Image)表服务实现类 18 | * 19 | * @author makejava 20 | * @since 2022-08-31 20:40:52 21 | */ 22 | @Service("imageService") 23 | public class ImageServiceImpl implements ImageService { 24 | @Autowired 25 | private ImageMapper imageMapper; 26 | /** 27 | * 分页查询数据 28 | * 29 | * @param //前端传来的参数 30 | * @return 实例对象 31 | */ 32 | @Override 33 | public RestFulBean getList(Page page) throws Exception{ 34 | //前端传来的参数 第几页 35 | Integer pageNum =page.getPageNum(); 36 | //mysql从0开始算起 0 为第一页 所以要减1 startNum 值为从第几条开始拿 37 | Integer startNum =(pageNum-1)* page.getPageSize(); 38 | page.setStartNum(startNum); 39 | //根据前端传来的的条件进行查询 //分页查询 40 | List list= imageMapper.getPageListByCondition(page); 41 | if(list.size()>0){ //数据大于0 才进去 42 | for(Image image: list){ 43 | image.setImagesUrl("http://localhost:8087/file/"+image.getImages()); 44 | } 45 | } 46 | //根据条件查询数据的条数 47 | Integer count = imageMapper.getPageListCount(page); 48 | //拿到总条数跟总页数 在前端渲染 49 | Map map = PageUtil.pagingPrepare(page, count); 50 | //讲查询的数据用map对象返回 51 | map.put("list",list); 52 | return RestFulBean.succ(map); 53 | } 54 | /** 55 | * 通过ID查询单条数据 56 | * 57 | * @param id 主键 58 | * @return 实例对象 59 | */ 60 | @Override 61 | public RestFulBean queryById(Integer id) { 62 | Image image=this.imageMapper.queryById(id); 63 | return RestFulBean.succ(image); 64 | } 65 | 66 | /** 67 | * 新增数据 68 | * 69 | * @param image 实例对象 70 | * @return 实例对象 71 | */ 72 | @Override 73 | public RestFulBean insert(Image image) { 74 | if(image.getImages()==null || image.getImages().equals("")){ 75 | return RestFulBean.error("图片不能为空"); 76 | } 77 | this.imageMapper.insert(image); 78 | return RestFulBean.succ("添加成功"); 79 | } 80 | 81 | /** 82 | * 修改数据 83 | * 84 | * @param image 实例对象 85 | * @return 实例对象 86 | */ 87 | @Override 88 | public RestFulBean update(Image image) { 89 | this.imageMapper.update(image); 90 | return RestFulBean.succ("修改成功"); 91 | } 92 | 93 | /** 94 | * 通过主键删除数据 95 | * 96 | * @param id 主键 97 | * @return 是否成功 98 | */ 99 | @Override 100 | public RestFulBean deleteById(Integer id) { 101 | this.imageMapper.deleteById(id); 102 | return RestFulBean.succ("删除成功"); 103 | } 104 | 105 | @Override 106 | public RestFulBean> getSlideshow() { 107 | List list =imageMapper.getSlideshow(); 108 | if(list.size()>0){ //数据大于0 才进去 109 | for(Image image: list){ 110 | image.setImagesUrl("http://localhost:8087/file/"+image.getImages()); 111 | } 112 | } 113 | return RestFulBean.succ(list); 114 | } 115 | 116 | @Override 117 | public RestFulBean> getFoodImage() { 118 | List list =imageMapper.getFoodImage(); 119 | if(list.size()>0){ //数据大于0 才进去 120 | for(Image image: list){ 121 | image.setImagesUrl("http://localhost:8087/file/"+image.getImages()); 122 | } 123 | } 124 | return RestFulBean.succ(list); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/controller/FestivalFoodController.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.controller; 2 | 3 | import com.design.foodmanagement.pojo.FestivalFood; 4 | import com.design.foodmanagement.pojo.Image; 5 | import com.design.foodmanagement.service.FestivalFoodService; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.*; 8 | import javax.annotation.Resource; 9 | import com.design.foodmanagement.pojo.res.RestFulBean; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.*; 12 | import com.design.foodmanagement.dto.Page; 13 | import org.springframework.web.multipart.MultipartFile; 14 | 15 | import java.io.IOException; 16 | import java.util.List; 17 | import java.util.Map; 18 | /** 19 | * (FestivalFood)表控制层 20 | * 21 | * @author makejava 22 | * @since 2022-08-31 20:38:36 23 | */ 24 | @RestController 25 | @RequestMapping("/festivalFood") 26 | public class FestivalFoodController { 27 | /** 28 | * 服务对象 29 | */ 30 | @Autowired 31 | private FestivalFoodService festivalFoodService; 32 | 33 | /** 34 | * 分页查询 35 | * 36 | * @param //前端传来的参数 37 | * @return 38 | */ 39 | @PostMapping("/get/page/list") 40 | public RestFulBean getList(@RequestBody Pagepage) throws Exception{ 41 | return this.festivalFoodService.getList(page); 42 | } 43 | /** 44 | * 通过主键查询单条数据 45 | * 46 | * @param id 主键 47 | * @return 单条数据 48 | */ 49 | @PostMapping("/get/by/id") 50 | public RestFulBean queryById(@RequestBody FestivalFood festivalFood) { 51 | return this.festivalFoodService.queryById(festivalFood.getId()); 52 | } 53 | 54 | /** 55 | * 新增数据 56 | * 57 | * @param festivalFood 实体 58 | * @return 新增结果 59 | */ 60 | @PostMapping("/add") 61 | public RestFulBean add(@RequestBody FestivalFood festivalFood) { 62 | return this.festivalFoodService.insert(festivalFood); 63 | } 64 | 65 | /** 66 | * 编辑数据 67 | * 68 | * @param festivalFood 实体 69 | * @return 编辑结果 70 | */ 71 | @PostMapping("/update") 72 | public RestFulBean edit(@RequestBody FestivalFood festivalFood) { 73 | return this.festivalFoodService.update(festivalFood); 74 | } 75 | 76 | /** 77 | * 删除数据 78 | * 79 | * @param id 主键 80 | * @return 删除是否成功 81 | */ 82 | @PostMapping("/delete") 83 | public RestFulBean deleteById(@RequestBody FestivalFood festivalFood) { 84 | return this.festivalFoodService.deleteById(festivalFood.getId()); 85 | } 86 | //上传照片 87 | @PostMapping("/upload/image") 88 | public RestFulBean upload(@RequestParam(value = "coverFile",required = false) MultipartFile coverFile ) throws Exception { 89 | return festivalFoodService.upload(coverFile); 90 | } 91 | /** 92 | * 获取网页最新发布 93 | * 94 | * @param 95 | * @return 96 | */ 97 | @PostMapping("/get/new/product") 98 | public RestFulBean> getNewProduct() { 99 | return this.festivalFoodService.getNewProduct(); 100 | } 101 | /** 102 | * 获取网页热门推荐 103 | * 104 | * @param 105 | * @return 106 | */ 107 | @PostMapping("/get/recommend") 108 | public RestFulBean> getRecommend() { 109 | return this.festivalFoodService.getRecommend(); 110 | } 111 | /** 112 | * 获取网页节日美食 113 | * 114 | * @param 115 | * @return 116 | */ 117 | @PostMapping("/get/festival/food") 118 | public RestFulBean> getFestivalFood() { 119 | return this.festivalFoodService.getFestivalFood(); 120 | } 121 | 122 | /** 123 | * 修改数据是否展示 124 | * 125 | * @param 126 | * @return 127 | */ 128 | @PostMapping("/show/in") 129 | public RestFulBean showIn(@RequestBody FestivalFood festivalFood) { 130 | return this.festivalFoodService.showIn(festivalFood); 131 | } 132 | /** 133 | * 获取美食活动数据 134 | * 135 | * @param 136 | * @return 137 | */ 138 | @PostMapping("/get/food/active") 139 | public RestFulBean> getFoodActive() { 140 | return this.festivalFoodService.getFoodActive(); 141 | } 142 | } 143 | 144 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.exception; 2 | 3 | import com.design.foodmanagement.pojo.res.Code; 4 | import com.design.foodmanagement.pojo.res.RestFulBean; 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.http.converter.HttpMessageNotReadableException; 9 | import org.springframework.validation.FieldError; 10 | import org.springframework.web.HttpRequestMethodNotSupportedException; 11 | import org.springframework.web.bind.MethodArgumentNotValidException; 12 | import org.springframework.web.bind.annotation.ControllerAdvice; 13 | import org.springframework.web.bind.annotation.ExceptionHandler; 14 | import org.springframework.web.bind.annotation.ResponseBody; 15 | import org.springframework.web.util.ContentCachingRequestWrapper; 16 | 17 | import javax.servlet.ServletException; 18 | import javax.servlet.ServletRequest; 19 | import javax.validation.ConstraintViolationException; 20 | import java.io.ByteArrayOutputStream; 21 | import java.io.IOException; 22 | import java.io.PrintStream; 23 | import java.nio.charset.Charset; 24 | import java.sql.SQLException; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | @ControllerAdvice 29 | @ResponseBody 30 | public class GlobalExceptionHandler { 31 | private final static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); 32 | 33 | /** 34 | * controller 数据校验异常 35 | * @param exception 36 | * @return 37 | */ 38 | @ExceptionHandler(ConstraintViolationException.class) 39 | @ResponseBody 40 | public RestFulBean constraintViolationException(ConstraintViolationException exception) { 41 | RestFulBean error = RestFulBean.error(Code.BAD_REQUEST, exception.getMessage()); 42 | return error; 43 | } 44 | @ExceptionHandler(HttpMessageNotReadableException.class) 45 | @ResponseBody 46 | public RestFulBean httpRequestMethodNotSupportedException(HttpMessageNotReadableException exception) { 47 | RestFulBean error = RestFulBean.error(Code.BAD_REQUEST, "参数转换失败"); 48 | return error; 49 | } 50 | @ExceptionHandler(HttpRequestMethodNotSupportedException.class) 51 | @ResponseBody 52 | public RestFulBean httpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) { 53 | RestFulBean error = RestFulBean.error(Code.ERROR, "不支持该请求方式"); 54 | return error; 55 | } 56 | @ExceptionHandler(NullPointerException.class) 57 | @ResponseBody 58 | public RestFulBean nullPointerException(ServletRequest req, NullPointerException exception) throws IOException { 59 | String uri = ""; 60 | String body = ""; 61 | if (req instanceof ContentCachingRequestWrapper) { 62 | ContentCachingRequestWrapper wrapper = (ContentCachingRequestWrapper) req; 63 | body = StringUtils.toEncodedString(wrapper.getContentAsByteArray(), Charset.forName(wrapper.getCharacterEncoding())); 64 | uri = wrapper.getRequestURI(); 65 | } 66 | String message = getException(exception); 67 | logger.error("uri:{} 发生未知异常{}",uri,message); 68 | RestFulBean error = RestFulBean.error(Code.Null_Pointer, exception.getMessage()); 69 | return error; 70 | } 71 | 72 | //校验逻辑抛出 73 | @ExceptionHandler(MethodArgumentNotValidException.class) 74 | @ResponseBody 75 | public RestFulBean> handleValidationExceptions(MethodArgumentNotValidException exception) { 76 | Map errors = new HashMap<>(); 77 | StringBuilder sb = new StringBuilder(); 78 | exception.getBindingResult().getAllErrors().forEach((error) -> { 79 | sb.append(error.getDefaultMessage()).append(","); 80 | String fieldName = ((FieldError) error).getField(); 81 | String errorMessage = error.getDefaultMessage(); 82 | errors.put(fieldName, errorMessage); 83 | }); 84 | RestFulBean> error = RestFulBean.error(Code.BAD_REQUEST, sb.toString(),errors); 85 | return error; 86 | } 87 | @ExceptionHandler(SQLException.class) 88 | @ResponseBody 89 | public RestFulBean SQLException(MethodArgumentNotValidException exception) { 90 | return RestFulBean.error(Code.BAD_REQUEST, "执行失败请刷新再试",400); 91 | } 92 | //HttpRequestMethodNotSupportedException 请求方式异常 93 | 94 | /** 95 | * 处理,实际为捕捉全局异常 96 | * @param exception 全局异常 97 | * @return 具体异常信息 后面那个是500报错内容是服务器内部异常 98 | */ 99 | @ExceptionHandler(Exception.class) 100 | @ResponseBody 101 | public RestFulBean Exception(ServletRequest req, Exception exception) throws IOException, ServletException { 102 | String uri = ""; 103 | String body = ""; 104 | if (req instanceof ContentCachingRequestWrapper) { 105 | ContentCachingRequestWrapper wrapper = (ContentCachingRequestWrapper) req; 106 | body = StringUtils.toEncodedString(wrapper.getContentAsByteArray(), Charset.forName(wrapper.getCharacterEncoding())); 107 | uri = wrapper.getRequestURI(); 108 | } 109 | String message = getException(exception); 110 | logger.error("uri:{} 发生未知异常{}",uri,message); 111 | return RestFulBean.error(Code.ERROR,"请求异常"); 112 | } 113 | public static String getException(Exception e) throws IOException { 114 | String ret = null; 115 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 116 | PrintStream pout = new PrintStream(out); 117 | e.printStackTrace(pout); 118 | ret = new String(out.toByteArray()); 119 | pout.close(); 120 | out.close(); 121 | return ret; 122 | 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/impl/MainMenuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service.impl; 2 | 3 | import com.design.foodmanagement.mapper.SubmenuMapper; 4 | import com.design.foodmanagement.mapper.UsersMapper; 5 | import com.design.foodmanagement.pojo.MainMenu; 6 | import com.design.foodmanagement.mapper.MainMenuMapper; 7 | import com.design.foodmanagement.pojo.Submenu; 8 | import com.design.foodmanagement.pojo.Users; 9 | import com.design.foodmanagement.service.MainMenuService; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import com.design.foodmanagement.pojo.res.RestFulBean; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | /** 21 | * (MainMenu)表服务实现类 22 | * 23 | * @author makejava 24 | * @since 2022-07-02 09:06:33 25 | */ 26 | @Service("mainMenuService") 27 | public class MainMenuServiceImpl implements MainMenuService { 28 | @Autowired 29 | private MainMenuMapper mainMenuMapper; 30 | 31 | @Autowired 32 | private UsersMapper usersMapper; 33 | 34 | @Autowired 35 | private SubmenuMapper submenuMapper; 36 | /** 37 | * 通过ID查询单条数据 38 | * 39 | * @param id 主键 40 | * @return 实例对象 41 | */ 42 | @Override 43 | public RestFulBean queryById(Integer id) { 44 | MainMenu mainMenu=this.mainMenuMapper.queryById(id); 45 | return RestFulBean.succ(mainMenu); 46 | } 47 | 48 | /** 49 | * 新增数据 50 | * 51 | * @param mainMenu 实例对象 52 | * @return 实例对象 53 | */ 54 | @Override 55 | public RestFulBean insert(MainMenu mainMenu) { 56 | this.mainMenuMapper.insert(mainMenu); 57 | return RestFulBean.succ("添加成功"); 58 | } 59 | 60 | /** 61 | * 修改数据 62 | * 63 | * @param mainMenu 实例对象 64 | * @return 实例对象 65 | */ 66 | @Override 67 | public RestFulBean update(MainMenu mainMenu) { 68 | this.mainMenuMapper.update(mainMenu); 69 | return RestFulBean.succ("修改成功"); 70 | } 71 | 72 | /** 73 | * 通过主键删除数据 74 | * 75 | * @param id 主键 76 | * @return 是否成功 77 | */ 78 | @Override 79 | public RestFulBean deleteById(Integer id) { 80 | this.mainMenuMapper.deleteById(id); 81 | return RestFulBean.succ("删除成功"); 82 | } 83 | /** 84 | * 获取菜单权限 85 | * 86 | * @param user 87 | * @return Map 88 | */ 89 | @Override 90 | public RestFulBean> getMenuTree() throws Exception { 91 | //try catch 如果请求异常 则return 请求异常 92 | try { 93 | ListmainMenuList=mainMenuMapper.getMainMenu(); //根据主菜单 94 | List subMenuLsit = submenuMapper.getSubMenu();//根据子菜单 95 | //循环遍历 96 | for(MainMenu mainMenu : mainMenuList) 97 | { 98 | List list=new ArrayList<>();//定义一个新数组 用来放子菜单的对象 99 | for(Submenu submenu :subMenuLsit ) 100 | { 101 | if(mainMenu.getId()==submenu.getMainId()) 102 | { 103 | list.add(submenu); 104 | } 105 | } 106 | mainMenu.setSubmenuList(list);//将主菜单所属的子菜单存到MainMenu的对象数组返回给前端渲染 107 | } 108 | //返回一个对象map 109 | Map date = new HashMap<>(); 110 | date.put("menuList", mainMenuList); 111 | return RestFulBean.succ(date); 112 | } catch (Exception e) { 113 | e.printStackTrace(); 114 | return RestFulBean.error("请求异常"); 115 | } 116 | } 117 | 118 | @Override 119 | public RestFulBean addMenu(Submenu submenu) throws Exception { 120 | //判空 121 | if(submenu.getMainId()==null) 122 | { 123 | return RestFulBean.error("请选择主菜单"); 124 | } 125 | if(submenu.getMenuName()==null) 126 | { 127 | return RestFulBean.error("菜单名字不能为空"); 128 | } 129 | if(submenu.getSeq()==null) 130 | { 131 | return RestFulBean.error("序号不能为空"); 132 | } 133 | //创建人跟修改写死开发者 这个功能只有开发者用 134 | submenu.setCreatedBy("developer"); 135 | submenu.setUpdatedBy("developer"); 136 | submenuMapper.addMenu(submenu); 137 | return RestFulBean.succ("新增成功"); 138 | } 139 | 140 | @Override 141 | public RestFulBean addMainMenu(MainMenu mainMenu) { 142 | //判空 143 | if(mainMenu.getMainName()==null) 144 | { 145 | return RestFulBean.error("菜单名字不能为空"); 146 | } 147 | if(mainMenu.getSeq()==null) 148 | { 149 | return RestFulBean.error("序号不能为空"); 150 | } 151 | //创建人跟修改写死开发者 这个功能只有开发者用 152 | mainMenu.setCreatedBy("developer"); 153 | mainMenu.setUpdatedBy("developer"); 154 | mainMenuMapper.addMenu(mainMenu); 155 | return RestFulBean.succ("新增成功"); 156 | } 157 | 158 | @Override 159 | public RestFulBean updateMainMenu(MainMenu mainMenu) { 160 | mainMenuMapper.updateMainMenu(mainMenu); 161 | return RestFulBean.succ("修改成功"); 162 | } 163 | 164 | @Override 165 | public RestFulBean updateMenu(Submenu submenu) { 166 | submenuMapper.updateMenu(submenu); 167 | return RestFulBean.succ("修改成功"); 168 | } 169 | 170 | @Override 171 | public RestFulBean delMenu(Submenu submenu) { 172 | submenuMapper.deleteById(submenu.getId()); 173 | return RestFulBean.succ("删除成功"); 174 | } 175 | //用@Transactional事务注解回滚 多表删除 如果报错则撤回原来删除的数据 176 | @Transactional 177 | @Override 178 | public RestFulBean delMainMenu(MainMenu mainMenu) { 179 | //删除主菜单 必须要主表细表的数据都删除掉 就是 main_menu submenu 相关联的数据都删掉 180 | Integer id =mainMenu.getId();//main_menu的id 181 | Listlist=submenuMapper.getByMainId(id); 182 | if(list.size()>0) 183 | { 184 | for(Submenu submenu:list){ 185 | submenuMapper.deleteById(submenu.getId());//把submenu表中main_id所有等于main_menu id 的值全部删除 186 | } 187 | } 188 | mainMenuMapper.deleteById(id);//根据id删掉main_menu中的表 189 | return RestFulBean.succ("删除成功"); 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/service/impl/FestivalFoodServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.service.impl; 2 | 3 | import com.design.foodmanagement.pojo.FestivalFood; 4 | import com.design.foodmanagement.mapper.FestivalFoodMapper; 5 | import com.design.foodmanagement.pojo.Image; 6 | import com.design.foodmanagement.service.FestivalFoodService; 7 | import com.design.foodmanagement.util.FileUtil; 8 | import org.springframework.stereotype.Service; 9 | import javax.annotation.Resource; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import com.design.foodmanagement.pojo.res.RestFulBean; 12 | 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | import java.io.IOException; 17 | import com.design.foodmanagement.util.PageUtil; 18 | import com.design.foodmanagement.dto.Page; 19 | import org.springframework.web.multipart.MultipartFile; 20 | 21 | /** 22 | * (FestivalFood)表服务实现类 23 | * 24 | * @author makejava 25 | * @since 2022-08-31 20:38:36 26 | */ 27 | @Service("festivalFoodService") 28 | public class FestivalFoodServiceImpl implements FestivalFoodService { 29 | @Autowired 30 | private FestivalFoodMapper festivalFoodMapper; 31 | /** 32 | * 分页查询数据 33 | * 34 | * @param //前端传来的参数 35 | * @return 实例对象 36 | */ 37 | @Override 38 | public RestFulBean getList(Page page) throws Exception{ 39 | //前端传来的参数 第几页 40 | Integer pageNum =page.getPageNum(); 41 | //mysql从0开始算起 0 为第一页 所以要减1 startNum 值为从第几条开始拿 42 | Integer startNum =(pageNum-1)* page.getPageSize(); 43 | page.setStartNum(startNum); 44 | //根据前端传来的的条件进行查询 //分页查询 45 | List list= festivalFoodMapper.getPageListByCondition(page); 46 | if(list.size()>0){ //数据大于0 才进去 47 | for(FestivalFood festivalFood: list){ 48 | festivalFood.setImagesUrl("http://localhost:8087/file/"+festivalFood.getImages()); 49 | } 50 | } 51 | //根据条件查询数据的条数 52 | Integer count = festivalFoodMapper.getPageListCount(page); 53 | //拿到总条数跟总页数 在前端渲染 54 | Map map = PageUtil.pagingPrepare(page, count); 55 | //讲查询的数据用map对象返回 56 | map.put("list",list); 57 | return RestFulBean.succ(map); 58 | } 59 | /** 60 | * 通过ID查询单条数据 61 | * 62 | * @param id 主键 63 | * @return 实例对象 64 | */ 65 | @Override 66 | public RestFulBean queryById(Integer id) { 67 | FestivalFood festivalFood=this.festivalFoodMapper.queryById(id); 68 | return RestFulBean.succ(festivalFood); 69 | } 70 | 71 | /** 72 | * 新增数据 73 | * 74 | * @param festivalFood 实例对象 75 | * @return 实例对象 76 | */ 77 | @Override 78 | public RestFulBean insert(FestivalFood festivalFood) { 79 | if(festivalFood.getTitle()==null){ 80 | return RestFulBean.error("标题不能为空"); 81 | } 82 | if(festivalFood.getDescb()==null){ 83 | return RestFulBean.error("描述不能为空"); 84 | } 85 | this.festivalFoodMapper.insert(festivalFood); 86 | return RestFulBean.succ("添加成功"); 87 | } 88 | 89 | /** 90 | * 修改数据 91 | * 92 | * @param festivalFood 实例对象 93 | * @return 实例对象 94 | */ 95 | @Override 96 | public RestFulBean update(FestivalFood festivalFood) { 97 | this.festivalFoodMapper.update(festivalFood); 98 | return RestFulBean.succ("修改成功"); 99 | } 100 | 101 | /** 102 | * 通过主键删除数据 103 | * 104 | * @param id 主键 105 | * @return 是否成功 106 | */ 107 | @Override 108 | public RestFulBean deleteById(Integer id) { 109 | this.festivalFoodMapper.deleteById(id); 110 | return RestFulBean.succ("删除成功"); 111 | } 112 | 113 | @Override 114 | public RestFulBean upload(MultipartFile coverFile) { 115 | String destPath ="D:\\design\\images\\"; 116 | // 存图片 117 | try{ 118 | FileUtil.saveFile(coverFile, destPath,coverFile.getOriginalFilename()); 119 | } 120 | catch(Exception e){ 121 | return RestFulBean.error("请求异常"); 122 | } 123 | Map map =new HashMap(); 124 | //将图片名字返回 用于录入用户的时候 把这个值保存到image字段中 125 | map.put("imageName",coverFile.getOriginalFilename()); 126 | //本地获取图片的路劲 127 | map.put("url","http://localhost:8087/file/"+coverFile.getOriginalFilename()); 128 | 129 | return RestFulBean.succ(map); 130 | } 131 | 132 | @Override 133 | public RestFulBean> getNewProduct() { 134 | List list =festivalFoodMapper.getNewProduct(); 135 | if(list.size()>0){ //数据大于0 才进去 136 | for(FestivalFood festivalFood: list){ 137 | festivalFood.setImagesUrl("http://localhost:8087/file/"+festivalFood.getImages()); 138 | } 139 | } 140 | return RestFulBean.succ(list); 141 | } 142 | 143 | @Override 144 | public RestFulBean> getRecommend() { 145 | List list =festivalFoodMapper.getRecommend(); 146 | if(list.size()>0){ //数据大于0 才进去 147 | for(FestivalFood festivalFood: list){ 148 | festivalFood.setImagesUrl("http://localhost:8087/file/"+festivalFood.getImages()); 149 | } 150 | } 151 | return RestFulBean.succ(list); 152 | } 153 | 154 | @Override 155 | public RestFulBean> getFestivalFood() { 156 | List list =festivalFoodMapper.getFestivalFood(); 157 | if(list.size()>0){ //数据大于0 才进去 158 | for(FestivalFood festivalFood: list){ 159 | festivalFood.setImagesUrl("http://localhost:8087/file/"+festivalFood.getImages()); 160 | } 161 | } 162 | return RestFulBean.succ(list); 163 | } 164 | 165 | @Override 166 | public RestFulBean showIn(FestivalFood festivalFood) { 167 | this.festivalFoodMapper.showIn(festivalFood); 168 | return RestFulBean.succ("修改成功"); 169 | } 170 | 171 | @Override 172 | public RestFulBean> getFoodActive() { 173 | List list =festivalFoodMapper.getFoodActive(); 174 | if(list.size()>0){ //数据大于0 才进去 175 | for(FestivalFood festivalFood: list){ 176 | festivalFood.setImagesUrl("http://localhost:8087/file/"+festivalFood.getImages()); 177 | } 178 | } 179 | return RestFulBean.succ(list); 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /foodmanagement/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* 50 | if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 124 | 125 | FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% ^ 162 | %JVM_CONFIG_MAVEN_PROPS% ^ 163 | %MAVEN_OPTS% ^ 164 | %MAVEN_DEBUG_OPTS% ^ 165 | -classpath %WRAPPER_JAR% ^ 166 | "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ 167 | %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 168 | if ERRORLEVEL 1 goto error 169 | goto end 170 | 171 | :error 172 | set ERROR_CODE=1 173 | 174 | :end 175 | @endlocal & set ERROR_CODE=%ERROR_CODE% 176 | 177 | if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost 178 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 179 | if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" 180 | if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" 181 | :skipRcPost 182 | 183 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 184 | if "%MAVEN_BATCH_PAUSE%"=="on" pause 185 | 186 | if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% 187 | 188 | cmd /C exit /B %ERROR_CODE% 189 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/util/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.util; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import java.io.*; 9 | import java.nio.charset.Charset; 10 | import java.util.Enumeration; 11 | import java.util.UUID; 12 | import java.util.regex.Matcher; 13 | import java.util.regex.Pattern; 14 | import java.util.zip.ZipEntry; 15 | import java.util.zip.ZipFile; 16 | 17 | @Component 18 | public class FileUtil { 19 | private final static Logger logger = LoggerFactory.getLogger(FileUtil.class); 20 | 21 | //文件类型 22 | public static String IMG_TYPE_PNG = "PNG"; 23 | public static String IMG_TYPE_JPG = "JPG"; 24 | 25 | /** 26 | * 文件后缀名分隔符 27 | */ 28 | public static final String SUFFIX_SPLIT = "."; 29 | 30 | /** 31 | * 获取文件名的后缀,如 jpg/txt等 32 | * 33 | * @param fileName 34 | * @return 35 | */ 36 | public static String getSuffix(String fileName) { 37 | if (fileName!=null){ 38 | return fileName.substring(fileName.lastIndexOf(SUFFIX_SPLIT) + 1); 39 | } 40 | return null; 41 | } 42 | 43 | /** 44 | * 上传文件 可随机命名或者使用原名 45 | * @param file 46 | * @param filePath 存储地址 47 | * @param repetition 是否使用原名 建议不要使用中文路径会有bug 48 | * @return 返回文件名(不包括文件路径) 49 | */ 50 | public static String saveFile(MultipartFile file, String filePath, boolean repetition) throws IOException, NullPointerException { 51 | if (!file.isEmpty()) { 52 | String fileName = file.getOriginalFilename(); 53 | assert fileName != null; 54 | if (!repetition){ 55 | String uuid = UUID.randomUUID().toString(); 56 | uuid = uuid.replace("-", ""); 57 | fileName = uuid + "." +FileUtil.getSuffix(fileName); 58 | } 59 | File dest = new File(filePath + fileName); 60 | if (!dest.getParentFile().exists()) { 61 | dest.getParentFile().mkdirs(); 62 | } 63 | file.transferTo(dest); 64 | return fileName; 65 | }else{ 66 | throw new NullPointerException("不能上传空文件"); 67 | } 68 | } 69 | 70 | /** 71 | * 上传文件 自定义文件名 72 | * @param file 73 | * @param filePath 路径名 74 | * @param fileName 文件名 75 | * @return 76 | * @throws IOException 77 | * @throws NullPointerException 78 | */ 79 | public static String saveFile(MultipartFile file, String filePath, String fileName) throws IOException, NullPointerException { 80 | if (!file.isEmpty()) { 81 | File dest = new File(filePath + fileName); 82 | if (!dest.getParentFile().exists()) { 83 | dest.getParentFile().mkdirs(); 84 | } 85 | file.transferTo(dest); 86 | return fileName; 87 | }else{ 88 | throw new NullPointerException("不能上传空文件"); 89 | } 90 | } 91 | 92 | 93 | /*public static void main(String[] args) { 94 | File oldName = new File("D:\\opt\\java\\cms\\temporary\\default.jpg"); 95 | File newName = new File("D:\\opt\\java\\cms\\StockStore2\\public\\images\\EBook\\FW2022\\cover\\en\\default.jpg"); 96 | System.out.println(oldName.renameTo(newName));//E:\\java task\\zhl.txt移动至E:\\java task\\zhlll 97 | 98 | }*/ 99 | /** 100 | * 移动文件 101 | * 102 | * @param originalFilePath 原文件 103 | * @param destinationFloderUrl 目标地址 104 | * @param destName 文件名需要带后缀名 105 | */ 106 | public static boolean removeFile(String originalFilePath, String destinationFloderUrl, String destName) { 107 | 108 | File file = new File(originalFilePath); 109 | File destFloder = new File(destinationFloderUrl); 110 | //检查目标路径是否合法 111 | if (destFloder.exists()) { 112 | if (destFloder.isFile()) { 113 | return false; 114 | } 115 | } else { 116 | if (!destFloder.mkdirs()) { 117 | return false; 118 | } 119 | } 120 | //检查源文件是否合法 121 | if (file.isFile() && file.exists()) { 122 | String destinationFile = destinationFloderUrl + destName; 123 | File destFile = new File(destinationFile); 124 | if (!file.renameTo(destFile)) { 125 | return false; 126 | } 127 | } else { 128 | return false; 129 | } 130 | return true; 131 | } 132 | 133 | /** 134 | * 匹配文件类型 135 | *忽略大小写 136 | * @param fileType jpg,png 137 | * @param fileName 138 | * @return 139 | */ 140 | public static boolean isNumType(String fileType, String fileName) { 141 | if (fileType != null && fileName != null) { 142 | String substring = fileName.substring(fileName.lastIndexOf(".")+1); //获取文件后缀名(判断类型) 143 | String[] str = fileType.split(","); //截取出来后缀名 也就是要匹配什么类型 144 | for (String s : str) {//遍历是否符合后缀 145 | if (substring.toLowerCase().equals(s)) { 146 | return true; 147 | } 148 | } 149 | return false; 150 | } 151 | return false; 152 | } 153 | /** 154 | * 解压zip 155 | * @param zipFilePath 待解压文件的路径 D:/test/java.zip 156 | * @param unzipFilePath 解压后的文件存储路径 D:/test/ 157 | * @throws Exception 158 | */ 159 | public static void unzip(String zipFilePath, String unzipFilePath) throws Exception { 160 | File zipFile = new File(zipFilePath); 161 | 162 | 163 | //创建解压缩文件保存的路径 164 | File unzipFileDir = new File(unzipFilePath); 165 | if (!unzipFileDir.exists() || !unzipFileDir.isDirectory()) { 166 | unzipFileDir.mkdirs(); 167 | } 168 | 169 | //开始解压 170 | ZipEntry entry = null; 171 | String entryFilePath = null, entryDirPath = null; 172 | File entryFile = null, entryDir = null; 173 | int index = 0, count = 0; 174 | byte[] buffer = new byte[1024]; 175 | BufferedInputStream bis = null; 176 | BufferedOutputStream bos = null; 177 | ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK")); 178 | Enumeration entries = (Enumeration)zip.entries(); 179 | //循环对压缩包里的每一个文件进行解压 180 | while(entries.hasMoreElements()) { 181 | entry = entries.nextElement(); 182 | String entryName = entry.getName(); 183 | entryName = entryName.replace("/",File.separator); 184 | //构建压缩包中一个文件解压后保存的文件全路径 185 | entryFilePath = unzipFilePath + entryName; 186 | //构建解压后保存的文件夹路径 187 | index = entryFilePath.lastIndexOf(File.separator); 188 | if (index != -1) { 189 | entryDirPath = entryFilePath.substring(0, index); 190 | } 191 | else { 192 | entryDirPath = ""; 193 | } 194 | entryDir = new File(entryDirPath); 195 | //如果文件夹路径不存在,则创建文件夹 196 | if (!entryDir.exists() || !entryDir.isDirectory()) { 197 | entryDir.mkdirs(); 198 | } 199 | 200 | //创建解压文件 201 | entryFile = new File(entryFilePath); 202 | if (entryFile.exists()&&entryFile.isFile()) { 203 | //检测文件是否允许删除,如果不允许删除,将会抛出SecurityException 204 | SecurityManager securityManager = new SecurityManager(); 205 | securityManager.checkDelete(entryFilePath); 206 | // 删除已存在的目标文件 207 | entryFile.delete(); 208 | } 209 | if(entryFile.isDirectory()){ 210 | continue; 211 | } 212 | //写入文件 213 | bos = new BufferedOutputStream(new FileOutputStream(entryFile)); 214 | bis = new BufferedInputStream(zip.getInputStream(entry)); 215 | while ((count = bis.read(buffer, 0, 1024)) != -1) { 216 | bos.write(buffer, 0, count); 217 | } 218 | bos.flush(); 219 | bos.close(); 220 | bis.close(); 221 | } 222 | } 223 | /** 224 | * 删除单个文件 225 | * 226 | * @param fileName 227 | * 要删除的文件的文件名(包括路径) 228 | * @return 单个文件删除成功返回true,否则返回false 229 | */ 230 | public static boolean deleteFile(String fileName) { 231 | File file = new File(fileName); 232 | // 如果文件路径所对应的文件存在,并且是一个文件,则直接删除 233 | if (file.exists() && file.isFile()) { 234 | if (file.delete()) { 235 | logger.info("文件删除成功{}",fileName); 236 | return true; 237 | } else { 238 | logger.error("文件删除失败{}",fileName); 239 | 240 | return false; 241 | } 242 | } else { 243 | logger.error("文件删除失败{} 不存在",fileName); 244 | 245 | return false; 246 | } 247 | } 248 | 249 | 250 | //复制文件 251 | public static void copyFile(File fromFile, File toFile) throws IOException { 252 | FileInputStream ins = new FileInputStream(fromFile); 253 | if (!toFile.getParentFile().exists()) { 254 | toFile.getParentFile().mkdirs(); 255 | } 256 | if (!toFile.exists()){ 257 | toFile.createNewFile(); 258 | } 259 | FileOutputStream out = new FileOutputStream(toFile); 260 | byte[] b = new byte[1024]; 261 | int n = 0; 262 | while ((n = ins.read(b)) != -1) { 263 | out.write(b, 0, n); 264 | } 265 | ins.close(); 266 | out.close(); 267 | } 268 | 269 | /** 270 | * 校验文件名字、以及后缀 271 | * @param file 272 | * @return 273 | */ 274 | public static Boolean isCorrectFile(MultipartFile file) { 275 | String originalFilename = file.getOriginalFilename(); 276 | String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1); 277 | String fileName = originalFilename.substring(0, originalFilename.lastIndexOf(".")); 278 | // 判断后缀 279 | if(!(IMG_TYPE_PNG.equals(suffix.toUpperCase()) || IMG_TYPE_JPG .equals(suffix.toUpperCase()))){ 280 | return false; 281 | } 282 | // 判断文件名是否有不符合规则字符 283 | if (fileName == null || fileName.length() > 255){ 284 | return false; 285 | } 286 | // 校验文件名是否有中文,有中文就返回false,代表不符合规矩 287 | /*Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); 288 | Matcher m = p.matcher(fileName); 289 | if (m.find()) { 290 | return false; 291 | }*/ 292 | Pattern pattern = Pattern.compile("[\\s\\\\/:\\*\\?\\\"<>\\|]"); 293 | Matcher matcher = pattern.matcher(fileName); 294 | boolean matches = matcher.matches();// 是否属于违规名字 295 | return !matches; 296 | } 297 | 298 | /** 299 | * 判断文件是否存在 300 | * @param fileFullPath 301 | * @return 302 | */ 303 | public static Boolean isFileExit(String fileFullPath) { 304 | File file = new File(fileFullPath); 305 | if (file.exists() && file.isFile()){ 306 | return true; 307 | }else { 308 | return false; 309 | } 310 | } 311 | 312 | } 313 | -------------------------------------------------------------------------------- /foodmanagement/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /usr/local/etc/mavenrc ] ; then 40 | . /usr/local/etc/mavenrc 41 | fi 42 | 43 | if [ -f /etc/mavenrc ] ; then 44 | . /etc/mavenrc 45 | fi 46 | 47 | if [ -f "$HOME/.mavenrc" ] ; then 48 | . "$HOME/.mavenrc" 49 | fi 50 | 51 | fi 52 | 53 | # OS specific support. $var _must_ be set to either true or false. 54 | cygwin=false; 55 | darwin=false; 56 | mingw=false 57 | case "`uname`" in 58 | CYGWIN*) cygwin=true ;; 59 | MINGW*) mingw=true;; 60 | Darwin*) darwin=true 61 | # Use /usr/libexec/java_home if available, otherwise fall back to /foodmanagement/Java/Home 62 | # See https://developer.apple.com/foodmanagement/mac/qa/qa1170/_index.html 63 | if [ -z "$JAVA_HOME" ]; then 64 | if [ -x "/usr/libexec/java_home" ]; then 65 | export JAVA_HOME="`/usr/libexec/java_home`" 66 | else 67 | export JAVA_HOME="/foodmanagement/Java/Home" 68 | fi 69 | fi 70 | ;; 71 | esac 72 | 73 | if [ -z "$JAVA_HOME" ] ; then 74 | if [ -r /etc/gentoo-release ] ; then 75 | JAVA_HOME=`java-config --jre-home` 76 | fi 77 | fi 78 | 79 | if [ -z "$M2_HOME" ] ; then 80 | ## resolve links - $0 may be a link to maven's home 81 | PRG="$0" 82 | 83 | # need this for relative symlinks 84 | while [ -h "$PRG" ] ; do 85 | ls=`ls -ld "$PRG"` 86 | link=`expr "$ls" : '.*-> \(.*\)$'` 87 | if expr "$link" : '/.*' > /dev/null; then 88 | PRG="$link" 89 | else 90 | PRG="`dirname "$PRG"`/$link" 91 | fi 92 | done 93 | 94 | saveddir=`pwd` 95 | 96 | M2_HOME=`dirname "$PRG"`/.. 97 | 98 | # make it fully qualified 99 | M2_HOME=`cd "$M2_HOME" && pwd` 100 | 101 | cd "$saveddir" 102 | # echo Using m2 at $M2_HOME 103 | fi 104 | 105 | # For Cygwin, ensure paths are in UNIX format before anything is touched 106 | if $cygwin ; then 107 | [ -n "$M2_HOME" ] && 108 | M2_HOME=`cygpath --unix "$M2_HOME"` 109 | [ -n "$JAVA_HOME" ] && 110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 111 | [ -n "$CLASSPATH" ] && 112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 113 | fi 114 | 115 | # For Mingw, ensure paths are in UNIX format before anything is touched 116 | if $mingw ; then 117 | [ -n "$M2_HOME" ] && 118 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 119 | [ -n "$JAVA_HOME" ] && 120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 121 | fi 122 | 123 | if [ -z "$JAVA_HOME" ]; then 124 | javaExecutable="`which javac`" 125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 126 | # readlink(1) is not available as standard on Solaris 10. 127 | readLink=`which readlink` 128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 129 | if $darwin ; then 130 | javaHome="`dirname \"$javaExecutable\"`" 131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 132 | else 133 | javaExecutable="`readlink -f \"$javaExecutable\"`" 134 | fi 135 | javaHome="`dirname \"$javaExecutable\"`" 136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 137 | JAVA_HOME="$javaHome" 138 | export JAVA_HOME 139 | fi 140 | fi 141 | fi 142 | 143 | if [ -z "$JAVACMD" ] ; then 144 | if [ -n "$JAVA_HOME" ] ; then 145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 146 | # IBM's JDK on AIX uses strange locations for the executables 147 | JAVACMD="$JAVA_HOME/jre/sh/java" 148 | else 149 | JAVACMD="$JAVA_HOME/bin/java" 150 | fi 151 | else 152 | JAVACMD="`\\unset -f command; \\command -v java`" 153 | fi 154 | fi 155 | 156 | if [ ! -x "$JAVACMD" ] ; then 157 | echo "Error: JAVA_HOME is not defined correctly." >&2 158 | echo " We cannot execute $JAVACMD" >&2 159 | exit 1 160 | fi 161 | 162 | if [ -z "$JAVA_HOME" ] ; then 163 | echo "Warning: JAVA_HOME environment variable is not set." 164 | fi 165 | 166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 167 | 168 | # traverses directory structure from process work directory to filesystem root 169 | # first directory with .mvn subdirectory is considered project base directory 170 | find_maven_basedir() { 171 | 172 | if [ -z "$1" ] 173 | then 174 | echo "Path not specified to find_maven_basedir" 175 | return 1 176 | fi 177 | 178 | basedir="$1" 179 | wdir="$1" 180 | while [ "$wdir" != '/' ] ; do 181 | if [ -d "$wdir"/.mvn ] ; then 182 | basedir=$wdir 183 | break 184 | fi 185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 186 | if [ -d "${wdir}" ]; then 187 | wdir=`cd "$wdir/.."; pwd` 188 | fi 189 | # end of workaround 190 | done 191 | echo "${basedir}" 192 | } 193 | 194 | # concatenates all lines of a file 195 | concat_lines() { 196 | if [ -f "$1" ]; then 197 | echo "$(tr -s '\n' ' ' < "$1")" 198 | fi 199 | } 200 | 201 | BASE_DIR=`find_maven_basedir "$(pwd)"` 202 | if [ -z "$BASE_DIR" ]; then 203 | exit 1; 204 | fi 205 | 206 | ########################################################################################## 207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 208 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 209 | ########################################################################################## 210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Found .mvn/wrapper/maven-wrapper.jar" 213 | fi 214 | else 215 | if [ "$MVNW_VERBOSE" = true ]; then 216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 217 | fi 218 | if [ -n "$MVNW_REPOURL" ]; then 219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 220 | else 221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" 222 | fi 223 | while IFS="=" read key value; do 224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 225 | esac 226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 227 | if [ "$MVNW_VERBOSE" = true ]; then 228 | echo "Downloading from: $jarUrl" 229 | fi 230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 231 | if $cygwin; then 232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 233 | fi 234 | 235 | if command -v wget > /dev/null; then 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Found wget ... using wget" 238 | fi 239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 241 | else 242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" 243 | fi 244 | elif command -v curl > /dev/null; then 245 | if [ "$MVNW_VERBOSE" = true ]; then 246 | echo "Found curl ... using curl" 247 | fi 248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 249 | curl -o "$wrapperJarPath" "$jarUrl" -f 250 | else 251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 252 | fi 253 | 254 | else 255 | if [ "$MVNW_VERBOSE" = true ]; then 256 | echo "Falling back to using Java to download" 257 | fi 258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 259 | # For Cygwin, switch paths to Windows format before running javac 260 | if $cygwin; then 261 | javaClass=`cygpath --path --windows "$javaClass"` 262 | fi 263 | if [ -e "$javaClass" ]; then 264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 265 | if [ "$MVNW_VERBOSE" = true ]; then 266 | echo " - Compiling MavenWrapperDownloader.java ..." 267 | fi 268 | # Compiling the Java class 269 | ("$JAVA_HOME/bin/javac" "$javaClass") 270 | fi 271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 272 | # Running the downloader 273 | if [ "$MVNW_VERBOSE" = true ]; then 274 | echo " - Running MavenWrapperDownloader.java ..." 275 | fi 276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 277 | fi 278 | fi 279 | fi 280 | fi 281 | ########################################################################################## 282 | # End of extension 283 | ########################################################################################## 284 | 285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 286 | if [ "$MVNW_VERBOSE" = true ]; then 287 | echo $MAVEN_PROJECTBASEDIR 288 | fi 289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 290 | 291 | # For Cygwin, switch paths to Windows format before running java 292 | if $cygwin; then 293 | [ -n "$M2_HOME" ] && 294 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 295 | [ -n "$JAVA_HOME" ] && 296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 297 | [ -n "$CLASSPATH" ] && 298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 299 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 301 | fi 302 | 303 | # Provide a "standardized" way to retrieve the CLI args that will 304 | # work with both Windows and non-Windows executions. 305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 306 | export MAVEN_CMD_LINE_ARGS 307 | 308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 309 | 310 | exec "$JAVACMD" \ 311 | $MAVEN_OPTS \ 312 | $MAVEN_DEBUG_OPTS \ 313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 314 | "-Dmaven.home=${M2_HOME}" \ 315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 317 | -------------------------------------------------------------------------------- /foodmanagement/src/main/java/com/design/foodmanagement/util/RedisUtil.java: -------------------------------------------------------------------------------- 1 | package com.design.foodmanagement.util; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.redis.core.RedisTemplate; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.util.CollectionUtils; 8 | 9 | import java.nio.charset.Charset; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.Set; 13 | import java.util.concurrent.TimeUnit; 14 | 15 | /** 16 | * Redis工具类 17 | * 18 | * @author ZENG.XIAO.YAN 19 | * @date 2018年6月7日 20 | */ 21 | @Component 22 | public final class RedisUtil { 23 | 24 | @Autowired 25 | private RedisTemplate redisTemplate; 26 | 27 | public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); 28 | 29 | // =============================common============================ 30 | /** 31 | * 指定缓存失效时间 32 | * 33 | * @param key 键 34 | * @param time 时间(秒) 35 | * @return 36 | */ 37 | public boolean expire(String key, long time) { 38 | try { 39 | if (time > 0) { 40 | redisTemplate.expire(key, time, TimeUnit.SECONDS); 41 | } 42 | return true; 43 | } catch (Exception e) { 44 | e.printStackTrace(); 45 | return false; 46 | } 47 | } 48 | 49 | /** 50 | * 根据key 获取过期时间 51 | * 52 | * @param key 键 不能为null 53 | * @return 时间(秒) 返回0代表为永久有效 54 | */ 55 | public long getExpire(String key) { 56 | return redisTemplate.getExpire(key, TimeUnit.SECONDS); 57 | } 58 | 59 | /** 60 | * 判断key是否存在 61 | * 62 | * @param key 键 63 | * @return true 存在 false不存在 64 | */ 65 | public boolean hasKey(String key) { 66 | try { 67 | return redisTemplate.hasKey(key); 68 | } catch (Exception e) { 69 | e.printStackTrace(); 70 | return false; 71 | } 72 | } 73 | 74 | /** 75 | * 删除缓存 76 | * 77 | * @param key 可以传一个值 或多个 78 | */ 79 | @SuppressWarnings("unchecked") 80 | public void del(String... key) { 81 | if (key != null && key.length > 0) { 82 | if (key.length == 1) { 83 | redisTemplate.delete(key[0]); 84 | } else { 85 | redisTemplate.delete((List) CollectionUtils.arrayToList(key)); 86 | } 87 | } 88 | } 89 | 90 | // ============================String============================= 91 | /** 92 | * 普通缓存获取 93 | * 94 | * @param key 键 95 | * @return 值 96 | */ 97 | public Object get(String key) { 98 | return key == null ? null : redisTemplate.opsForValue().get(key); 99 | } 100 | 101 | public T get(String key,Class clazz) { 102 | String str=null; 103 | Object obj=get(key) ; 104 | if(obj instanceof String) { 105 | str=new String(obj.toString()); 106 | } 107 | 108 | //System.out.println("get="+value); 109 | if(str!=null) { 110 | try { 111 | return JSON.parseObject(str, clazz); 112 | }catch (Exception e) { 113 | // TODO: handle exception 114 | e.printStackTrace(); 115 | return null; 116 | } 117 | } 118 | return (T) obj; 119 | } 120 | 121 | 122 | 123 | /** 124 | * 普通缓存放入 125 | * 126 | * @param key 键 127 | * @param value 值 128 | * @return true成功 false失败 129 | */ 130 | public boolean set(String key, Object value) { 131 | try { 132 | 133 | redisTemplate.opsForValue().set(key, 134 | JSON.toJSONString(value)); 135 | return true; 136 | } catch (Exception e) { 137 | e.printStackTrace(); 138 | return false; 139 | } 140 | } 141 | 142 | /** 143 | * 普通缓存放入并设置时间 144 | * 145 | * @param key 键 146 | * @param value 值 147 | * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 148 | * @return true成功 false 失败 149 | */ 150 | public boolean set(String key, Object value, long time) { 151 | try { 152 | if (time > 0) { 153 | redisTemplate.opsForValue().set(key, JSON.toJSONString(value), time, TimeUnit.SECONDS); 154 | } else { 155 | set(key, value); 156 | } 157 | return true; 158 | } catch (Exception e) { 159 | e.printStackTrace(); 160 | return false; 161 | } 162 | } 163 | 164 | /** 165 | * 递增 166 | * 167 | * @param key 键 168 | * @param delta 要增加几(大于0) 169 | * @return 170 | */ 171 | public long incr(String key, long delta) { 172 | if (delta < 0) { 173 | throw new RuntimeException("递增因子必须大于0"); 174 | } 175 | return redisTemplate.opsForValue().increment(key, delta); 176 | } 177 | 178 | /** 179 | * 递减 180 | * 181 | * @param key 键 182 | * @param delta 要减少几(小于0) 183 | * @return 184 | */ 185 | public long decr(String key, long delta) { 186 | if (delta < 0) { 187 | throw new RuntimeException("递减因子必须大于0"); 188 | } 189 | return redisTemplate.opsForValue().increment(key, -delta); 190 | } 191 | 192 | // ================================Map================================= 193 | /** 194 | * HashGet 195 | * 196 | * @param key 键 不能为null 197 | * @param item 项 不能为null 198 | * @return 值 199 | */ 200 | public Object hget(String key, String item) { 201 | return redisTemplate.opsForHash().get(key, item); 202 | } 203 | 204 | /** 205 | * 获取hashKey对应的所有键值 206 | * 207 | * @param key 键 208 | * @return 对应的多个键值 209 | */ 210 | public Map hmget(String key) { 211 | return redisTemplate.opsForHash().entries(key); 212 | } 213 | 214 | /** 215 | * HashSet 216 | * 217 | * @param key 键 218 | * @param map 对应多个键值 219 | * @return true 成功 false 失败 220 | */ 221 | public boolean hmset(String key, Map map) { 222 | try { 223 | redisTemplate.opsForHash().putAll(key, map); 224 | return true; 225 | } catch (Exception e) { 226 | e.printStackTrace(); 227 | return false; 228 | } 229 | } 230 | 231 | /** 232 | * HashSet 并设置时间 233 | * 234 | * @param key 键 235 | * @param map 对应多个键值 236 | * @param time 时间(秒) 237 | * @return true成功 false失败 238 | */ 239 | public boolean hmset(String key, Map map, long time) { 240 | try { 241 | redisTemplate.opsForHash().putAll(key, map); 242 | if (time > 0) { 243 | expire(key, time); 244 | } 245 | return true; 246 | } catch (Exception e) { 247 | e.printStackTrace(); 248 | return false; 249 | } 250 | } 251 | 252 | /** 253 | * 向一张hash表中放入数据,如果不存在将创建 254 | * 255 | * @param key 键 256 | * @param item 项 257 | * @param value 值 258 | * @return true 成功 false失败 259 | */ 260 | public boolean hset(String key, String item, Object value) { 261 | try { 262 | redisTemplate.opsForHash().put(key, item, value); 263 | return true; 264 | } catch (Exception e) { 265 | e.printStackTrace(); 266 | return false; 267 | } 268 | } 269 | 270 | /** 271 | * 向一张hash表中放入数据,如果不存在将创建 272 | * 273 | * @param key 键 274 | * @param item 项 275 | * @param value 值 276 | * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 277 | * @return true 成功 false失败 278 | */ 279 | public boolean hset(String key, String item, Object value, long time) { 280 | try { 281 | redisTemplate.opsForHash().put(key, item, value); 282 | if (time > 0) { 283 | expire(key, time); 284 | } 285 | return true; 286 | } catch (Exception e) { 287 | e.printStackTrace(); 288 | return false; 289 | } 290 | } 291 | 292 | /** 293 | * 删除hash表中的值 294 | * 295 | * @param key 键 不能为null 296 | * @param item 项 可以使多个 不能为null 297 | */ 298 | public void hdel(String key, Object... item) { 299 | redisTemplate.opsForHash().delete(key, item); 300 | } 301 | 302 | /** 303 | * 判断hash表中是否有该项的值 304 | * 305 | * @param key 键 不能为null 306 | * @param item 项 不能为null 307 | * @return true 存在 false不存在 308 | */ 309 | public boolean hHasKey(String key, String item) { 310 | return redisTemplate.opsForHash().hasKey(key, item); 311 | } 312 | 313 | /** 314 | * hash递增 如果不存在,就会创建一个 并把新增后的值返回 315 | * 316 | * @param key 键 317 | * @param item 项 318 | * @param by 要增加几(大于0) 319 | * @return 320 | */ 321 | public double hincr(String key, String item, double by) { 322 | return redisTemplate.opsForHash().increment(key, item, by); 323 | } 324 | 325 | /** 326 | * hash递减 327 | * 328 | * @param key 键 329 | * @param item 项 330 | * @param by 要减少记(小于0) 331 | * @return 332 | */ 333 | public double hdecr(String key, String item, double by) { 334 | return redisTemplate.opsForHash().increment(key, item, -by); 335 | } 336 | 337 | // ============================set============================= 338 | /** 339 | * 根据key获取Set中的所有值 340 | * 341 | * @param key 键 342 | * @return 343 | */ 344 | public Set sGet(String key) { 345 | try { 346 | return redisTemplate.opsForSet().members(key); 347 | } catch (Exception e) { 348 | e.printStackTrace(); 349 | return null; 350 | } 351 | } 352 | 353 | /** 354 | * 根据value从一个set中查询,是否存在 355 | * 356 | * @param key 键 357 | * @param value 值 358 | * @return true 存在 false不存在 359 | */ 360 | public boolean sHasKey(String key, Object value) { 361 | try { 362 | return redisTemplate.opsForSet().isMember(key, value); 363 | } catch (Exception e) { 364 | e.printStackTrace(); 365 | return false; 366 | } 367 | } 368 | 369 | /** 370 | * 将数据放入set缓存 371 | * 372 | * @param key 键 373 | * @param values 值 可以是多个 374 | * @return 成功个数 375 | */ 376 | public long sSet(String key, Object... values) { 377 | try { 378 | return redisTemplate.opsForSet().add(key, values); 379 | } catch (Exception e) { 380 | e.printStackTrace(); 381 | return 0; 382 | } 383 | } 384 | 385 | /** 386 | * 将set数据放入缓存 387 | * 388 | * @param key 键 389 | * @param time 时间(秒) 390 | * @param values 值 可以是多个 391 | * @return 成功个数 392 | */ 393 | public long sSetAndTime(String key, long time, Object... values) { 394 | try { 395 | Long count = redisTemplate.opsForSet().add(key, values); 396 | if (time > 0) 397 | expire(key, time); 398 | return count; 399 | } catch (Exception e) { 400 | e.printStackTrace(); 401 | return 0; 402 | } 403 | } 404 | 405 | /** 406 | * 获取set缓存的长度 407 | * 408 | * @param key 键 409 | * @return 410 | * 411 | */ 412 | 413 | public long sGetSetSize(String key) { 414 | 415 | try { 416 | 417 | return redisTemplate.opsForSet().size(key); 418 | 419 | } catch (Exception e) { 420 | 421 | e.printStackTrace(); 422 | 423 | return 0; 424 | 425 | } 426 | 427 | } 428 | 429 | /** 430 | * 431 | * 移除值为value的 432 | * 433 | * @param key 键 434 | * 435 | * @param values 值 可以是多个 436 | * 437 | * @return 移除的个数 438 | * 439 | */ 440 | 441 | public long setRemove(String key, Object... values) { 442 | 443 | try { 444 | 445 | Long count = redisTemplate.opsForSet().remove(key, values); 446 | 447 | return count; 448 | 449 | } catch (Exception e) { 450 | 451 | e.printStackTrace(); 452 | 453 | return 0; 454 | 455 | } 456 | 457 | } 458 | 459 | // ===============================list================================= 460 | 461 | /** 462 | * 463 | * 获取list缓存的内容 464 | * 465 | * @param key 键 466 | * 467 | * @param start 开始 468 | * 469 | * @param end 结束 0 到 -1代表所有值 470 | * 471 | * @return 472 | * 473 | */ 474 | 475 | public List lGet(String key, long start, long end) { 476 | 477 | try { 478 | 479 | return redisTemplate.opsForList().range(key, start, end); 480 | 481 | } catch (Exception e) { 482 | 483 | e.printStackTrace(); 484 | 485 | return null; 486 | 487 | } 488 | 489 | } 490 | 491 | /** 492 | * 493 | * 获取list缓存的长度 494 | * 495 | * @param key 键 496 | * 497 | * @return 498 | * 499 | */ 500 | 501 | public long lGetListSize(String key) { 502 | 503 | try { 504 | 505 | return redisTemplate.opsForList().size(key); 506 | 507 | } catch (Exception e) { 508 | 509 | e.printStackTrace(); 510 | 511 | return 0; 512 | 513 | } 514 | 515 | } 516 | 517 | /** 518 | * 519 | * 通过索引 获取list中的值 520 | * 521 | * @param key 键 522 | * 523 | * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 524 | * 419 525 | * @return 526 | * 527 | */ 528 | 529 | public Object lGetIndex(String key, long index) { 530 | 531 | try { 532 | 533 | return redisTemplate.opsForList().index(key, index); 534 | 535 | } catch (Exception e) { 536 | 537 | e.printStackTrace(); 538 | 539 | return null; 540 | 541 | } 542 | 543 | } 544 | 545 | /** 546 | * 547 | * 将list放入缓存 548 | * 549 | * @param key 键 550 | * 551 | * @param value 值 552 | * 553 | * @param time 时间(秒) 554 | * 555 | * @return 556 | * 557 | */ 558 | 559 | public boolean lSet(String key, Object value) { 560 | 561 | try { 562 | 563 | redisTemplate.opsForList().rightPush(key, value); 564 | 565 | return true; 566 | 567 | } catch (Exception e) { 568 | 569 | e.printStackTrace(); 570 | 571 | return false; 572 | 573 | } 574 | 575 | } 576 | 577 | /** 578 | * 579 | * 将list放入缓存 580 | * 581 | * @param key 键 582 | * 583 | * @param value 值 584 | * 585 | * @param time 时间(秒) 586 | * 587 | * @return 588 | * 589 | */ 590 | 591 | public boolean lSet(String key, Object value, long time) { 592 | 593 | try { 594 | 595 | redisTemplate.opsForList().rightPush(key, value); 596 | 597 | if (time > 0) 598 | 599 | expire(key, time); 600 | 601 | return true; 602 | 603 | } catch (Exception e) { 604 | 605 | e.printStackTrace(); 606 | 607 | return false; 608 | 609 | } 610 | 611 | } 612 | 613 | /** 614 | * 615 | * 将list放入缓存 616 | * 617 | * @param key 键 618 | * 619 | * @param value 值 620 | * 621 | * @param time 时间(秒) 622 | * 623 | * @return 624 | * 625 | */ 626 | 627 | public boolean lSet(String key, List value) { 628 | 629 | try { 630 | 631 | redisTemplate.opsForList().rightPushAll(key, value); 632 | 633 | return true; 634 | 635 | } catch (Exception e) { 636 | 637 | e.printStackTrace(); 638 | 639 | return false; 640 | 641 | } 642 | 643 | } 644 | 645 | /** 646 | * 647 | * 将list放入缓存 648 | * 649 | * 650 | * 651 | * @param key 键 652 | * 653 | * @param value 值 654 | * 655 | * @param time 时间(秒) 656 | * 657 | * @return 658 | * 659 | */ 660 | 661 | public boolean lSet(String key, List value, long time) { 662 | 663 | try { 664 | 665 | redisTemplate.opsForList().rightPushAll(key, value); 666 | 667 | if (time > 0) 668 | 669 | expire(key, time); 670 | 671 | return true; 672 | 673 | } catch (Exception e) { 674 | 675 | e.printStackTrace(); 676 | 677 | return false; 678 | 679 | } 680 | 681 | } 682 | 683 | /** 684 | * 685 | * 根据索引修改list中的某条数据 686 | * 687 | * @param key 键 688 | * 689 | * @param index 索引 690 | * 691 | * @param value 值 692 | * 693 | * @return 694 | * 695 | */ 696 | 697 | public boolean lUpdateIndex(String key, long index, Object value) { 698 | 699 | try { 700 | 701 | redisTemplate.opsForList().set(key, index, value); 702 | 703 | return true; 704 | 705 | } catch (Exception e) { 706 | 707 | e.printStackTrace(); 708 | 709 | return false; 710 | 711 | } 712 | 713 | } 714 | 715 | /** 716 | * 717 | * 移除N个值为value 718 | * 719 | * @param key 键 720 | * 721 | * @param count 移除多少个 722 | * 723 | * @param value 值 724 | * 725 | * @return 移除的个数 726 | * 727 | */ 728 | 729 | public long lRemove(String key, long count, Object value) { 730 | 731 | try { 732 | 733 | Long remove = redisTemplate.opsForList().remove(key, count, value); 734 | 735 | return remove; 736 | 737 | } catch (Exception e) { 738 | 739 | e.printStackTrace(); 740 | 741 | return 0; 742 | 743 | } 744 | 745 | } 746 | 747 | } --------------------------------------------------------------------------------