导航,附件,拦截器

This commit is contained in:
2023-12-22 22:07:53 +08:00
parent cffa534f2c
commit 3bf4a8e793
19 changed files with 434 additions and 41 deletions

View File

@@ -8,7 +8,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class MyWebConfigurer implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new UserInterceptor()).addPathPatterns("/*/**").excludePathPatterns("/error","/login","/register","/findThePassword","/verifyCode","/sendActiveCode");
// registry.addInterceptor(new UserInterceptor()).addPathPatterns("/*/**").excludePathPatterns("/error","/login","/register","/findThePassword","/verifyCode","/sendActiveCode");
WebMvcConfigurer.super.addInterceptors(registry);
}
}

View File

@@ -0,0 +1,32 @@
package com.lovenav.controller;
import com.lovenav.entity.Config;
import com.lovenav.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConfigController {
@Autowired
ConfigService configService;
@RequestMapping("/updateConfig")
public String updateConfig(Config config){
if (configService.updateConfis(config)==1){
return "更新成功";
}
else {
return "更新配置失败";
}
}
@RequestMapping("/addConfig")
public String addConfig(Config config){
if (config.getName()==null||config.getValue()==null){
return "属性值不能为空";
}else {
return configService.addConfig(config);
}
}
}

View File

@@ -0,0 +1,41 @@
package com.lovenav.controller;
import com.lovenav.entity.Nav;
import com.lovenav.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class NavController {
@Autowired
NavService navService;
@RequestMapping("/updateNav")
public String updateNav(Nav nav){
if (nav==null){
return "选择更新的导航标签!";
}
return navService.updateNav(nav);
}
@RequestMapping("/addNav")
public String addNav(Nav nav){
if (nav==null){
return "添加的导航不能为空";
}
return navService.addNav(nav);
}
@RequestMapping("/deleteNav")
public String deleteNav(Nav nav){
if (nav==null){
return "删除的导航不能为空";
}
return navService.deleteNav(nav);
}
@RequestMapping("/selectAllNav")
public String selectAllNav(){
return navService.selectAllNav();
}
}

View File

@@ -0,0 +1,23 @@
package com.lovenav.controller;
import com.lovenav.entity.UrlList;
import com.lovenav.service.UrlListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UrlListController {
@Autowired
UrlListService urlListService;
//后台修改网站状态
@RequestMapping("/admin/weblist/alterUrlStatus")
public String setUrlStatus(UrlList urlList){
int result=urlListService.updateUrlStatusListById(urlList);
if (result==1){
return "修改成功";
}else {
return "修改失败";
}
}
}

View File

@@ -1,6 +1,7 @@
package com.lovenav.controller;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.entity.UrlList;
import com.lovenav.entity.User;
import com.lovenav.service.UserService;
import com.lovenav.utils.MD5Utils;
@@ -146,4 +147,5 @@ public class UserController {
}
}

View File

