没有合适的资源?快使用搜索试试~ 我知道了~
首页sturts2+jpa+spring
sturts2+jpa+spring
需积分: 3 36 浏览量
更新于2023-05-30
评论
收藏 143KB DOC 举报
sturts2+jpa+springsturts2+jpa+springsturts2+jpa+springsturts2+jpa+springsturts2+jpa+springsturts2+jpa+spring
资源详情
资源评论
资源推荐

Tomcat
Install Tomcat before going forward. See Tomcat's installation guide if you have any
problem installing it.
MySql
Install and congure MySql. Create a database named "quickstart" and run the script below
to create the "Person" table. Later, on applicationContext.xml, we'll use 'root' as the user
name and password for the database, remember to replace those values with the right
ones for your database.
CREATE TABLE 'quickstart'.'Person' (
'id' INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
'rstName' VARCHAR(45) NOT NULL,
'lastName' VARCHAR(45) NOT NULL,
PRIMARY KEY('id')
)
ENGINE = InnoDB;
Get the code
Show me the code
You can just download the zipped Eclipse project , add the required dependencies to the
lib folder under the /WebContent/WEB-INF/lib folder (relative to project's root folder) and
import it into Eclipse.
The maven way
To run the project this way you will need maven installed.
1. Download the zipped project
2. Download jta jar from here .
o Note that the Download Manager may save the le to your root drive, and
it may give the le a .ZIP extension. You must rename the le to jta- 1. 1-
classes.jar.
o If a later version is available, update the version references in the next
step.
3. Install the jta jar le running:

$ mvn install:install-le -DgroupId=javax.transaction -
DartifactId=jta -Dversion=1.1 -Dpackaging=jar -Dle=c:\path\
to\jar\jta-1.1-classes.jar
4. Bear with me, we are almost there
5. cd into quickstart and run:
$ mvn jetty:run
6. Point your browser to http://localhost:8080/quickstart
7. To create an eclipse project run:
$ mvn eclipse:eclipse
or (to create web project for WTP):
mvn eclipse:eclipse -Dwtpversion=1.0
Doing it yourself
Create Eclipse project
1. Open Eclipse. Seriously, you need to open Eclipse.
2. Click File -> New -> Project. Under the "Web" folder, select "Dynamic Web Project"
and click "Next".
3. Enter the project name, "quickstart" from here on. The project will be running
inside Tomcat, so we need to create a server conguration for it.
1. Under "Target Runtime", click "New", select "Apache Tomcat 5.5" and click
next.
2. Enter Tomcat's installation directory and select an installed JRE (1.5 is
required)
4. Now you should be back to the project creation wizard, with Tomcat as your Target
Runtime. Click "Next". Select "Dynamic Web Module" and "Java" facets, and click
"Finish".
Dependencies
Your project should contain the folders "src", "build" and "WebContent". We are going to
put all the required jars under "/WebContent/WEB-INF/lib". To add les to the "lib" folder,
just copy them to ${workspace}\quickstart\WebContent\WEB-INF\lib, where ${workspace}
is the location of your Eclipse workspace folder.
In the table, the version has been removed from the JAR les, since these may change in future
milestone releases. Use whatever version is shipping with the indicated products.

JAR From License
xwork.jar Struts 2 Apache License
struts2-core.jar Struts 2
struts2-spring-plugin.jar Struts 2
ognl.jar Struts 2
freemarker.jar Struts 2
commons-logging-api.jar Struts 2
mysql-connector-java.jar MySql JDBC Driver
MySQL licensing policy
spring.jar Spring 2.0 Apache License
antlr.jar Hibernate Core LGPL
asm.jar Hibernate Core
asm-attrs.jar Hibernate Core
cglib.jar Hibernate Core
dom4j.jar Hibernate Core
jdbc2_0-stdext.jar Hibernate Core
ehcache.jar Hibernate Core
hibernate3.jar Hibernate Core
xml-apis.jar Hibernate Core
commons-collections.jar Hibernate Core
ejb3-persistence.jar Hibernate Annotations LGPL
jta.jar Hibernate Annotations
hibernate-commons-
annotations.jar
Hibernate Annotations
hibernate-annotations.jar Hibernate Annotations
hibernate-entitymanager.jar
Hibernate Entity
Manager
LGPL
javassist.jar
Hibernate Entity
Manager
jboss-archive-browsing.jar
Hibernate Entity
Manager
Right click on the project and select "Refresh" (to notify Eclipse of the jars that we just
added).
Domain
Our domain model will consist of just a simple "Person" class with a couple of elds.

1. Create a new class named "Person" (File -> New -> Class), and enter
"quickstart.model" for the package name.
2. Add the elds "id" (int), "rstName" (String), and lastName ("String") with their
setter/getter methods.
3. Mark your class with the "@Entity" annotation, and the "id" eld with the
annotations "@Id" and "@GeneratedValue".
your class will look like:
Person.java
package quickstart.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Person {
@Id
@GeneratedValue
private Integer id;
private String lastName;
private String rstName;
public String getFirstName() {
return rstName;
}
public void setFirstName(String rstName) {
this.rstName = rstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}
}
@Entity will let the provider know that this class can be persisted. @Id marks the "id" eld
as the primary key for this class. @GeneratedValue will cause the id eld to be generated
by the provider (Hibernate). Classes and elds are by default mapped to tables and
columns with the same name, see JPA's documentation for more details.
Person service.
We will now write the class that will take care of CRUD operations on "Person" objects.
1. Create a new interface (File -> New -> Interface), enter "PersonService" for the
name, and "quickstart.service" for the namespace. Set its content to:
PersonService.java
package quickstart.service;
import java.util.List;
import quickstart.model.Person;
public interface PersonService {
public List<Person> ndAll();
public void save(Person person);
public void remove(int id);
public Person nd(int id);
}
1. Create a new class (File -> New -> Class), enter "PersonServiceImpl" for the name
and "quickstart.service" for the namespace. Set its content to:
PersonServiceImpl.java
package quickstart.service;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
剩余22页未读,继续阅读














hongjintian
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
最新资源
- ARM Cortex-A(armV7)编程手册V4.0.pdf
- ABB机器人保养总结解析.ppt
- 【超详细图解】菜鸡如何理解双向链表的python代码实现
- 常用网络命令的使用 ipconfig ping ARP FTP Netstat Route Tftp Tracert Telnet nslookup
- 基于单片机控制的DC-DC变换电路
- RS-232接口电路的ESD保护.pdf
- linux下用time(NULL)函数和localtime()获取当前时间的方法
- Openstack用户使用手册.docx
- KUKA KR 30 hA,KR 60 hA机器人产品手册.pdf
- Java programming with JNI
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0