ssm框架点击图片网页跳转中间缺失/tickert,导致网页找不到,点击导演名路径完整正常跳转,这是哪里配置出现了问题呢,有遇到过这种问题的吗
文件配置如下
controller层
package com.duing.controller;
import com.duing.service.FilmService;
import com.duing.vo.FilmDetailVo;
import com.duing.vo.FilmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class FilmController {
@Autowired
private FilmService filmService;
@RequestMapping("/filmList")
@ResponseBody
public List<FilmVo> selectAll(){
List<FilmVo> filmVos = filmService.selectAll();
return filmVos;
}
@RequestMapping("/home")
public String home(Model model){
System.out.println("接受首页请求");
List<FilmVo> filmVoList = filmService.selectAll();
model.addAttribute("filmVoList",filmVoList);
return "home";
}
// 接受请求参数
@RequestMapping("/filmInfo")
public String filmInfo(@RequestParam String filmId, Model model){
FilmDetailVo detailVo=filmService.findFilmById(filmId);
model.addAttribute("detailVo",detailVo);
return "detail";
}
}
dao层
package com.duing.dao;
import com.duing.entity.Film;
import java.util.List;
public interface FilmDao {
List<Film> getList();
Film getFilmById(String filmId);
}
跟数据库的表映射的实体类
package com.duing.entity;
import java.io.Serializable;
import java.util.Date;
// 实体类 跟数据库的表映射
public class Film implements Serializable {
private static final long serialVersionUID = -4427069375523038931L;
private long id;
private String film_id;
private String name;
private String director;
private String player;
private String type;
private String country;
private int length;
private String synopsis;
private Date play_time;
private String img_path;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFilm_id() {
return film_id;
}
public void setFilm_id(String film_id) {
this.film_id = film_id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getPlayer() {
return player;
}
public void setPlayer(String player) {
this.player = player;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getSynopsis() {
return synopsis;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public Date getPlay_time() {
return play_time;
}
public void setPlay_time(Date play_time) {
this.play_time = play_time;
}
public String getImg_path() {
return img_path;
}
public void setImg_path(String img_path) {
this.img_path = img_path;
}
}
service层
package com.duing.service.impl;
import com.duing.dao.FilmDao;
import com.duing.entity.Film;
import com.duing.service.FilmService;
import com.duing.vo.FilmDetailVo;
import com.duing.vo.FilmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class FilmServiceimpl implements FilmService {
@Autowired
private FilmDao filmDao;
@Override
public List<FilmVo> selectAll() {
List<Film> films = filmDao.getList();
System.out.println("数据库影片数量"+films.size());
List<FilmVo> result=new ArrayList<>();
for (Film film : films) {
FilmVo vo= new FilmVo();
vo.setFilmId(film.getFilm_id());
vo.setName(film.getName());
vo.setDirector(film.getDirector());
vo.setImgPath(film.getImg_path());
result.add(vo);
}
return result;
}
@Override
public FilmDetailVo findFilmById(String filmId) {
Film film = filmDao.getFilmById(filmId);
FilmDetailVo vo=new FilmDetailVo();
vo.setFilmId(filmId);
vo.setName(film.getName());
vo.setDirector(film.getDirector());
vo.setImgPath(film.getImg_path());
vo.setType(film.getType());
vo.setPlayer(film.getPlayer());
vo.setSynopsis(film.getSynopsis());
vo.setCountry(film.getCountry());
vo.setLength(film.getLength());
return vo;
}
}
service接口
package com.duing.service;
import com.duing.vo.FilmDetailVo;
import com.duing.vo.FilmVo;
import java.util.List;
public interface FilmService {
List<FilmVo> selectAll();
FilmDetailVo findFilmById(String filmId);
}
vo数据
package com.duing.vo;
import java.util.Date;
public class FilmDetailVo {
private String filmId;
private String name;
private String director;
private String player;
private String type;
private String country;
private int length;
private String synopsis;
private Date playTime;
private String imgPath;
public String getFilmId() {
return filmId;
}
public void setFilmId(String filmId) {
this.filmId = filmId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getPlayer() {
return player;
}
public void setPlayer(String player) {
this.player = player;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public String getSynopsis() {
return synopsis;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public Date getPlayTime() {
return playTime;
}
public void setPlayTime(Date playTime) {
this.playTime = playTime;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
}
package com.duing.vo;
// 视图层对象 用来展示给用户使用
public class FilmVo {
private String filmId;
private String name;
private String director;
private String imgPath;
public String getFilmId() {
return filmId;
}
public void setFilmId(String filmId) {
this.filmId = filmId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgpath) {
this.imgPath = imgpath;
}
}
mappers文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.duing.dao.FilmDao">
<select id="getList" resultType="com.duing.entity.Film">
select id , film_id,`name`,director,player,`type`,country,`length`,synopsis,play_time,img_path
from film;
</select>
<select id="getFilmById" resultType="com.duing.entity.Film">
select id , film_id,`name`,director,player,`type`,country,`length`,synopsis,play_time,img_path
from film
where film_id = #{filmId};
</select>
</mapper>
mybatis配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<mappers>
<package name="com.duing.dao"/>
</mappers>
</configuration>
spring配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
https://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<context:component-scan base-package="com.duing.service"/>
<context:property-placeholder location="classpath:druid.properties"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:/mybatis.xml"/>
<property name="mapperLocations" value="classpath:mappers/*.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="factory"/>
<property name="basePackage" value="com.duing.dao"/>
</bean>
</beans>
springmvc配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<context:component-scan base-package="com.duing.controller"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:resources mapping="/img/**" location="/img/"/>
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:annotation-driven/>
</beans>
jsp文件
<%--
Created by IntelliJ IDEA.
User: 22018
Date: 2022/7/28
Time: 15:23
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>电影详情</title>
</head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
<style type="text/css">
body {
background: #2E323B;
}
#register table tr {
height: 50px;
}
.detailed {
background: white;
border-radius: 20px;
padding-bottom: 50px;
}
</style>
<body>
<div class="container">
<div class="container detailed">
<div class="container" style="margin-top: 20px;">
<div>
<strong id="biaoti" style="font-size: 26px;">${film.name}</strong>
</div>
<img style="float: left; display: block; height: 350px; width: 250px; margin-right: 20px;"
src="${pageContext.request.contextPath}${detailVo.imgPath}"/>
<div>
<div style="padding-top: 15px;line-height: 25px;">
<p>导演: ${detailVo.director}</p>
<p>主演: ${detailVo.player}</p>
<p>类型: ${detailVo.type}</p>
<p>片长: ${detailVo.length}分钟</p>
<p>国家: ${detailVo.country}</p>
<p>剧情简介: ${detailVo.synopsis}</p>
<strong>
<a href="shopping?detailVoId=${detailVo.filmId}">购票</a>
</strong>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: 22018
Date: 2022/7/28
Time: 8:32
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Title</title>
</head>
<body>
<table bgcolor="0" align="center">
<tr>
<c:forEach items="${filmVoList}" var="film" begin="0" end="3">
<td>
<div style="width: 250px;margin: 10px">
<a href="/filmInfo?filmId=${film.filmId}">
<img src="${pageContext.request.contextPath}${film.imgPath}"
style="white: 250px;height: 380px">
</a>
<div class="piao">
<a href="fimlInfo?filmId=${film.filmId}">
<P style="color: white; top: 50px;">${film.name}</P></a>
<a href="filmInfo?filmId=${film.filmId}">
<p style="color: white; top: 50px">导演:${film.director}</p></a>
</div>
</div>
</td>
</c:forEach>
</tr>
<c:forEach items="${filmVoList}" var="film" begin="4" end="7">
<td>
<div style="width: 250px;margin: 10px">
<a href="/filmInfo?filmId=${film.filmId}">
<img src="${pageContext.request.contextPath}${film.imgPath}"
style="white: 250px;height: 380px">
</a>
<div>
<a href="fimlInfo?filmId=${film.filmId}">
<P style="color: white; top: 50px;">${film.name}</P></a>
<a href="filmInfo?filmId=${film.filmId}">
<p style="color: white; top: 50px">导演:${film.director}</p></a>
</div>
</div>
</td>
</c:forEach>
</tr>
</table>
</body>
</html>
web配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
index文件
<html>
<body>
<h2>Hello World!</h2>
<jsp:forward page="/home"/>
</body>
</html>