我有这个简单的代码来获取视图中的数据,但我无法获得,也没有得到任何堆栈跟踪
@Controller
public class ControllerClass {
@Autowired
RepoisitiryClass repoisitiryClass;
@RequestMapping("testData")
public String getView(Model model) {
model.addAttribute("getData", repoisitiryClass.setData());
return "domain";
}
}
public class Domain {
private String domain;
public Domain(String domain) {
this.domain = domain;
}
public String getDomain() {
return domain;
}
}
@Repository
public class RepoisitiryClass {
private String dataDomain = "";
public RepoisitiryClass() {
System.out.println("inside Repo");
Domain domain = new Domain("this is domain");
dataDomain = domain.getDomain();
}
public String setData() {
return dataDomain;
}
}
<mvc:annotation-driven />
<context:component-scan base-package="com" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
现在,当我尝试运行网址时:http://localhost:8080/Test_path_Variable/testData
它找不到错误404页面。
无论如何都要解决这个错误,或者我做错了什么?