我对spring框架有疑问,我不确定它是日食还是罐子还是我...
我进行了组件扫描,有时在spring-mvc-demo-servlet.xml中添加软件包时有时无法工作
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema /beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="com.luis.org.springdemo.mvc" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
现在并在web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org /xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>spring-mvc-demo</display-name>
<!-- Spring MVC Configs -->
<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
这些是我的控制器,其中有些映射,有些不映射,但是最有趣的是,当我更改并使用新的类和控制器重新运行该项目时,只有旧的控制器才起作用。
@Controller
@RequestMapping("/Customer")
public class CustomerController{
@RequestMapping("/forms")
public String getForm(Model customerModel) {
customerModel.addAttribute("customer", new Customer());
return "customer-form";
}
@RequestMapping("/processForm")
public String processForm(@Valid @ModelAttribute("customer") Customer
customer, BindingResult theBindingResult) {
System.out.println("The Customer Last Name is : |" + customer.getLastName()+"|");
if(theBindingResult.hasErrors()) {
return "customer-form";
}else {
return "customer-result";
}
}
}
但是这个没有
@Controller
@RequestMapping("/osa")
public class ProductController{
@RequestMapping("/forms")
public String createAModel(Model productModel) {
productModel.addAttribute("product", new Product());
return "product-form";
}
@RequestMapping("/processForm")
public String ProcessModel(@Valid @ModelAttribute("product") Product product, BindingResult
theBindingResult){
if(theBindingResult.hasErrors()) {
return "product-form";
}else {
return "process-product";
}
}
}
答案 0 :(得分:0)
我知道那是什么...
我的Apache服务器正在适当地缓存最新信息,但没有运行任何信息。因此,我删除并再次运行即可。