数据库、表和前端的资料都再这里
链接:https://pan.baidu.com/s/1DyZeJvIoh6IeuU7P-gmymg
提取码:n32q
CategoryDaoImpl .java
package cn.itcast.travel.dao.impl;
import cn.itcast.travel.dao.CategoryDao;
import cn.itcast.travel.domain.Category;
import cn.itcast.travel.util.JDBCUtils;
import com.alibaba.druid.util.JdbcUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;
public class CategoryDaoImpl implements CategoryDao {
private JdbcTemplate template =new JdbcTemplate(JDBCUtils.getDataSource());
//查询所有
@Override
public List<Category> findAll() {
String sql ="select * from tab_category ";
return template.query(sql,new BeanPropertyRowMapper<Category>(Category.class));
}
}
FavoriteDaoImpl .java
package cn.itcast.travel.dao.impl;
import cn.itcast.travel.dao.FavoriteDao;
import cn.itcast.travel.domain.Favorite;
import cn.itcast.travel.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.Date;
public class FavoriteDaoImpl implements FavoriteDao {
private JdbcTemplate template =new JdbcTemplate(JDBCUtils.getDataSource());
@Override
public Favorite findByRidAndUid(int rid, int uid) {
Favorite favorite = null;
try {
String sql ="select * from tab_favorite where rid =? and uid =? ";
favorite = template.queryForObject(sql, new BeanPropertyRowMapper<Favorite>(Favorite.class), rid, uid);
} catch (DataAccessException e) {
e.printStackTrace();
}
return favorite;
}
@Override
public int findCountByRid(int rid) {
String sql ="select count(*) from tab_favorite where rid =? ";
return template.queryForObject(sql,Integer.class,rid);
}
@Override
public void add(int rid, int uid) {
String sql ="insert into tab_favorite values(?,?,?)";
template.update(sql,rid,new Date(),uid);
}
}
RouteDaoImpl .java
package cn.itcast.travel.dao.impl;
import cn.itcast.travel.dao.RouteDao;
import cn.itcast.travel.domain.Route;
import cn.itcast.travel.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.ArrayList;
import java.util.List;
public class RouteDaoImpl implements RouteDao {
private JdbcTemplate template =new JdbcTemplate(JDBCUtils.getDataSource());
@Override
public int findTotalCount(int cid,String rname) {
// String sql="select count(*) from tab_route where cid=?";
//1.定义一个sql模板
String sql="select count(*) from tab_route where 1=1 ";
StringBuilder sb =new StringBuilder(sql);
List params =new ArrayList();//条件们
//2.判断参数是否有值
if (cid !=0){
sb.append(" and cid = ? ");
params.add(cid);//添加?对应的值
}
if (rname !=null && rname.length()>0 ){
sb.append(" and rname like ? ");
params.add("%"+rname+"%");
}
sql=sb.toString();
return template.queryForObject(sql,Integer.class,params.toArray());
}
@Override
public List<Route> findByPage(int cid, int start, int pageSize,String rname) {
// String sql="select * from tab_route where cid=? limit ? ,?,";
String sql =" select * from tab_route where 1 = 1 ";
StringBuilder sb =new StringBuilder(sql);
List params =new ArrayList();
if (cid !=0){
sb.append(" and cid = ? ");
params.add(cid);//添加?对应的值
}
if (rname !=null && rname.length()>0 ){
sb.append(" and rname like ? ");
params.add("%"+rname+"%");
}
sb.append(" limit ? , ? ");//分页条件
sql=sb.toString();
params.add(start);
params.add(pageSize);
return template.query(sql,new BeanPropertyRowMapper<Route>(Route.class),params.toArray());
}
@Override
public Route findOne(int rid) {
String sql ="select * from tab_route where rid= ? ";
return template.queryForObject(sql,new BeanPropertyRowMapper<Route>(Route.class),rid);
}
}
RouteImgDaoImpl .java
package cn.itcast.travel.dao.impl;
import cn.itcast.travel.dao.RouteImgDao;
import cn.itcast.travel.domain.RouteImg;
import cn.itcast.travel.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;
public class RouteImgDaoImpl implements RouteImgDao {
private JdbcTemplate template =new JdbcTemplate(JDBCUtils.getDataSource());
@Override
public List<RouteImg> findByRid(int rid) {
String sql ="select * from tab_route_img where rid = ?";
return template.query(sql,new BeanPropertyRowMapper<RouteImg>(RouteImg.class),rid);
}
}
SellerDaoImpl .java
package cn.itcast.travel.dao.impl;
import cn.itcast.travel.dao.SellerDao;
import cn.itcast.travel.domain.RouteImg;
import cn.itcast.travel.domain.Seller;
import cn.itcast.travel.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
public class SellerDaoImpl implements SellerDao {
private JdbcTemplate template =new JdbcTemplate(JDBCUtils.getDataSource());
@Override
public Seller findById(int id) {
String sql ="select * from tab_seller where sid = ?";
return template.queryForObject(sql,new BeanPropertyRowMapper<Seller>(Seller.class),id);
}
}
UserDaoImpl .java
package cn.itcast.travel.dao.impl;
import cn.itcast.travel.dao.UserDao;
import cn.itcast.travel.domain.User;
import cn.itcast.travel.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
public class UserDaoImpl implements UserDao {
private JdbcTemplate template =new JdbcTemplate(JDBCUtils.getDataSource());
@Override
public User findByUsername(String username) {
User user = null;
try {
//1.定义sql
String sql ="select * from tab_user where username =? ";
//2.执行sql
user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username);
} catch (Exception e) {
}
return user;
}
@Override
public void save(User user) {
//1.定义sql
String sql ="insert into tab_user(username,password,name,birthday,sex,telephone,email,status,code) values(?,?,?,?,?,?,?,?,?)";
//2.执行sql
template.update(sql,user.getUsername(),
user.getPassword(),
user.getName(),
user.getBirthday(),
user.getSex(),
user.getTelephone(),
user.getEmail(),
user.getStatus(),
user.getCode()
);
}
//根据激活码查询用户对象
@Override
public User findByCode(String code) {
User user = null;
try {
String sql ="select * from tab_user where code=?";
user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), code);
} catch (DataAccessException e) {
e.printStackTrace();
}
return user;
}
//修改激活码状态
@Override
public void updateStatus(User user) {
String sql ="update tab_user set status ='Y' where uid = ?";
template.update(sql,user.getUid());
}
//登陆方法
@Override
public User findByUsernameAndPassword(String username, String password) {
User user = null;
try {
String sql ="select * from tab_user where username = ? and password =?";
user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username, password);
} catch (DataAccessException e) {
e.printStackTrace();
}
return user;
}
}
CategoryDao
package cn.itcast.travel.dao;
import cn.itcast.travel.domain.Category;
import java.util.List;
public interface CategoryDao {
//查询所有
public List<Category> findAll();
}
FavoriteDao
package cn.itcast.travel.dao;
import cn.itcast.travel.domain.Favorite;
public interface FavoriteDao {
/**
* 根据rid和uid查询收藏信息
* @param rid
* @param uid
* @return
*/
public Favorite findByRidAndUid(int rid, int uid);
/**
* 根据rid 查询收藏次数
* @param rid
* @return
*/
int findCountByRid(int rid);
/**
* 添加收藏的方法
* @param rid
* @param uid
*/
void add(int rid, int uid);
}
RouteDao
package cn.itcast.travel.dao;
import cn.itcast.travel.domain.Route;
import java.util.List;
public interface RouteDao {
/**
* 根据cid查询总记录数
*/
public int findTotalCount(int cid ,String rname);
/**
* 根据cid,start,pageSize查询当前页对的数据集合
*/
public List<Route> findByPage(int cid,int start ,int pageSize,String rname);
/**
* 根据id查询
* @param rid
* @return
*/
public Route findOne(int rid);
}
RouteImgDao
package cn.itcast.travel.dao;
import cn.itcast.travel.domain.RouteImg;
import java.util.List;
public interface RouteImgDao {
/**
* 根据route的id查询图片
* @param rid
* @return
*/
public List<RouteImg> findByRid(int rid);
}
SellerDao
package cn.itcast.travel.dao;
import cn.itcast.travel.domain.Seller;
public interface SellerDao {
/**
* 根据id查询
* @param id
* @return
*/
public Seller findById(int id);
}
UserDao
package cn.itcast.travel.dao;
import cn.itcast.travel.domain.User;
public interface UserDao {
//根据用户名查询用户信息
public User findByUsername(String username);
//用户保存
public void save(User user);
//根据激活码查询用户对象
User findByCode(String code);
//修改激活码状态
void updateStatus(User user);
User findByUsernameAndPassword(String username, String password);
}
CategoryServiceImpl
package cn.itcast.travel.service.impl;
import cn.itcast.travel.dao.CategoryDao;
import cn.itcast.travel.dao.impl.CategoryDaoImpl;
import cn.itcast.travel.domain.Category;
import cn.itcast.travel.service.CategoryService;
import cn.itcast.travel.util.JedisUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Tuple;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class CategoryServiceImpl implements CategoryService {
private CategoryDao dao =new CategoryDaoImpl();
@Override
public List<Category> findAll() {
//1.从redis中查询
//1.1获取jedis客户端
Jedis jedis = JedisUtil.getJedis();
//1.2可以使用sortedset排序查询
//Set categorys = jedis.zrange("category", 0, -1);
//1.3查询sortedset中的分数(cid)和值(cname)
Set<Tuple> categorys = jedis.zrangeWithScores("category", 0, -1);
List<Category> cs =null;
//2.判断查询的集合是否为空
if (categorys == null || categorys.size() == 0){
System.out.println("数据库查询");
//3.如果为空,需要从数据库查询,在将数据存入redis中
//3.1从数据库查询
cs= dao.findAll();
//3.2将集合数据存储到redis中的category的key
for (int i = 0; i < cs.size(); i++) {
jedis.zadd("category",cs.get(i).getCid(),cs.get(i).getCname());
}
}else {
System.out.println("redis查询");
//4.如果不为空,将set的数据存入list
cs = new ArrayList<Category>();
for (Tuple tuple : categorys) {
Category category = new Category();
category.setCname(tuple.getElement());
category.setCid((int)tuple.getScore());
cs.add(category);
}
}
//4.不为空,直接返回。
return cs;
}
}
FavoriteServiceImpl
package cn.itcast.travel.service.impl;
import cn.itcast.travel.dao.FavoriteDao;
import cn.itcast.travel.dao.impl.FavoriteDaoImpl;
import cn.itcast.travel.domain.Favorite;
import cn.itcast.travel.service.FavoriteService;
import cn.itcast.travel.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
public class FavoriteServiceImpl implements FavoriteService {
private FavoriteDao dao =new FavoriteDaoImpl();
@Override
public boolean isFavorite(String rid, int uid) {
Favorite favorite = dao.findByRidAndUid(Integer.parseInt(rid), uid);
return favorite != null;//如果对象有值,则为true,反之,则为false
}
@Override
public void add(String rid, int uid) {
dao.add(Integer.parseInt(rid), uid);
}
}
RouteServiceImpl
package cn.itcast.travel.service.impl;
import cn.itcast.travel.dao.FavoriteDao;
import cn.itcast.travel.dao.RouteDao;
import cn.itcast.travel.dao.RouteImgDao;
import cn.itcast.travel.dao.SellerDao;
import cn.itcast.travel.dao.impl.FavoriteDaoImpl;
import cn.itcast.travel.dao.impl.RouteDaoImpl;
import cn.itcast.travel.dao.impl.RouteImgDaoImpl;
import cn.itcast.travel.dao.impl.SellerDaoImpl;
import cn.itcast.travel.domain.PageBean;
import cn.itcast.travel.domain.Route;
import cn.itcast.travel.domain.RouteImg;
import cn.itcast.travel.domain.Seller;
import cn.itcast.travel.service.RouteService;
import java.util.List;
public class RouteServiceImpl implements RouteService {
private RouteDao dao =new RouteDaoImpl();
private RouteImgDao routeImgDao =new RouteImgDaoImpl();
private SellerDao sellerDao =new SellerDaoImpl();
private FavoriteDao favoriteDao =new FavoriteDaoImpl();
@Override
public PageBean<Route> pageQuery(int cid, int currentPage, int pageSize,String rname) {
//封装PageBean
PageBean<Route> pb =new PageBean<Route>();
//设置当前页码
pb.setCurrentPage(currentPage);
//设置每页显示条数
pb.setPageSize(pageSize);
//设置总记录数
int totalCount = dao.findTotalCount(cid, rname);
pb.setTotalCount(totalCount);
//设置当前页显示的数据集合
int start =(currentPage-1)*pageSize; //开始的记录数
List<Route> list =dao.findByPage(cid,start,pageSize,rname);
pb.setList(list);
//设置总页数 = 总记录数/每页显示条数
int totalPage = totalCount % pageSize == 0 ? totalCount / pageSize :(totalCount / pageSize) + 1 ;
pb.setTotalPage(totalPage);
return pb;
}
@Override
public Route findOne(String rid) {
//1.根据id去route表中查询route对象
Route route = dao.findOne(Integer.parseInt(rid));
//2.根据route的id 查询图片集合信息
List<RouteImg> routeImgList = routeImgDao.findByRid(route.getRid());
//2.2将集合设置到route对象
route.setRouteImgList(routeImgList);
//3.根据route的sid 查询商家对象
Seller seller = sellerDao.findById(route.getSid());
route.setSeller(seller);
//4.查询收藏次数
int count=favoriteDao.findCountByRid(route.getRid());
route.setCount(count);
return route;
}
}
UserServiceImpl
package cn.itcast.travel.service.impl;
import cn.itcast.travel.dao.UserDao;
import cn.itcast.travel.dao.impl.UserDaoImpl;
import cn.itcast.travel.domain.User;
import cn.itcast.travel.service.UserService;
import cn.itcast.travel.util.MailUtils;
import cn.itcast.travel.util.UuidUtil;
public class UserServiceImpl implements UserService {
private UserDao dao =new UserDaoImpl();
//注册用户
@Override
public boolean regist(User user) {
//1.根据用户名查询用户对象
User u = dao.findByUsername(user.getUsername());
if (u != null){
//用户名存在,注册失败
return false;
}
//2.保存用户信息
//2.1设置激活码,唯一字符串
user.setCode(UuidUtil.getUuid());
//2.2设置激活状态
user.setStatus("N");
dao.save(user);
//3.激活邮件发送,邮件正文
StringBuilder sbd = new StringBuilder();
sbd.append(user.getName() + "
欢迎!请确认此邮件地址以激活您的账号。
");
sbd.append("您的邮箱尚未激活,请点击激活" );
MailUtils.sendMail(user.getEmail(),sbd.toString(),"激活1") ;
return true;
}
//激活用户
@Override
public boolean active(String code) {
//1.根据激活码查询用户对象
User user=dao.findByCode(code);
if (user != null){
//2.调用dao得修改激活状态得方法
dao.updateStatus(user);
return true;
}else {
return false;
}
}
//登陆方法
@Override
public User login(User user) {
return dao.findByUsernameAndPassword(user.getUsername(),user.getPassword());
}
}
CategoryService
package cn.itcast.travel.service;
import cn.itcast.travel.domain.Category;
import java.util.List;
public interface CategoryService {
public List<Category> findAll();
}
isFavorite
package cn.itcast.travel.service;
public interface FavoriteService {
/**
* 判断是否收藏
* @param rid
* @param uid
* @return
*/
public boolean isFavorite(String rid,int uid);
/**
* 添加收藏
* @param rid
* @param uid
*/
void add(String rid, int uid);
}
RouteService
package cn.itcast.travel.service;
import cn.itcast.travel.domain.PageBean;
import cn.itcast.travel.domain.Route;
//线路Service
public interface RouteService {
/**
* 根据类别进行分页查询
* @param cid
* @param currentPage
* @param pageSize
* @return
*/
public PageBean<Route> pageQuery(int cid,int currentPage,int pageSize,String rname);
/**
* 根据id查询
* @param rid
* @return
*/
Route findOne(String rid);
}
package cn.itcast.travel.util;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
/**
* 发邮件工具类
*/
public final class MailUtils {
private static final String USER = "[email protected]"; // 发件人称号,同邮箱地址
private static final String PASSWORD = "xxxxxxxx"; // 如果是qq邮箱可以使户端授权码
/**
*
* @param to 收件人邮箱
* @param text 邮件正文
* @param title 标题
*/
/* 发送验证信息的邮件 */
public static boolean sendMail(String to, String text, String title){
try {
final Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.163.com");
// 发件人的账号
props.put("[email protected]", USER);//账号
//发件人的密码
props.put("xxxxx", PASSWORD);//密码
// 构建授权信息,用于进行SMTP进行身份验证
Authenticator authenticator = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
// 用户名、密码
String userName = props.getProperty("[email protected]");//账号
String password = props.getProperty("xxxxxxxxx");//密码
return new PasswordAuthentication(userName, password);
}
};
// 使用环境属性和授权信息,创建邮件会话
Session mailSession = Session.getInstance(props, authenticator);
// 创建邮件消息
MimeMessage message = new MimeMessage(mailSession);
// 设置发件人
String username = props.getProperty("[email protected]");
InternetAddress form = new InternetAddress(username);
message.setFrom(form);
// 设置收件人
InternetAddress toAddress = new InternetAddress(to);
message.setRecipient(Message.RecipientType.TO, toAddress);
// 设置邮件标题
message.setSubject(title);
// 设置邮件的内容体
message.setContent(text, "text/html;charset=UTF-8");
// 发送邮件
Transport.send(message);
return true;
}catch (Exception e){
e.printStackTrace();
}
return false;
}
public static void main(String[] args) throws Exception { // 做测试用
MailUtils.sendMail("[email protected]","我兄弟,这是一个测试邮件,无需回复。","测试邮件");
System.out.println("发送成功");
}
}
UserService
package cn.itcast.travel.service;
import cn.itcast.travel.domain.User;
public interface UserService {
//注册用户
boolean regist(User user);
boolean active(String code);
User login(User user);
}
UserServlet
package cn.itcast.travel.web.servlet;
import cn.itcast.travel.domain.ResultInfo;
import cn.itcast.travel.domain.User;
import cn.itcast.travel.service.UserService;
import cn.itcast.travel.service.impl.UserServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.beanutils.BeanUtils;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
@WebServlet("/User/*")
public class UserServlet extends BaseServlet {
//声明UserService业务对象
private UserService service =new UserServiceImpl();
/**
* 注册功能
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void regist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//验证码校验
String check = request.getParameter("check");
//从session中获取验证码
HttpSession session = request.getSession();
String checkcode_server = (String) session.getAttribute("CHECKCODE_SERVER");
session.removeAttribute("CHECKCODE_SERVER");//保证验证码只使用一次
//比较
if (checkcode_server == null || !checkcode_server.equalsIgnoreCase(check) ){
//验证码错误
ResultInfo info =new ResultInfo();
//注册失败
info.setFlag(false);
info.setErrorMsg("验证码错误");
//将info对象序列化为json
ObjectMapper mapper =new ObjectMapper();
String json = mapper.writeValueAsString(info);
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(json);
return ;
}
//1.获取数据
Map<String, String[]> map = request.getParameterMap();
//2.封装对象
User user =new User();
try {
BeanUtils.populate(user,map);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
//3.调用service完成注册
// UserService service =new UserServiceImpl();
boolean flag =service.regist(user);
ResultInfo info =new ResultInfo();
//4.响应结果
if (flag){
//注册成功
info.setFlag(true);
}else {
//注册失败
info.setFlag(false);
info.setErrorMsg("注册失败!");
}
//将info对象序列化为json
ObjectMapper mapper =new ObjectMapper();
//String json = mapper.writeValueAsString(info);
//将json数据写回客户端
//设置content-type
// response.setContentType("application/json;charset=utf-8");
String json = super.writerValueAsString(info, response);
response.getWriter().write(json);
}
/**
* 登陆功能
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//验证码校验
String check = request.getParameter("check");
//从session中获取验证码
HttpSession session = request.getSession();
String checkcode_server = (String) session.getAttribute("CHECKCODE_SERVER");
session.removeAttribute("CHECKCODE_SERVER");//保证验证码只使用一次
//比较
if (checkcode_server == null || !checkcode_server.equalsIgnoreCase(check) ){
//验证码错误
ResultInfo info =new ResultInfo();
//注册失败
info.setFlag(false);
info.setErrorMsg("验证码错误");
//将info对象序列化为json
ObjectMapper mapper =new ObjectMapper();
String json = mapper.writeValueAsString(info);
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(json);
return ;
}
//1.获取用户名和密码
Map<String, String[]> map = request.getParameterMap();
//2.封装User对象
User user =new User();
try {
BeanUtils.populate(user,map);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
//3.调用service方法
// UserService service =new UserServiceImpl();
User u=service.login(user);
ResultInfo info =new ResultInfo();
//4.判断用户名对象是否为null
if (u == null){
//用户名或密码错误
info.setFlag(false);
info.setErrorMsg("用户名或密码错误");
}
//5.判断用户是否激活
if (u != null && !"Y".equals(u.getStatus())){
//用户尚未激活
info.setFlag(false);
info.setErrorMsg("用户尚未激活,请激活");
}
//6.判断登陆成功
if (u != null &&"Y".equals(u.getStatus())){
request.getSession().setAttribute("user",u);//登录成功标记
//登陆成功
info.setFlag(true);
}
//响应数据
//ObjectMapper mapper =new ObjectMapper();
// response.setContentType("application/json;charset=utf-8");
// mapper.writeValue(response.getOutputStream(),info);
super.writerValue(info,response);
}
/**
* 查询单个对象
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void findOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//从session中获取登陆用户
Object user = request.getSession().getAttribute("user");
//将user写回客户端
// ObjectMapper mapper =new ObjectMapper();
// response.setContentType("application/json;charset=utf-8");
// mapper.writeValue(response.getOutputStream(),user);
super.writerValue(user,response);
}
/**
* 退出功能
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void exit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.销毁session
request.getSession().invalidate();
//2.跳转登陆页面
response.sendRedirect(request.getContextPath()+"/login.html");
}
/**
* 激活功能
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void active(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.获取激活码
String code = request.getParameter("code");
if (code != null){
//2.调用service完成激活
// UserService service= new UserServiceImpl();
boolean flag=service.active(code);
//3.判断标记
String msg =null;
if (flag){
//激活成功
msg="激活成功,请登陆";
}else {
//激活失败
msg ="激活失败,请联系管理员";
}
//response.setContentType("text/html;charset=utf-8");
// response.getWriter().write(msg);
super.write(msg,response);
}
}
}
RouteServlet
package cn.itcast.travel.web.servlet;
import cn.itcast.travel.dao.RouteImgDao;
import cn.itcast.travel.domain.PageBean;
import cn.itcast.travel.domain.Route;
import cn.itcast.travel.domain.User;
import cn.itcast.travel.service.FavoriteService;
import cn.itcast.travel.service.RouteService;
import cn.itcast.travel.service.impl.FavoriteServiceImpl;
import cn.itcast.travel.service.impl.RouteServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/Route/*")
public class RouteServlet extends BaseServlet {
private RouteService service = new RouteServiceImpl();
private FavoriteService favoriteService = new FavoriteServiceImpl();
/**
* 分页查询
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void pageQuery(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.接收参数
String currentPageStr = request.getParameter("currentPage");
String pageSizeStr = request.getParameter("pageSize");
String cidStr = request.getParameter("cid");
//接受rname 线路名称
String rname = request.getParameter("rname");
if ("null".equals(rname)) {
rname = null;
}
//tomcat8以上都不用转换字节码
// rname = new String(rname.getBytes("iso-8859-1"),"utf-8");
int cid = 0;//类别id
//2.处理参数
if (cidStr != null && cidStr.length() > 0 && !"null".equals(cidStr)) {
cid = Integer.parseInt(cidStr);
}
int currentPage = 0;//当前页码,如果不传递,则默认为第一页
if (currentPageStr != null && currentPageStr.length() > 0) {
currentPage = Integer.parseInt(currentPageStr);
} else {
currentPage = 1;
}
int pageSize = 0;//每页显示条数,如果不传递,默认每页显示5条记录
if (pageSizeStr != null && pageSizeStr.length() > 0) {
pageSize = Integer.parseInt(pageSizeStr);
} else {
pageSize = 5;
}
//3.调用service查询PageBean对象
PageBean<Route> pb = service.pageQuery(cid, currentPage, pageSize, rname);
//4.将pageBean对象序列化为json,返回
writerValue(pb, response);
}
/**
* 根据id查询一个旅游线路的详细信息
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void findOne(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.接受参数id
String rid = request.getParameter("rid");
//2.调用service查询route对象
Route route = service.findOne(rid);
//3.转为json写回客户端
writerValue(route, response);
}
/**
* 判断当前登陆用户是否收藏过该线路
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void isFavorite(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.获取线路id
String rid = request.getParameter("rid");
//2.获取当前登陆的用户user
User user = (User) request.getSession().getAttribute("user");
int uid;//用户id
if (user == null) {
//用户尚未登陆
uid = 0;
} else {
//用户已经登陆
uid = user.getUid();
}
//3.调用FavoriteService查询是否收藏
boolean flag = favoriteService.isFavorite(rid, uid);
//4.写回客户端
writerValue(flag, response);
}
/**
* 添加收藏的方法
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void addFavorite(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1.获取线路id
String rid = request.getParameter("rid");
//2.获取当前登陆的用户user
User user = (User) request.getSession().getAttribute("user");
int uid;//用户id
if (user == null) {
//用户尚未登陆
return;
} else {
//用户已经登陆
uid = user.getUid();
}
//3.调用service添加
favoriteService.add(rid,uid);
}
}
BaseServlet
package cn.itcast.travel.web.servlet;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class BaseServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp){
//System.out.println("baseServlet的service方法被执行了...");
//完成方法分发
//1.获取请求路径
String uri = req.getRequestURI(); // /travel/user/add
// System.out.println("请求uri:"+uri);// /travel/user/add
//2.获取方法名称
String methodName = uri.substring(uri.lastIndexOf('/') + 1);
// System.out.println("方法名称:"+methodName);
//3.获取方法对象Method
//谁调用我?我代表谁
// System.out.println(this);//UserServlet的对象cn.itcast.travel.web.servlet.UserServlet@4903d97e
try {
//获取方法
Method method = this.getClass().getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
//4.执行方法
//暴力反射
//method.setAccessible(true);
method.invoke(this,req,resp);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
/**
* 直接将传入的对象序列化为json,并且写回客户端
* @param object
*/
public void writerValue(Object object,HttpServletResponse response) throws IOException {
//2.序列化json返回
ObjectMapper mapper =new ObjectMapper();
response.setContentType("application/json;charset=utf-8");
mapper.writeValue(response.getOutputStream(),object);
}
/**
* 将传入的对象序列化为json,返回
* @param object
* @return
*/
public String writerValueAsString(Object object,HttpServletResponse response) throws IOException {
//2.序列化json返回
ObjectMapper mapper =new ObjectMapper();
response.setContentType("application/json;charset=utf-8");
return mapper.writeValueAsString(object);
}
public void write(String s,HttpServletResponse response) throws IOException {
response.setContentType("text/html;charset=utf-8");
response.getWriter().write(s);
}
}
header.html
<!-- 头部 start -->
<script src="js/getParameter.js"></script>
<script>
$(function () {
//查询用户信息
$.get("User/findOne",{},function (data) {
//{uid:1,name:"李四"}
var msg ="欢迎回来, "+data.name;
$("#span_username").html(msg);
});
//查询分类数据
$.get("Category/findAll",{},function (data) {
//[{cid:1,cname:国内游},{},{}]
var lis ='首页 ';
//遍历数组,拼接字符串()
for (var i = 0; i <data.length ; i++) {
var li =' + data[i].cid+'">'+data[i].cname+'';
lis+=li;
}
//拼接收藏排行榜的li,收藏排行榜
lis+='收藏排行榜 ';
//将lis字符串,设置到ul的html内容中
$("#category").html(lis);
});
//给搜索按钮绑定单击事件,获取搜索输入框的内容
$("#search-button").click(function () {
var rname=$("#search_input").val();
var cid =getParameter("cid");
location.href="http://localhost:8080/route_list.html?cid="+cid+"&rname="+rname;
})
});
</script>
<header id="header">
<div class="top_banner">
<img src="images/top_banner.jpg" alt="">
</div>
<div class="shortcut">
<!-- 未登录状态 -->
<div class="login_out">
<a href="login.html">登录</a>
<a href="register.html">注册</a>
</div>
<!-- 登录状态 -->
<div class="login">
<span id="span_username"></span>
<a href="myfavorite.html" class="collection">我的收藏</a>
<a href="javascript:location.href='User/exit';">退出</a>
</div>
</div>
<div class="header_wrap">
<div class="topbar">
<div class="logo">
<a href="/"><img src="images/logo.jpg" alt=""></a>
</div>
<div class="search">
<input name="" id="search_input" type="text" placeholder="请输入路线名称" class="search_input" autocomplete="off">
<a href="javascript:;" id="search-button" class="search-button">搜索</a>
</div>
<div class="hottel">
<div class="hot_pic">
<img src="images/hot_tel.jpg" alt="">
</div>
<div class="hot_tel">
<p class="hot_time">客服热线(9:00-6:00)</p>
<p class="hot_num">400-618-9090</p>
</div>
</div>
</div>
</div>
</header>
<!-- 头部 end -->
<!-- 首页导航 -->
<div class="navitem">
<ul id="category" class="nav">
<!-- <li class="nav-active"><a href="index.html">首页</a></li>
<li><a href="route_list.html">门票</a></li>
<li><a href="route_list.html">酒店</a></li>
<li><a href="route_list.html">香港车票</a></li>
<li><a href="route_list.html">出境游</a></li>
<li><a href="route_list.html">国内游</a></li>
<li><a href="route_list.html">港澳游</a></li>
<li><a href="route_list.html">抱团定制</a></li>
<li><a href="route_list.html">全球自由行</a></li>
<li><a href="favoriterank.html">收藏排行榜</a></li> -->
</ul>
</div>
login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>黑马旅游网-登录</title>
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" type="text/css" href="css/login.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!--导入angularJS文件-->
<script src="js/angular.min.js"></script>
<!--导入jquery-->
<script src="js/jquery-3.3.1.js"></script>
<script>
$(function () {
//1.给登陆按钮绑定单击事件
$("#btn_sub").click(function () {
//2.发送ajax请求,提交表单数据
$.post("User/login", $("#loginForm").serialize(), function (data) {
//data:{flag:false,errorMsg:''}
if (data.flag) {
//登陆成功
location.href = "index.html";
} else {
//登陆失败
$("#errorMsg").html(data.errorMsg);
}
});
});
});
//3.处理响应结果
</script>
</head>
<body>
<!--引入头部-->
<div id="header"></div>
<!-- 头部 end -->
<section id="login_wrap">
<div class="fullscreen-bg" style="background: url(images/login_bg.png);height: 532px;">
</div>
<div class="login-box">
<div class="title">
<img src="images/login_logo.png" alt="">
<span>欢迎登录黑马旅游账户</span>
</div>
<div class="login_inner">
<!--登录错误提示消息-->
<div id="errorMsg" class="alert alert-danger" ></div>
<form id="loginForm" action="" method="post" accept-charset="utf-8">
<input type="hidden" name="action" value="login"/>
<input name="username" type="text" placeholder="请输入账号" autocomplete="off">
<input name="password" type="text" placeholder="请输入密码" autocomplete="off">
<div class="verify">
<input name="check" id="check" class="check" type="text" placeholder="请输入验证码" autocomplete="off">
<span><img src="checkCode" alt="" onclick="changeCheckCode(this)"></span>
<script type="text/javascript">
//图片点击事件
function changeCheckCode(img) {
img.src="checkCode?"+new Date().getTime();
}
</script>
</div>
<div class="submit_btn">
<button type="button" id="btn_sub">登录</button>
<div class="auto_login">
<input type="checkbox" name="" class="checkbox">
<span>自动登录</span>
</div>
</div>
</form>
<div class="reg">没有账户?<a href="javascript:;">立即注册</a></div>
</div>
</div>
</section>
<!--引入尾部-->
<div id="footer"></div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-1.11.0.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!--导入布局js,共享header和footer-->
<script type="text/javascript" src="js/include.js"></script>
</body>
</html>
register.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>注册</title>
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" href="css/register.css">
<!--导入jquery-->
<script src="js/jquery-3.3.1.js"></script>
<script>
/*
表单得校验:
1.用户名:单词字符,长度8到20位
2.密码:单词字符,长度8到20位
3.email:邮件格式
4.姓名:非空
5.手机号:手机格式
6.出生日期:非空
7.验证码:非空
*/
//校验用户名
//单词字符,长度8到20位
function checkUsername() {
//1.获取用户名的值
var username = $("username").val();
//2.定义正则表达式
var reg_username=/^\w{8,20}$/;
//3.判断,给出提示信息
var flag = reg_username.test(username);
if (flag){
//用户名合法
$("#username").css("border","");
}else {
//用户名非法,加一个红色边框
$("#username").css("border","1px solid red");
}
return flag;
}
//校验密码
function checkPassword() {
//1.获取用户名的值
var password = $("password").val();
//2.定义正则表达式
var reg_password=/^\w{8,20}$/;
//3.判断,给出提示信息
var flag = reg_password.test(password);
if (flag){
//用户名合法
$("#password").css("border","");
}else {
//用户名非法,加一个红色边框
$("#password").css("border","1px solid red");
}
return flag;
}
//校验邮箱
function checkEmail(){
//1.获取邮箱
var email = $("#email").val();
//2.定义正则 [email protected]
var reg_email = /^\w+@\w+\.\w+$/;
//3.判断
var flag = reg_email.test(email);
if(flag){
$("#email").css("border","");
}else{
$("#email").css("border","1px solid red");
}
return flag;
}
//
//姓名校验
function checkName(){
//1.获取数据
var name = $("name").val();
//2.正则表达式
var reg_name =/^\w{8,20}$/;
//3.判断
var flag = reg_name.test(name);
if (flag){
//合法
$("#name").css("border","")
}else {
//不合法
$("#name").css("border","1px solid red")
}
return flag;
}
// //手机号码校验
// function checkTelephone(){
// //1.获取数据
// var telephone = $("telephone").val();
// //2.正则表达式
// var reg_telephone =/^1(3|4|5|6|7|8|9)\d{9}$/;
// //3.判断
// var flag = reg_telephone.test(telephone);
// if (flag){
// //合法
// $("#telephone").css("border","")
// }else {
// //不合法
// $("#telephone").css("border","1px solid red")
// }
// return flag;
// }
//
//
// //出生校验
// function checkBirthday(){
// //1.获取数据
// var birthday = $("birthday").val();
// //2.正则表达式
// var reg_birthday =/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
// //3.判断
// var flag = reg_birthday.test(birthday);
// if (flag){
// //合法
// $("#birthday").css("border","")
// }else {
// //不合法
// $("#birthday").css("border","1px solid red")
// }
// return flag;
// }
//
// //验证码校验
// function checkCheck(){
// //1.获取数据
// var check = $("check").val();
// //2.正则表达式
// var reg_check =/^\d{4}$/;
// //3.判断
// var flag = reg_check.test(check);
// if (flag){
// //邮箱合法
// $("#check").css("border","")
// }else {
// //邮箱不合法
// $("#check").css("border","1px solid red")
// }
// return flag;
// }
$(function () {
//当表单提交时,调用所有的校验方法
$("#registerForm").submit(function () {
//1.发送数据到服务器
if (checkUsername() && checkPassword() && checkEmail() &&checkName()
// &&checkTelephone() &&checkBirthday() &&checkCheck()
) {
//校验通过,发送ajax请求,提交表单数据 username=zhangsan&password=123
$.post("User/regist",$(this).serialize(),function (data) {
//处理服务器响应的数据 data{flag:true,errorMsg:"注册失败"}
if (data.flag){
//注册成功,跳转成功页面
location.href="register_ok.html";
} else {
//注册失败,给errorMsg添加提示信息
$("#errorMsg").html(data.errorMsg);
}
});
}
//2.跳转页面
return false;
//如果这个方法没有返回值,或者返回为true,则表单提交,如果返回为false,则表单不提交
});
//当某一个组件失去焦点时,调用对应的校验方法
$("#username").blur(checkUsername);
$("#password").blur(checkPassword);
$("#email").blur(checkEmail);
$("#name").blur(checkName);
// $("#telephone").blur(checkTelephone);
// $("#birthday").blur(checkBirthday);
// $("#check").blur(checkCheck);
});
</script>
</head>
<body>
<!--引入头部-->
<div id="header"></div>
<!-- 头部 end -->
<div class="rg_layout">
<div class="rg_form clearfix">
<div class="rg_form_left">
<p>新用户注册</p>
<p>USER REGISTER</p>
</div>
<div class="rg_form_center">
<div id="errorMsg" style="color: red; text-align: center"></div>
<!--注册表单-->
<form id="registerForm" action="user">
<!--提交处理请求的标识符-->
<input type="hidden" name="action" value="register">
<table style="margin-top: 25px;">
<tr>
<td class="td_left">
<label for="username">用户名</label>
</td>
<td class="td_right">
<input type="text" id="username" name="username" placeholder="请输入账号">
</td>
</tr>
<tr>
<td class="td_left">
<label for="password">密码</label>
</td>
<td class="td_right">
<input type="text" id="password" name="password" placeholder="请输入密码">
</td>
</tr>
<tr>
<td class="td_left">
<label for="email">Email</label>
</td>
<td class="td_right">
<input type="text" id="email" name="email" placeholder="请输入Email">
</td>
</tr>
<tr>
<td class="td_left">
<label for="name">姓名</label>
</td>
<td class="td_right">
<input type="text" id="name" name="name" placeholder="请输入真实姓名">
</td>
</tr>
<tr>
<td class="td_left">
<label for="telephone">手机号</label>
</td>
<td class="td_right">
<input type="text" id="telephone" name="telephone" placeholder="请输入您的手机号">
</td>
</tr>
<tr>
<td class="td_left">
<label for="sex">性别</label>
</td>
<td class="td_right gender">
<input type="radio" id="sex" name="sex" value="男" checked> 男
<input type="radio" name="sex" value="女"> 女
</td>
</tr>
<tr>
<td class="td_left">
<label for="birthday">出生日期</label>
</td>
<td class="td_right">
<input type="date" id="birthday" name="birthday" placeholder="年/月/日">
</td>
</tr>
<tr>
<td class="td_left">
<label for="check">验证码</label>
</td>
<td class="td_right check">
<input type="text" id="check" name="check" class="check">
<img src="checkCode" height="32px" alt="" onclick="changeCheckCode(this)">
<script type="text/javascript">
//图片点击事件
function changeCheckCode(img) {
img.src="checkCode?"+new Date().getTime();
}
</script>
</td>
</tr>
<tr>
<td class="td_left">
</td>
<td class="td_right check">
<input type="submit" class="submit" value="注册">
<span id="msg" style="color: red;"></span>
</td>
</tr>
</table>
</form>
</div>
<div class="rg_form_right">
<p>
已有账号?
<a href="#">立即登录</a>
</p>
</div>
</div>
</div>
<!--引入尾部-->
<div id="footer"></div>
<!--导入布局js,共享header和footer-->
<script type="text/javascript" src="js/include.js"></script>
</body>
</html>
route_detail.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>路线详情</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" type="text/css" href="css/route-detail.css">
</head>
<body>
<!--引入头部-->
<div id="header"></div>
<!-- 详情 start -->
<div class="wrap">
<div class="bread_box">
<a href="/">首页</a>
<span> ></span>
<a href="#">国内游</a><span> ></span>
<a href="#">全国-曼谷6-7天自由行 泰国出境旅游 特价往返机票自由行二次确认</a>
</div>
<div class="prosum_box">
<dl class="prosum_left">
<dt>
<img alt="" class="big_img" src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m49788843d72171643297ccc033d9288ee.jpg">
</dt>
<dd id="dd">
<a class="up_img up_img_disable"></a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m40920d0669855e745d97f9ad1df966ebb.jpg">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m20920d0669855e745d97f9ad1df966ebb.jpg">
</a>
<a title="" class="little_img cur_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m49788843d72171643297ccc033d9288ee.jpg">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m29788843d72171643297ccc033d9288ee.jpg">
</a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m4531a8dbceefa2c44e6d0e35627cd2689.jpg">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m2531a8dbceefa2c44e6d0e35627cd2689.jpg">
</a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m46d8cb900e9f6c0a762aca19eae40c00c.jpg">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m26d8cb900e9f6c0a762aca19eae40c00c.jpg">
</a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m45ea00f6eba562a767b5095bbf8cffe07.jpg" style="display:none;">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m25ea00f6eba562a767b5095bbf8cffe07.jpg">
</a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m4265ec488cd1bc7ce749bc8c9b34b87bc.jpg" style="display:none;">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m2265ec488cd1bc7ce749bc8c9b34b87bc.jpg">
</a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m4e7e964909d7dd1a9f6e5494d4dc0c847.jpg" style="display:none;">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m2e7e964909d7dd1a9f6e5494d4dc0c847.jpg">
</a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m467db00e1b76718fab0fe8b96e10f4d35.jpg" style="display:none;">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m267db00e1b76718fab0fe8b96e10f4d35.jpg">
</a>
<a title="" class="little_img" data-bigpic="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size4/201703/m487bbbc6e43eba6aa6a36cc1a182f7a20.jpg" style="display:none;">
<img src="http://www.jinmalvyou.com/Public/uploads/goods_img/img_size2/201703/m287bbbc6e43eba6aa6a36cc1a182f7a20.jpg">
</a>
<a class="down_img down_img_disable" style="margin-bottom: 0;"></a>
</dd>
</dl>
<div class="prosum_right">
<p class="pros_title" id="rname">【尾单特卖】全国-曼谷6-7天自由行 泰国出境旅游 特价往返机票自由行二次确认</p>
<p class="hot" id="routeIntroduce">1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
<div class="pros_other">
<p >经营商家 :<span id="sname"></span>黑马国旅</p>
<p >咨询电话 : <span id="consphone"></span>400-618-9090</p>
<p >地址 : <span id="address"></span>传智播客黑马程序员</p>
</div>
<div class="pros_price">
<p class="price"><strong id="price">¥2699.00</strong><span>起</span></p>
<p class="collect">
<a class="btn" id="favorite" onclick="addFavorite();"><i class="glyphicon glyphicon-heart-empty"></i>点击收藏</a>
<!-- <a class="btn already" disabled="disabled"><i class="glyphicon glyphicon-heart-empty"></i>点击收藏</a>-->
<span id="favoriteCount">已收藏100次</span>
</p>
</div>
</div>
</div>
<div class="you_need_konw">
<span>旅游须知</span>
<div class="notice">
<p>1、旅行社已投保旅行社责任险。建议游客购买旅游意外保险 <br>
<p>2、旅游者参加打猎、潜水、海边游泳、漂流、滑水、滑雪、滑草、蹦极、跳伞、滑翔、乘热气球、骑马、赛车、攀岩、水疗、水上飞机等属于高风险性游乐项目的,敬请旅游者务必在参加前充分了解项目的安全须知并确保身体状况能适应此类活动;如旅游者不具备较好的身体条件及技能,可能会造成身体伤害。</p>
<p>3、参加出海活动时,请务必穿着救生设备。参加水上活动应注意自己的身体状况,有心脏病、冠心病、高血压、感冒、发烧和饮酒及餐后不可以参加水上活动及潜水。在海里活动时,严禁触摸海洋中各种鱼类,水母,海胆,珊瑚等海洋生物,避免被其蛰伤。老人和小孩必须有成年人陪同才能参加合适的水上活动。在海边游玩时,注意保管好随身携带的贵重物品。</p>
<p>4、根据中国海关总署的规定,旅客在境外购买的物品,在进入中国海关时可能需要征收关税。详细内容见《中华人民共和国海关总署公告2010年第54号文件》。</p>
<p>5、建议出发时行李托运,贵重物品、常用物品、常用药品、御寒衣物等请随身携带,尽量不要托运。行李延误属于不可抗力因素,我司将全力协助客人跟进后续工作,但我司对此不承担任何责任。</p>
<p>1、旅行社已投保旅行社责任险。建议游客购买旅游意外保险 <br>
<p>2、旅游者参加打猎、潜水、海边游泳、漂流、滑水、滑雪、滑草、蹦极、跳伞、滑翔、乘热气球、骑马、赛车、攀岩、水疗、水上飞机等属于高风险性游乐项目的,敬请旅游者务必在参加前充分了解项目的安全须知并确保身体状况能适应此类活动;如旅游者不具备较好的身体条件及技能,可能会造成身体伤害。</p>
<p>3、参加出海活动时,请务必穿着救生设备。参加水上活动应注意自己的身体状况,有心脏病、冠心病、高血压、感冒、发烧和饮酒及餐后不可以参加水上活动及潜水。在海里活动时,严禁触摸海洋中各种鱼类,水母,海胆,珊瑚等海洋生物,避免被其蛰伤。老人和小孩必须有成年人陪同才能参加合适的水上活动。在海边游玩时,注意保管好随身携带的贵重物品。</p>
<p>4、根据中国海关总署的规定,旅客在境外购买的物品,在进入中国海关时可能需要征收关税。详细内容见《中华人民共和国海关总署公告2010年第54号文件》。</p>
<p>5、建议出发时行李托运,贵重物品、常用物品、常用药品、御寒衣物等请随身携带,尽量不要托运。行李延误属于不可抗力因素,我司将全力协助客人跟进后续工作,但我司对此不承担任何责任。</p>
</div>
</div>
</div>
<!-- 详情 end -->
<!--引入头部-->
<div id="footer"></div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-3.3.1.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!--导入布局js,共享header和footer-->
<script type="text/javascript" src="js/include.js"></script>
<script src="js/getParameter.js"></script>
<script>
$(document).ready(function() {
//自动播放
goImg();
// var timer = setInterval("auto_play()", 5000);
});
function goImg() {
//焦点图效果
//点击图片切换图片
$('.little_img').on('mousemove', function() {
$('.little_img').removeClass('cur_img');
var big_pic = $(this).data('bigpic');
$('.big_img').attr('src', big_pic);
$(this).addClass('cur_img');
});
//上下切换
var picindex = 0;
var nextindex = 4;
$('.down_img').on('click',function(){
var num = $('.little_img').length;
if((nextindex + 1) <= num){
$('.little_img:eq('+picindex+')').hide();
$('.little_img:eq('+nextindex+')').show();
picindex = picindex + 1;
nextindex = nextindex + 1;
}
});
$('.up_img').on('click',function(){
var num = $('.little_img').length;
if(picindex > 0){
$('.little_img:eq('+(nextindex-1)+')').hide();
$('.little_img:eq('+(picindex-1)+')').show();
picindex = picindex - 1;
nextindex = nextindex - 1;
}
});
}
//自动轮播方法
function auto_play() {
var cur_index = $('.prosum_left dd').find('a.cur_img').index();
cur_index = cur_index - 1;
var num = $('.little_img').length;
var max_index = 3;
if ((num - 1) < 3) {
max_index = num - 1;
}
if (cur_index < max_index) {
var next_index = cur_index + 1;
var big_pic = $('.little_img:eq(' + next_index + ')').data('bigpic');
$('.little_img').removeClass('cur_img');
$('.little_img:eq(' + next_index + ')').addClass('cur_img');
$('.big_img').attr('src', big_pic);
} else {
var big_pic = $('.little_img:eq(0)').data('bigpic');
$('.little_img').removeClass('cur_img');
$('.little_img:eq(0)').addClass('cur_img');
$('.big_img').attr('src', big_pic);
}
}
$(function () {
//1.获取rid
var rid =getParameter("rid");
//2.发送请求 Route/findOne
$.get("Route/findOne",{rid:rid},function (route) {
//3.解析数据填充html
$("#rname").html(route.rname);
$("#routeIntroduce").html(route.routeIntroduce);
$("#price").html("¥"+route.price);
$("#sname").html(route.seller.sname);
$("#consphone").html(route.seller.consphone);
$("#address").html(route.seller.address);
//设置收藏次数
$("#favoriteCount").html("已收藏"+route.count+"次");
//图片展示
var ddstr = '';
//遍历routeImgList
for (var i = 0; i < route.routeImgList.length; i++) {
var astr;
if (i >= 4){
astr=' +route.routeImgList[i].bigPic+'" style="display:none;" >\n' +
'+route.routeImgList[i].smallPic+'">\n' +
'';
}else {
astr=' +route.routeImgList[i].bigPic+'" >\n' +
'+route.routeImgList[i].smallPic+'">\n' +
'';
}
ddstr+=astr;
}
ddstr+='';
$("#dd").html(ddstr);
//图片的展示和切换代码的调用]
goImg();
});
});
$(function () {
//发送请求,判断用户是否收藏过该线路
var rid =getParameter("rid");
$.get("Route/isFavorite",{rid:rid},function (flag) {
if (flag){
//用户已经收藏过
//设置收藏按钮的样式
$("#favorite").addClass("already");
$("#favorite").attr("disabled","disabled");
//删除按钮的点击事件
$("#favorite").removeAttr("onclick");
}else {
//用户没有收藏
}
});
});
// 点击收藏按钮触发的方法
function addFavorite() {
var rid = getParameter("rid");
//1.判断用户是否登陆
$.get("User/findOne",{},function (user) {
if (user) {
//用户登陆了
//添加的功能
$.get("Route/addFavorite",{rid:rid},function () {
//代码刷新页面
location.reload();
});
}else {
//用户没有登陆
alert("您尚未登陆,请登录");
location.href="http://localhost:8080/login.html";
}
});
}
</script>
</body>
</html>
route_list.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>黑马旅游-搜索</title>
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" href="css/search.css">
<script src="js/jquery-3.3.1.js"></script>
<script src="js/getParameter.js"></script>
<script>
$(function () {
// var search =location.search;
// //alert(search);//?id=5
// //切割字符串,拿到第二个值
// var cid = search.split("=")[1];
//获取cid参数值
var cid=getParameter("cid");
//获取rname的参数值
var rname=getParameter("rname");
//判断rname如果不为null或者""
if (rname){
//url解码
rname=window.decodeURIComponent(rname);
}
//当页码加载完成后,调用load方法,发送ajax请求加载数据
load(cid,null,rname);
});
function load(cid,currentPage,rname) {
//发送ajax请求,请求route/pageQuery,传递cid
$.get("Route/pageQuery",{cid:cid,currentPage:currentPage,rname:rname},function (pb) {
//解析pagebean数据,将其展示页面上
//1.分页工具条数据展示
//1.1展示一下总页码和总记录数
$("#totalPage").html(pb.totalPage);
$("#totalCount").html(pb.totalCount);
var lis ="";
var fristPage ='+cid+',1,\''+rname+'\')">首页 ';
//计算上一页的页码
var beforeNum=pb.currentPage -1;
if (beforeNum <= 0) {
beforeNum =1;
}
var beforePage='+cid+','+beforeNum+',\''+rname+'\')")" class="threeword">上一页 ';
lis +=fristPage;
lis +=beforePage;
//1.2展示分页页码
/*
1.一共展示10个页码,能够达到前5后4的效果
2.如果前边不够5个,后边补齐10个
3.如果后边不足4个,前边补齐10个
*/
//定义开始位置begin,结束位置end
var begin;//开始位置
var end;//结束位置
//要显示10个页码
if (pb.totalPage <10){
//总的页码不够10页
begin =1;
end =pb.totalPage;
}else {
//总的页码超过10页
begin=pb.currentPage -5;
end =pb.currentPage +4;
//2.如果前边不够5个,后边补齐10个
if (begin < 1) {
begin =1;
end =begin+9;
}
//3.后边不够4个,前边补齐10个
if (end > pb.totalPage){
end=pb.totalPage;
begin=end-9;
}
}
for (var i = begin; i <=end ; i++) {
var li;
if (pb.currentPage == i){
//判断当前页码是否等于i
li ='+cid+','+i+',\''+rname+'\')">'+i+' ';
}else {
//创建页码的li
li ='+cid+','+i+',\''+rname+'\')">'+i+' ';
}
//拼接字符串
lis +=li;
}
/*for (var i = 1; i <= pb.totalPage; i++) {
var li;
if (pb.currentPage == i){
//判断当前页码是否等于i
li =''+i+' ';
}else {
//创建页码的li
li =''+i+' ';
}
//拼接字符串
lis +=li;
}*/
var nextNum =pb.currentPage +1;
if (nextNum >= pb.totalPage) {
nextNum =pb.totalPage;
}
var nextPage='+cid+','+nextNum+',\''+rname+'\')" class="threeword">下一页 ';
var lastPage ='+cid+','+pb.totalPage+',\''+rname+'\')">末页 ';
lis += nextPage;
lis +=lastPage;
//将lis内容设置到ul中
$("#pageNum").html(lis);
//2.列表数据展示
var route_lis="";
for (var i = 0; i <pb.list.length ; i++) {
//获取{rid:1,rname:"xxx"}
var route =pb.list[i];
var li ='\n' +
' +route.rimage+'" style="width: 299px;">\n' +
' \n' +
' '
+route.rname+'\n' +
'
\n' +
' '
+route.routeIntroduce+'\n' +
' \n' +
' \n' +
'';
route_lis +=li;
}
$("#route").html(route_lis);
//定位到页面的顶部
window.scrollTo(0,0);
});
}
</script>
</head>
<body>
<!--引入头部-->
<div id="header"></div>
<div class="page_one">
<div class="contant">
<div class="crumbs">
<img src="images/search.png" alt="">
<p>黑马旅行><span>搜索结果</span></p>
</div>
<div class="xinxi clearfix">
<div class="left">
<div class="header">
<span>商品信息</span>
<span class="jg">价格</span>
</div>
<ul id="route">
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>【减100元 含除夕/春节出发】广州增城三英温泉度假酒店/自由行套票</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>299</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>浪花朵朵旅行普吉岛丛林飞跃空中飞人探险游中文服务泰国旅游</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>899</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>黑妞皇家旅行普吉岛攀牙湾大船星光之旅皮划艇日落休闲特色体验</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>999</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>浪花朵朵旅行普吉岛皇帝岛珊瑚岛香蕉船拖拽伞水上项目</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>99</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>环游记 泰国清迈Lila massage女子监狱spa 丽菈泰式按摩马杀鸡</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>199</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>【减100元 含除夕/春节出发】广州增城三英温泉度假酒店/自由行套票</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>899</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>【减100元 含除夕/春节出发】广州增城三英温泉度假酒店/自由行套票</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>1199</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
<li>
<div class="img"><img src="images/04-search_03.jpg" alt=""></div>
<div class="text1">
<p>泰国芭提雅三合一日游芭提雅蒂芬妮人妖秀成人门票bigeye含接送</p>
<br/>
<p>1-2月出发,网付立享¥1099/2人起!爆款位置有限,抢完即止!</p>
</div>
<div class="price">
<p class="price_num">
<span>¥</span>
<span>1589</span>
<span>起</span>
</p>
<p><a href="route_detail.html">查看详情</a></p>
</div>
</li>
</ul>
<div class="page_num_inf">
<i></i> 共
<span id="totalPage">12</span>页<span id="totalCount">132</span>条
</div>
<div class="pageNum">
<ul id="pageNum">
<li><a href="">首页</a></li>
<li class="threeword"><a href="#">上一页</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">6</a></li>
<li><a href="#">7</a></li>
<li><a href="#">8</a></li>
<li><a href="#">9</a></li>
<li><a href="#">10</a></li>
<li class="threeword"><a href="javascript:;">下一页</a></li>
<li class="threeword"><a href="javascript:;">末页</a></li>
</ul>
</div>
</div>
<div class="right">
<div class="top">
<div class="hot">HOT</div>
<span>热门推荐</span>
</div>
<ul>
<li>
<div class="left"><img src="images/04-search_09.jpg" alt=""></div>
<div class="right">
<p>清远新银盏温泉度假村酒店/自由行套...</p>
<p>网付价<span>¥<span>899</span>起</span>
</p>
</div>
</li>
<li>
<div class="left"><img src="images/04-search_09.jpg" alt=""></div>
<div class="right">
<p>清远新银盏温泉度假村酒店/自由行套...</p>
<p>网付价<span>¥<span>899</span>起</span>
</p>
</div>
</li>
<li>
<div class="left"><img src="images/04-search_09.jpg" alt=""></div>
<div class="right">
<p>清远新银盏温泉度假村酒店/自由行套...</p>
<p>网付价<span>¥<span>899</span>起</span>
</p>
</div>
</li>
<li>
<div class="left"><img src="images/04-search_09.jpg" alt=""></div>
<div class="right">
<p>清远新银盏温泉度假村酒店/自由行套...</p>
<p>网付价<span>¥<span>899</span>起</span>
</p>
</div>
</li>
<li>
<div class="left"><img src="images/04-search_09.jpg" alt=""></div>
<div class="right">
<p>清远新银盏温泉度假村酒店/自由行套...</p>
<p>网付价<span>¥<span>899</span>起</span>
</p>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<!--引入头部-->
<div id="footer"></div>
<!--导入布局js,共享header和footer-->
<script type="text/javascript" src="js/include.js"></script>
</body>
</html>