@@ -1,9 +1,11 @@
package com.lovenav.dao;
import com.lovenav.entity.Config;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@Repository
@Mapper
public interface ConfigDao {
int deleteByPrimaryKey(Integer id);
@@ -16,4 +18,8 @@ public interface ConfigDao {
int updateByPrimaryKeySelective(Config record);
int updateByPrimaryKey(Config record);
int updateByName(Config config);
Config selectByName(String name);
}

View File

@@ -1,38 +1,63 @@
package com.lovenav.entity;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* 配置项
* ln_config
*/
@Data
public class Config implements Serializable {
/**
* id
*/
private Integer id;
/**
* 类型
*/
private Object type;
/**
* 名称
*/
private String name;
/**
* 值
*/
private String value;
/**
* 更新时间
*/
private Date updatetime;
private Integer updatetime;
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Object getType() {
return type;
}
public void setType(Object type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Integer getUpdatetime() {
return updatetime;
}
public void setUpdatetime(Integer updatetime) {
this.updatetime = updatetime;
}
}

View File

@@ -0,0 +1,9 @@
package com.lovenav.service;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
public interface AttachmentService {
// public HashMap<String,String>storeFile(MultipartFile multipartFile);
}

View File

@@ -0,0 +1,12 @@
package com.lovenav.service;
import com.lovenav.entity.Config;
import java.util.HashMap;
public interface ConfigService {
public HashMap<String,Object>getAllConfig();
public int updateConfis(Config config);
public String addConfig(Config config);
}

View File

@@ -0,0 +1,12 @@
package com.lovenav.service;
import com.lovenav.entity.Nav;
public interface NavService {
public String deleteNav(Nav nav);
public String updateNav(Nav nav);
public String selectNav(Nav nav);
public String addNav(Nav nav);
String selectAllNav();
}

View File

@@ -10,4 +10,8 @@ public interface UrlListService {
public List<UrlList> selectUrList();
public UrlList selectUrListByInput(String input);
public UrlList selectUrlListByUrlId(Long urlId);
public int updateUrlStatusListById(UrlList urlList);
}

View File

@@ -0,0 +1,58 @@
package com.lovenav.service.serviceImpl;
import com.lovenav.service.AttachmentService;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class AttachmentServiceImpl implements AttachmentService {
// @Override
// public HashMap<String, String> storeFile(MultipartFile multipartFile) {
// HashMap<String,String> map = new HashMap<>();
// }
// File path = null;
//// try {
// path = new File(ResourceUtils.getURL("classpath:").getPath());
// File upload = new File(path.getAbsolutePath(),"static/img/");
// Date date=new Date();
//
// DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// String date1=format.format(date);
// String fileName = multipartFile.getOriginalFilename();//文件全名
// File parentDir = new File(upload.getAbsolutePath()+"/" + date1);
// System.out.println(upload.getAbsolutePath());
// System.out.println(fileName);
// map
// return
// if(!upload.exists()){
// upload.mkdirs();
// }
// if(!parentDir.exists()){
// parentDir.mkdirs();
// }
// String suffix = suffix(fileName);//文件后缀
// String relPath = "/" + yearMonth + "/" + "-" + UUID.randomUUID().toString().replaceAll("-","") + suffix;
// File fileUp = new File(upload.getAbsolutePath()+ relPath);
// file.transferTo(fileUp);
// Map<String, String> map = new HashMap();
// map.put("url", "/img" + relPath);
// log.info(relPath);
// return map;
// } catch (FileNotFoundException e) {
// throw e;
// } catch (IOException e) {
// throw e;
// }
// }
}

View File

@@ -0,0 +1,39 @@
package com.lovenav.service.serviceImpl;
import com.lovenav.dao.ConfigDao;
import com.lovenav.entity.Config;
import com.lovenav.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@Service
public class ConfigServiceImpl implements ConfigService {
@Autowired
ConfigDao configDao;
@Override
public HashMap<String, Object> getAllConfig() {
return null;
}
@Override
public int updateConfis(Config config) {
return configDao.updateByName(config);
}
@Override
public String addConfig(Config config) {
if(configDao.selectByName(config.getName())!=null){
return "该配置文件已经存在!";
}else {
int result=configDao.insertSelective(config);
if (result==1){
return "添加成功!";
}else {
return "添加失败!";
}
}
}
}

View File

@@ -0,0 +1,63 @@
package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson2.JSON;
import com.lovenav.dao.NavDao;
import com.lovenav.entity.Nav;
import com.lovenav.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class NavServiceImpl implements NavService {
@Autowired
NavDao navDao;
@Override
public String deleteNav(Nav nav) {
if (navDao.selectAlreadyExist(nav)==null) {
return "没有该记录";
}
int nav1=navDao.deleteByNavName(nav.getNavName());
if (nav1==1){
return "删除成功";
}else {
return "删除失败";
}
}
@Override
public String updateNav(Nav nav) {
if (navDao.selectAlreadyExist(nav)==null) {
return "没有该记录";
}
int result=navDao.updateByName(nav);
if (result==1){
return "更新成功";
}else {
return "更新失败";
}
}
@Override
public String selectNav(Nav nav) {
return null;
}
@Override
public String addNav(Nav nav) {
int result;
if(navDao.selectAlreadyExist(nav)!=null){
return "已经有相同名称的导航!";
}
result=navDao.insertSelective(nav);
if (result==1){
return "添加成功";
}else {
return "添加失败";
}
}
@Override
public String selectAllNav() {
return (String) JSON.toJSON(navDao.selectAllNav());
}
}

View File

@@ -60,4 +60,14 @@ public class UrlLiserServiceImpl implements UrlListService {
urlListDao.updateByPrimaryKeySelective(urlList);
return urlList;
}
@Override
public int updateUrlStatusListById(UrlList urlList) {
if (urlListDao.updateByPrimaryKey(urlList)==1){
return 1;
}else {
return 0;
}
}
}

View File

@@ -14,7 +14,7 @@ import javax.annotation.Resource;
import java.util.Date;
import java.util.regex.Pattern;
@Transactional
@Service("userService")
public class UserServiceImpl implements UserService {
@@ -72,7 +72,6 @@ public class UserServiceImpl implements UserService {
user.setUserRegistered(date);
return userDao.insert(user);
}