文章目录
- 旅游信息推荐系统
- 一、系统演示
- 二、项目介绍
- 三、系统运行界面图
- 四、系统部分功能截图
- 五、部分代码展示
- 六、底部获取源码
旅游信息推荐系统
一、系统演示
旅游信息推荐系统
二、项目介绍
数据库版本: mysql8.0
数据库可视化工具: navicat
服务器:SpringBoot自带 apache tomcat
主要技术:Java,Springboot,mybatis,mysql,jquery,html,vue
功能简介:系统分为前台跟后台两个项目
前台: 展示旅游新闻、景区信息、美食信息、旅游线路、在线留言
后台管理员: 账号管理、地区管理、景点信息管理、地方美食管理、旅游线路管理、订单信息管理、新闻管理、系统管理
普通用户:旅游线路、订单信息
三、系统运行界面图
四、系统部分功能截图
五、部分代码展示
package dao;
import com.spring.util.QueryConnection;
import net.jntoo.db.Query;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* 数据库操作类
*/
public class CommDAO {
/**
* 获取链接类
* @return
*/
static public Connection getConn()
{
return new QueryConnection().getConnect();
}
/**
* 根据sql语句查询一行数据
* @param sql
* @return
*/
public HashMap find(String sql) {
HashMap map = new HashMap();
//List<HashMap> list = new ArrayList();
try {
Statement st = getConn().createStatement();
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
//HashMap map = new HashMap();
int i = rsmd.getColumnCount();
for (int j = 1; j <= i; j++) {
if (!rsmd.getColumnName(j).equals("ID")) {
String str = rs.getString(j) == null ? "" : rs.getString(j);
if (str.equals("null")) str = "";
map.put(rsmd.getColumnName(j), str);
} else
map.put("id", rs.getString(j));
}
//list.add(map);
break;
}
rs.close();
st.close();
System.out.println(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
int code = e.getErrorCode();
String message = e.getMessage();
System.err.println("SQL execute Error:"+sql);
System.err.println("code:"+code);
System.err.println("Message:"+message);
}
return map;
}
/**
* 执行sql
* @param sql
* @return
*/
public long commOper(String sql) {
long autoInsertId = -1;
try {
Statement st = getConn().createStatement();
st.executeUpdate(sql , Statement.RETURN_GENERATED_KEYS);
ResultSet rs = st.getGeneratedKeys();
while(rs.next()){
autoInsertId = rs.getLong(1);
}
rs.close();
st.close();
System.out.println(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
int code = e.getErrorCode();
String message = e.getMessage();
System.err.println("SQL execute Error:"+sql);
System.err.println("code:"+code);
System.err.println("Message:"+message);
}
return autoInsertId;
}
/**
*
* @param sql
* @return
*/
public List<HashMap> select(String sql) {
List<HashMap> list = new ArrayList();
try {
Statement st = getConn().createStatement();
ResultSet rs = st.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
HashMap map = new HashMap();
int i = rsmd.getColumnCount();
for (int j = 1; j <= i; j++) {
if (!rsmd.getColumnName(j).equals("ID")) {
String str = rs.getString(j) == null ? "" : rs.getString(j);
if (str.equals("null")) str = "";
map.put(rsmd.getColumnName(j), str);
} else
map.put("id", rs.getString(j));
}
list.add(map);
}
rs.close();
st.close();
System.out.println(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
if (sql.equals("show tables"))
list = select("select table_name from INFORMATION_SCHEMA.tables");
else{
int code = e.getErrorCode();
String message = e.getMessage();
System.err.println("SQL execute Error:"+sql);
System.err.println("code:"+code);
System.err.println("Message:"+message);
}
//e.printStackTrace();
}
return list;
}
}
package util;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 下周远程图片类,编辑器里面的图片保存在本地
*/
public class DownloadRemoteImage {
private static final String ECODING = "UTF-8";
private static final String IMGURL_REG = "<img.*src=(.*?)[^>]*?>";
private static final String IMGSRC_REG = "(http|https):\"?(.*?)(\"|>|\\s+)";
/**
* 执行下载远程图片
* @param content
* @return
*/
public static String run(String content)
{
HttpServletRequest request = Request.getRequest();
String path = "./upload";
DownloadRemoteImage image = new DownloadRemoteImage();
List<String> imgUrl = image.getImageUrl(content);
String text = image.getImageSrc(content , imgUrl , path);
//List<String> imgSrc = image.getImageSrc(imgUrl);
//image.Download(imgSrc,path);
return text;
}
/***
* 获取ImageUrl地址
*
* @param HTML
* @return
*/
private List<String> getImageUrl(String HTML) {
Matcher matcher = Pattern.compile(IMGURL_REG).matcher(HTML);
List<String> listImgUrl = new ArrayList<String>();
while (matcher.find()) {
listImgUrl.add(matcher.group());
}
return listImgUrl;
}
/***
* 获取ImageSrc地址
*
* @param listImageUrl
* @return
*/
private String getImageSrc(String content , List<String> listImageUrl , String path) {
//List<String> listImgSrc = new ArrayList<String>();
for (String image : listImageUrl) {
Matcher matcher = Pattern.compile(IMGSRC_REG).matcher(image);
while (matcher.find()) {
String src = matcher.group().substring(0, matcher.group().length() - 1);
String newsFile = download(src , path);
if(newsFile!= null){
content = content.replace(src , newsFile);
}
}
}
return content;
}
private static long downloadIndex = 1;
/**
* 根据url 生成保存的文件名
* @param url
* @return
*/
private String getFileName( String url )
{
//URL u = new URL(url);
String ext = "png";
String filename = new Date().getTime()+downloadIndex + "."+ext;
downloadIndex++;
return filename;
}
/**
* 下载远程图片
* @param url
* @param path
* @return
*/
private String download(String url, String path) {
String result = "";
String imageName = "";
try {
if(url.indexOf("http")>=0){
imageName = getFileName( url ); //url.substring(url.lastIndexOf("/") + 1, url.length());
URL uri = new URL(url);
URLConnection conn = uri.openConnection();
conn.setRequestProperty("Referer" , url);
conn.setRequestProperty("User-Agent" , "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36");
conn.setDoInput(true);
InputStream in = conn.getInputStream();
HttpServletRequest request = Request.getRequest();
String paths = request.getSession().getServletContext().getRealPath(path);
FileOutputStream fo = new FileOutputStream(new File(paths,imageName));
byte[] buf = new byte[1024];
int length = 0;
System.out.println("开始下载:" + url);
while ((length = in.read(buf, 0, buf.length)) != -1) {
fo.write(buf, 0, length);
}
in.close();
fo.close();
System.out.println(path+"/"+imageName + "下载完成");
}
} catch (Exception e) {
System.out.println("下载失败");
return null;
}
return path+"/"+imageName;
}
}
package util;
import net.jntoo.db.Query;
import com.alibaba.fastjson.*;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 操作类
*/
public class Info {
/**
* 获取单页内容
* @param name
* @param length
* @return
*/
public static String dx(String name, int length) {
HashMap row = Query.make("dx").where("leibie" , "name").find();
if (row == null || row.get("content") == null || row.isEmpty()) {
return "";
} else {
return subStr((String) row.get("content"), length);
}
}
/**
* 格式化密码,如果要加密在这里设置
* @param password
* @return
*/
public static String formatPassword(String password)
{
return password;
}
/**
* JSON 数据编码
* @param source
* @return
*/
public static String jsonEncode(Object source)
{
return JSON.toJSONString(source);
}
public static JSONObject jsonDecode(Object source)
{
if(source == null){
return JSON.parseObject("{}");
}
return JSON.parseObject( String.valueOf( source ));
}
public static JSONArray jsonDecodeArray( Object source )
{
if(source == null){
return JSON.parseArray("[]");
}
return JSON.parseArray( String.valueOf( source ));
}
public static List objectSplit(String exp , Object str)
{
List arr = new ArrayList();
if(str == null)
{
return arr;
}
String s = String.valueOf(str);
String[] sp = s.split(exp);
return Arrays.asList(sp);
}
/**
* 获取所有子集下的id
* @param table 表名
* @param pid 父级字段
* @param value 获取的所有子集
* @return
*/
public static String getAllChild( String table , String pid , Object value)
{
List templists = Query.make(table).select();
return StringUtil.join(",",getAllChild( table , pid , value , templists));
}
public static List getAllChild( String table , String pid , Object value , List templists)
{
List $ret = null;
List<HashMap> lists = templists;
List $result = new ArrayList();
String parentid = String.valueOf(value);
$result.add(parentid);
for (HashMap child : lists){
if(child.get(pid).equals(parentid))
{
$ret = getAllChild( table , pid , child.get("id") , templists );
if($ret.size() > 0){
$result.addAll($ret);
}
}
}
return $result;
}
public static String postion(String table , String pid , String name , String value)
{
List items = new ArrayList();
String parentid = value;
do {
HashMap mp = dao.Query.make(table).find(parentid);
if(mp.isEmpty()){
break;
}
items.add(mp.get(name));
parentid = mp.get(pid).toString();
}while ( !parentid.equals("") && !parentid.equals("0") );
Collections.reverse(items);
return StringUtil.join(" ",items);
}
public static String getTreeOption(String table , String pid , String name , Object value)
{
return postion(table , pid , name , String.valueOf(value));
}
/**
* 获取两个日期相差的天数
* @param dateA
* @param dateB
* @return
*/
public static int getBetweenDayNumber(String dateA, String dateB) {
long dayNumber = 0;
//1小时=60分钟=3600秒=3600000
long mins = 60L * 1000L;
//long day= 24L * 60L * 60L * 1000L;计算天数之差
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
Date d1 = df.parse(dateA);
Date d2 = df.parse(dateB);
dayNumber = (d2.getTime() - d1.getTime()) / mins;
} catch (Exception e) {
e.printStackTrace();
}
return (int) dayNumber;
}
/**
* 获取唯一id,生成随机编号
* @return
*/
public synchronized static String getID() {
Random random = new Random();
StringBuffer ret = new StringBuffer(20);
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("MMddHHmmss", Locale.CHINA);
ret.append(format.format(date));
String rand = String.valueOf(Math.abs(random.nextInt()));
//ret.append(getDateStr());
ret.append(rand.substring(0, 4));
return ret.toString();
}
/**
* 字符串截取,先把html 标签去除
* @param source
* @param length
* @return
*/
public synchronized static String subStr(Object source, int length) {
return subStr(source , length , "...");
}
/**
* 字符串截取,先把html 标签去除
* @param source
* @param length
* @return
*/
public synchronized static String subStr(Object source, int length , String append) {
if(source == null) return "";
String str = delHTMLTag(source.toString());
if (str.length() > length) {
str = ( str.substring(0, length)) + append;
}
return str;
}
/**
* 获取当前日期时间
* @return
*/
public static String getDateStr() {
String dateString = "";
try {//yyyyMMddHHmmss
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date currentTime_1 = new Date();
dateString = formatter.format(currentTime_1);
} catch (Exception e) {
}
return dateString;
}
/**
* 获取utf8 字符串
* @param str
* @return
*/
public static String getUTFStr(String str) {
if (str == null) {
return "";
}
try {
str = new String(str.getBytes("ISO-8859-1"), "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
/**
* 删除html标签
* @param htmlStr
* @return
*/
public static String delHTMLTag(String htmlStr) {
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); //过滤script标签
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); //过滤style标签
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); //过滤html标签
return htmlStr.trim(); //返回文本字符串
}
/**
* 格式化日期
* @param date
* @param day
* @return
*/
public static String getDay(String date, int day) {
String b = date.substring(0, 10);
String c = b.substring(0, 4);
String d = b.substring(5, 7);
String f = b.substring(8, 10);
String aa = c + "/" + d + "/" + f;
String a = "";
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
GregorianCalendar grc = new GregorianCalendar();
grc.setTime(new Date(aa));
grc.add(GregorianCalendar.DAY_OF_MONTH, day);
String resu = dateFormat.format(grc.getTime());
String t[] = resu.split("-");
String sesuu = "";
for (int i = 0; i < t.length; i++) {
if (t[i].length() == 1) {
t[i] = "0" + t[i];
}
sesuu += t[i] + "-";
}
return sesuu.substring(0, 10);
}
/**
* 比较时间大小
*/
public static long compare_datetime(String DATE1, String DATE2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
return dt1.getTime()-dt2.getTime();
} catch (Exception exception) {
exception.printStackTrace();
}
return -1;
}
/**
* 格式化代码
* @param source
* @return
*/
public static String html(Object source) {
return html( source.toString());
}
/**
* 格式化字符串
* @param source
* @return
*/
public static String html(String source) {
if (source == null) {
return "";
}
String html = "";
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < source.length(); i++) {
char c = source.charAt(i);
switch (c) {
case '<':
buffer.append("<");
break;
case '>':
buffer.append(">");
break;
case '&':
buffer.append("&");
break;
case '"':
buffer.append(""");
break;
default:
buffer.append(c);
}
}
html = buffer.toString();
return html;
}
/**
* 获取jstl变量的值
* @param jstlStr
* @return
* @throws Exception
*/
public static String jstl(String jstlStr) throws Exception
{
String[] strings=jstlStr.split("\\." );
HttpServletRequest http = Request.getRequest();
Object object = http.getAttribute(strings[0] );
return makeTableParam(object , strings[1]);
}
public static String jstltable(Object obj , String param) throws Exception
{
return makeTableParam(obj , param);
}
public static String address(String add)
{
if(add == null || add.length() == 0){
return "";
}
JSONObject json = JSONObject.parseObject(add);
if(json != null && !json.isEmpty()){
return json.getString("address");
}
return "";
}
/**
* 获取images 的第一个图片
* @param str
* @return
*/
public static String images(String str)
{
if(str.indexOf(",")>=0){
String[] li = str.split(",");
return li[0];
}
return str;
}
/**
* 获取jstl标签的值
* @param obj
* @param param
* @return
* @throws Exception
*/
public static String makeTableParam(Object obj, String param) throws Exception
{
if(obj == null){
return "";
}
if(obj instanceof Map)
{
Object ret = ((Map) obj).get(param);
if(ret == null){
return "";
}
return ret.toString();
}else{
Class classType=obj.getClass();
String firstLetter=param.substring(0,1).toUpperCase()+ param.substring(1);
String getMethodName = "get"+firstLetter;
Method getMethod=classType.getMethod(getMethodName,new Class[]{});
Object value=getMethod.invoke(obj,new Object[]{});
return value.toString();
}
}
/**
* 获取url 参数
* @param name
* @return
*/
public static String get(String name) {
String value = Request.getRequest().getParameter(name);
return value == null ? "" : value;
}
/**
* 格式化日期
* @param format
* @return
*/
public static String date(String format) {
return date(format, null);
}
/**
* 根据时间戳格式化日期
* @param format
* @param time
* @return
*/
public static String date(String format, long time) {
return date(format, new Date(time * 1000));
}
/**
* 获取当前时间戳
* @return
*/
public static long time() {
return Long.valueOf(new Date().getTime() / 1000).longValue();
}
/**
* 根据日期时间格式化
* @param format
* @param time
* @return
*/
public static String date(String format, Date time) {
if (time == null) {
time = new Date();
}
SimpleDateFormat formatter = new SimpleDateFormat(format);
return formatter.format(time);
}
}