0

web.xml

<servlet>
    <servlet-name>springMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring/*.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springMVC</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

controller

@Controller
@RequestMapping("/car/*")
public class CarController extends BaseController {

    @RequestMapping("baojia.html")
    public ModelAndView baojia() {
        ModelAndView view = new ModelAndView();
        view.setViewName("baojia");
        return view;
    }

when i visit http://mydomain/car/baojia.html and has this error:

[carloan]2016-04-21 09:01:31,177 WARN [org.springframework.web.servlet.PageNotFound] - <No mapping found for HTTP request with URI [/views/baojia.jsp] in DispatcherServlet with name 'springMVC'>

spring.xml ViewResolver

<bean id="ViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="cache" value="false"/>
    <property name="contentType" value="text/html;charset=UTF-8" />
    <property name="prefix" value="/views/"/>
    <property name="suffix" value=".jsp"/>
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
</bean>

and i have file in /views/boajia.jsp

whether i writer, it don't work

<mvc:resources mapping="/views/" location="/views/**" />

and i have another question, i wan't to matching this url-pattern: /api/* and the controller is:

@Controller
@RequestMapping("/api/*")
public class CarApiController extends BaseController {

    @RequestMapping("get")
    @ResponseBody
    public JsonResult getCars()

but it can't work

Viraj
  • 1,360
  • 3
  • 18
  • 38
EricLin
  • 21
  • 1
  • 3

2 Answers2

0

try @RequestMapping("/car") instead of @RequestMapping("/car/*")

And check below two links to understand, how request mapping defined.

can anybody explain me difference between class level controller and method level controller..?

http://duckranger.com/2012/04/advanced-requestmapping-tricks-controller-root-and-uri-templates/

Community
  • 1
  • 1
Viraj
  • 1,360
  • 3
  • 18
  • 38
0

URL mapping declaration is not proper use @RequestMapping("/car") and @RequestMapping("/baojia.html")

Dileep
  • 41
  • 4