1.准备环境
当然jdk要先安装好
1)下载maven,配置环境变量MAVEN_HOME,之为maven所在路径,配置PATH,添加%MAVEN_HOME%\bin;
2)ecipse 安装maven 插件,安装完成后,重启eclipse,配置maven,如下图
配置仓库,我这里配的是全局的settings.xml,也可以配置局部的,详细的maven配置,这里不详细说了,分享一个博客,感觉说的蛮详细
http://www.cnblogs.com/fangjins/archive/2012/05/06/2485459.html
3)eclipse安装jetty插件
环境准备完毕后,开始进入项目开发
2.web项目开发
1)进入命令提示符,进入工作空间目录,运行mvn archetype:create -DgroupId=com.test.web -DartifactId=demo-webapp -DarchetypeArtifactId=maven-archetype-webapp
接着运行mvn eclipse:eclipse 转为eclipse工程
2)导入project:import->exitsting maven project->选择目录后导入即可
3) 导入后,项目中没有src/main/java,需要新建,并添加至source中,
一切完备后,工程的目录如下:
4)编写pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.web</groupId>
<artifactId>demo-webapp</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>demo-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>demo-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
</project>
5)编写web.xml
<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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>demo</display-name>
<!-- <servlet> -->
<!-- <servlet-name>firstServlet</servlet-name> -->
<!-- <servlet-class>com.test.TestServlet</servlet-class> -->
<!-- </servlet> -->
<!-- <servlet-mapping> -->
<!-- <servlet-name>firstServlet</servlet-name> -->
<!-- <url-pattern>/index</url-pattern> -->
<!-- </servlet-mapping> -->
<!-- <context-param> -->
<!-- <param-name>contextConfigLocation</param-name> -->
<!-- <param-value>classpath:application-*.xml</param-value> -->
<!-- </context-param> -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml,classpath:application-*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
6)spring-mvc.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" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!-- 注解探测器 -->
<context:component-scan base-package="com" />
<mvc:annotation-driven>
</mvc:annotation-driven>
<mvc:default-servlet-handler />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
7)application-common.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
<!-- 配置DataSource数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@192.168.1.201:1521:NGBOSS" />
<property name="username" value="Intelligent_city" />
<property name="password" value="intelligent_city" />
</bean>
<!-- 配置SqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" >
<list>
<value>classpath:com/dao/mapper/*.xml</value>
</list>
</property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.dao.mapper" />
</bean>
</beans>
8)编写controller层
package com.controller;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.dao.entity.HouseInfo;
import com.google.gson.Gson;
import com.service.HouseSV;
@Controller
public class IndexController {
@Autowired
private HouseSV houseSV;
@RequestMapping("/hello")
public String showIndex(){
List<HouseInfo> list = houseSV.selectHouseById(2L);
System.out.println(list.size());
return "new";
}
@RequestMapping("/queryHouseInfo")
public void queryHouseInfo(HttpServletRequest request ,PrintWriter out){
String houseId= request.getParameter("houseId");
List<HouseInfo> list = null;
if(houseId!=null&&!houseId.equals("")){
list = houseSV.selectHouseById(Long.parseLong(houseId));
}
System.out.println("houseId:"+houseId);
Gson gson = new Gson();
String listStr = gson.toJson(list);
System.out.println("listStr:"+listStr);
out.print(gson.toJson(list));
}
}
9)service层
package com.service;
import java.util.List;
import com.dao.entity.HouseInfo;
public interface HouseSV {
public List<HouseInfo> selectHouseById(long houseId);
}
package com.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dao.entity.HouseInfo;
import com.dao.mapper.HouseInfoMapper;
import com.service.HouseSV;
@Service("houseSV")
public class HouseSVImpl implements HouseSV {
@Autowired
HouseInfoMapper houseMapper;
public List<HouseInfo> selectHouseById(long houseId) {
return houseMapper.selectHouseById(houseId);
//return null;
}
}
10)dao层
dao层的结构如下
注意HouseInfoMapper.java 和HouseInfoMapper.xml文件放在同一个包内,分别贴出三个文件:
package com.dao.entity;
import java.io.Serializable;
public class HouseInfo implements Serializable {
private Long communityId; // 社区编号
private Long zoneId; // 小区编号
private Long houseId; // 房屋 ID
private Long buildingId; // 所在楼栋
private String houseNo; // 房号
private String houseTypeId; // 户型
private String structureId; // 房屋结构
private String designUseId; // 设计用途
private Long houseArea; // 房屋面积
private Long houseStateId; // 房屋状态
private Long ownerTypeId; // 业主类型
private String ownerName; // 业主
private String ownerTel; // 业主联系电话
private Long houseCertificateId; // 产权证类型
private String houseCertificateNo; // 产权证编号
private Long toward; // 朝向
private String equity; // 产权年限
public Long getHouseId() {
return houseId;
}
public void setHouseId(Long houseId) {
this.houseId = houseId;
}
public Long getBuildingId() {
return buildingId;
}
public void setBuildingId(Long buildingId) {
this.buildingId = buildingId;
}
public String getHouseNo() {
return houseNo;
}
public void setHouseNo(String houseNo) {
this.houseNo = houseNo;
}
public String getHouseTypeId() {
return houseTypeId;
}
public void setHouseTypeId(String houseTypeId) {
this.houseTypeId = houseTypeId;
}
public String getStructureId() {
return structureId;
}
public void setStructureId(String structureId) {
this.structureId = structureId;
}
public String getDesignUseId() {
return designUseId;
}
public void setDesignUseId(String designUseId) {
this.designUseId = designUseId;
}
public Long getHouseArea() {
return houseArea;
}
public void setHouseArea(Long houseArea) {
this.houseArea = houseArea;
}
public Long getHouseStateId() {
return houseStateId;
}
public void setHouseStateId(Long houseStateId) {
this.houseStateId = houseStateId;
}
public Long getOwnerTypeId() {
return ownerTypeId;
}
public void setOwnerTypeId(Long ownerTypeId) {
this.ownerTypeId = ownerTypeId;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public String getOwnerTel() {
return ownerTel;
}
public void setOwnerTel(String ownerTel) {
this.ownerTel = ownerTel;
}
public Long getHouseCertificateId() {
return houseCertificateId;
}
public void setHouseCertificateId(Long houseCertificateId) {
this.houseCertificateId = houseCertificateId;
}
public String getHouseCertificateNo() {
return houseCertificateNo;
}
public void setHouseCertificateNo(String houseCertificateNo) {
this.houseCertificateNo = houseCertificateNo;
}
public Long getToward() {
return toward;
}
public void setToward(Long toward) {
this.toward = toward;
}
public String getEquity() {
return equity;
}
public void setEquity(String equity) {
this.equity = equity;
}
public Long getCommunityId() {
return communityId;
}
public void setCommunityId(Long communityId) {
this.communityId = communityId;
}
public Long getZoneId() {
return zoneId;
}
public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}
@Override
public String toString() {
return "HouseInfo [communityId=" + communityId + ", zoneId=" + zoneId
+ ", houseId=" + houseId + ", buildingId=" + buildingId
+ ", houseNo=" + houseNo + ", houseTypeId=" + houseTypeId
+ ", structureId=" + structureId + ", designUseId="
+ designUseId + ", houseArea=" + houseArea + ", houseStateId="
+ houseStateId + ", ownerTypeId=" + ownerTypeId
+ ", ownerName=" + ownerName + ", ownerTel=" + ownerTel
+ ", houseCertificateId=" + houseCertificateId
+ ", houseCertificateNo=" + houseCertificateNo + ", toward="
+ toward + ", equity=" + equity + "]";
}
}
package com.dao.mapper;
import java.util.List;
import com.dao.entity.HouseInfo;
public interface HouseInfoMapper {
public List<HouseInfo> selectHouseById(long houseId);
}
HouseInfoMapper.xml文件:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.dao.mapper.HouseInfoMapper">
<resultMap id="result_getHouseInfo"
type="com.dao.entity.HouseInfo">
<id property="houseId" column="HOUSE_ID" />
<result property="buildingId" column="BUILDING_ID" />
<result property="houseNo" column="HOUSE_NO" />
<result property="houseTypeId" column="HOUSE_TYPE_ID" />
<result property="structureId" column="STRUCTURE_ID" />
<result property="designUseId" column="DESIGN_USE_ID" />
<result property="houseArea" column="HOUSE_AREA" />
<result property="houseStateId" column="HOUSE_STATE_ID" />
<result property="ownerTypeId" column="OWNER_TYPE_ID" />
<result property="ownerName" column="OWNER_NAME" />
<result property="ownerTel" column="OWNER_TEL" />
<result property="houseCertificateId" column="HOUSE_CERTIFICATE_ID" />
<result property="houseCertificateNo" column="HOUSE_CERTIFICATE_NO" />
<result property="toward" column="TOWARD" />
<result property="equity" column="EQUITY" />
<result property="communityId" column="COMMUNITY_ID" />
<result property="zoneId" column="ZONE_ID" />
</resultMap>
<select id="selectHouseById" parameterType="long"
resultMap="result_getHouseInfo">
select * from T_HOUSE WHERE HOUSE_ID=#{houseId}
</select>
</mapper>
11)前台页面
前台页面结构
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<body>
<form action="hello" method="post">
<button type="submit">提交</button>
</form>
</body>
</html>
new.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>测试</title>
<link href="/js/easyui-1.3.6/themes/default/easyui.css" rel="stylesheet"
type="text/css" />
<link href="/js/easyui-1.3.6/themes/icon.css" rel="stylesheet"
type="text/css" />
<script src="/js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="/js/easyui-1.3.6/jquery.easyui.min.js"
type="text/javascript"></script>
</head>
<body>
<table id="houseInfo"></table>
</body>
</html>
<script type="text/javascript">
$(function(){
var grid = $("#houseInfo").datagrid({
url:'queryHouseInfo',
columns:[[{
width : '100',
title : '所在楼栋',
field : 'buildingId'
},
{
width : '100',
title : '房号',
field : 'houseNo'
}]]
});
$("#houseInfo").datagrid('load',{
houseId:'2'
});
});
</script>
代码开发完毕
3.部署
配置完成后,点击debug运行即可
最后,源码奉上
相关推荐
本项目框架“maven+springMVC+mybatis+velocity+mysql+junit”提供了一种高效、灵活且可维护的解决方案。以下将详细讲解这些组件及其作用。 1. Maven: Maven是一个项目管理工具,用于构建、依赖管理和项目信息...
本项目以“maven+springmvc+redis+mybatis整合”为主题,旨在提供一个基于这些技术的集成框架,特别强调了利用Redis作为缓存来提升应用性能。下面将详细阐述这个框架中的各个组成部分以及它们之间的协作。 首先,...
Maven 是一个优秀的项目管理和构建工具,Spring 是一个广泛使用的 Java 框架,SpringMVC 是基于 Spring 的一个 Web 框架,MyBatis 是一个持久层框架。在这个项目中,我们将使用这些技术栈来搭建一个完整的 Web 应用...
【Maven+SpringMVC+MyBatis+EasyUI+MySQL DEMO】是一个典型的Java Web项目集成示例,它展示了如何将这些流行的技术框架整合在一起,以构建一个功能丰富的Web应用。下面将详细介绍这些技术及其在项目中的作用。 1. ...
【标题】"maven+springMvc+MyBatis Demo"是一个综合性的开发示例,它展示了如何将三个关键的Java Web开发框架——Maven、Spring MVC和MyBatis——集成到一个项目中。这个示例旨在帮助开发者理解如何在实际项目中有效...
【Maven+SpringMVC+Mybatis Demo】是一个典型的Java Web开发示例,它结合了三个流行的开源框架:Maven、SpringMVC和Mybatis,用于构建高效、模块化的Web应用程序。下面将详细介绍这三个框架以及它们如何协同工作。 ...
整合搭建Spring+SpringMVC+Mybatis+Maven+Mysql开发实例
【标题】:“使用IntelliJ IDEA搭建MAVEN+SSM(Spring+SpringMVC+MyBatis)项目” 【正文】 在Java开发领域,Spring、SpringMVC和MyBatis框架的组合,简称SSM,是构建Web应用程序的常用技术栈。IntelliJ IDEA作为...
Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
【标题】"maven+springmvc+spring+mybatis"是一个经典的Java Web开发技术栈,它结合了四个关键组件:Maven(项目管理工具),Spring MVC(MVC框架),Spring(核心框架)以及MyBatis(持久层框架)。这个组合在企业...
【标题】"eclipse+maven+springmvc+spring+mybatis案例附带mysql数据库"是一个典型的Java Web开发项目,它涵盖了多个关键的技术栈,包括Eclipse IDE、Maven构建工具、Spring MVC作为MVC框架、Spring核心框架以及...
"maven+spring MVC+Mybatis+jetty+mysql" 的组合是常见的开发栈,它涵盖了项目管理、前端控制器、持久层操作、应用服务器以及数据库管理等多个层面。下面将详细介绍这些关键技术及其在实际应用中的作用。 1. Maven...
在本项目中,"Spring+SpringMVC+Mybatis+Maven+bootstrap+ajax+jQuery整合开发简单的员工后台管理系统",我们看到一个基于Java技术栈的Web应用开发实例。这个系统利用了多个核心技术来构建一个功能完备的员工管理...
Maven+SpringMVC+Spring+Mybatis+Mysql(Oracle)框架整合代码,需要注意的是Maven仓库不提供ojdbc.jar,需要手动添加,mvn install:install-file -DgroupId=...
maven项目+springmvc+mybatis操作数据库项目搭建
【标题】"maven + springmvc + mybatis" 指的是一个常见的Java Web开发框架组合,用于构建高效、模块化的应用程序。Maven是项目管理和综合工具,Spring MVC是Spring框架的一部分,用作Web应用的模型-视图-控制器...
在IT行业中,Maven和SpringMVC是两个非常重要的组件,它们分别是项目管理和Web应用程序开发的核心工具。Maven是一款强大的项目构建系统,它通过管理项目的依赖关系和构建生命周期,简化了Java开发流程。而SpringMVC...
在IT行业中,构建Java Web应用程序是一项常见的任务,而"Maven+spring+springMVC+mybatis"是一个经典的组合,它们各自扮演着不同的角色,共同构建出高效、灵活的应用框架。让我们详细了解一下这些技术及其在项目中的...
Spring、SpringMVC、Mybatis、Velocity和Maven是Java Web开发中常用的一组技术栈,它们各自在软件开发的不同层面发挥着重要作用。这个压缩包文件的标题和描述表明,它提供了一个集成这些技术的演示项目,下面我们将...