下面贴源码 Person.java package com.fei.domain;
public class Person implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 3972445346283975987L;
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
IPersonDao.java package com.fei.dao;
import com.fei.domain.Person;
public interface IPersonDao {
public Person findByName(String name);
}
PersonDaoImpl.java package com.fei.dao;
import com.fei.domain.Person;
public class PersonDaoImpl implements IPersonDao{
@Override
public Person findByName(String name) {
//模拟数据库查询
Person person=new Person();
person.setName("张三");
person.setAge(20);
return person;
}
}
IPersonService.java package com.fei.service;
import com.fei.domain.Person;
public interface IPersonService {
public Person findByName(String name);
}
PersonService.java package com.fei.service;
import com.fei.dao.IPersonDao;
import com.fei.dao.PersonDaoImpl;
import com.fei.domain.Person;
public class PersonService implements IPersonService{
private IPersonDao personDao=new PersonDaoImpl();
@Override
public Person findByName(String name) {
// TODO Auto-generated method stub
System.out.println("aaaaaaaa");
System.out.println(name);
return personDao.findByName(name);
}
}
service-config.xml <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="personService"
class="com.fei.service.PersonService" />
<bean id="serviceExporter"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="personService" />
<property name="serviceInterface"
value="com.fei.service.IPersonService" />
</bean>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/person.service">serviceExporter</prop>
</props>
</property>
</bean>
</beans>
web.xml <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name></display-name>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/service-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.service</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app> 至此,服务器看可以用web容器跑起来了,比如用tomcat |
所有评论(0)