Maven下的SpringMVC MyBatis
从头开始采用Maven管理,Spring、MyBatis、Tomcat。
在配置过程中SQL Server的Jar老是加载不了,解决方案参考前一篇博文。
eclipse中已经自带了Maven的插件所以不需要再另外下载Maven,使用Maven的好处就是方便jar的管理。配置上
groupId artifactId version 等属性省去自己下载jar 的烦恼。Tomcat 也不需要自己去下载,在Maven中配置好即可。
Maven下载Jar包,需要一段时间需耐心等待。
pom.xml文件如下
<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>test</groupId>
<artifactId>example</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>example Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>4.2.0.RELEASE</spring.version>
<mybatis.version>3.2.8</mybatis.version>
<slf4j.version>1.6.6</slf4j.version>
<log4j.version>1.2.9</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>example</finalName>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<versionRange>[3.1,)</versionRange>
<goals>
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
数据库的文件
Microsoft SQL Server 2008
USE [tonyDb]
GO /****** Object: Table [dbo].[User] Script Date: 08/22/2015 23:08:12 ******/
SET ANSI_NULLS ON
GO SET QUOTED_IDENTIFIER ON
GO SET ANSI_PADDING ON
GO CREATE TABLE [dbo].[User](
[UserID] [int] IDENTITY(1,1) NOT NULL,
[UserName] [varchar](50) NULL,
[PassWord] [varchar](50) NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[UserID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] GO SET ANSI_PADDING OFF
GO
首先看一个新增报错的配置文件中有UserID,不过未给该字段设值。
新增
@RequestMapping(value = "/insertUser", method = RequestMethod.POST)
public @ResponseBody String insertUser(HttpServletRequest request, HttpServletResponse response) {
try {
User u = new User();
u.setUserName((String) request.getAttribute("userName"));
u.setPassWord((String) request.getAttribute("passWord"));
userService.insertUser(u);
return "success";
} catch (Exception e) {
logger.error(e);
}
return "error|Exception ";
}
保存成功的示例
整个项目目录如下:
项目中到的url分享如下:
Maven下的SpringMVC MyBatis的更多相关文章
- 使用maven整合spring+springmvc+mybatis
使用maven整合spring+springmvc+mybatis 开发环境: 1. jdk1.8 2. eclipse4.7.0 (Oxygen) 3. mysql 5.7 在pom.xml文件中, ...
- Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 以及 IntelliJ IDEA 怎样打开依赖视图
Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 配置原则: 利用依赖,将所需的jar包加载到project中. 先依赖主要jar包 Spring + Spring ...
- IDEA中maven搭建Spring+SpringMVC+mybatis项目
一.介绍 使用IDEA搭建maven web项目,整合框架Spring+SpringMVC+mybatis 项目结构图:
- 使用intellij idea搭建MAVEN+SSM(Spring+SpringMVC+MyBatis)框架
基本概念 使用SSM(Spring,SpringMVC和Mybatis) 1.1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod ...
- Maven搭建Spring+SpringMVC+Mybatis+Shiro项目详解
一. 环境搭建: 1. 开发工具:myeclipse 2014 / IDEA: 2. maven管理版本:apache-maven-3.0+: 3. jdk 1.7.0+4. Tomcat8.0 二: ...
- Maven下Spring + SpringMvc + Hibernate4 配置实例
1. 开发环境 IDEA 2. 在pom.xml中配置引用相关的包. <properties> <junit.version>4.10</junit.version> ...
- Maven创建web项目:SpringMVC+Mybatis 【转】
IDEA14创建Maven管理的SpringMVC+Mybatis,web项目 项目构建步骤 1.File->New->Project 勾选Create from archetype 点击 ...
- (4)Maven快速入门_4在Spring+SpringMVC+MyBatis+Oracle+Maven框架整合运行在Tomcat8中
利用Maven 创建Spring+SpringMVC+MyBatis+Oracle 项目 分了三个项目 Dao (jar) Service (jar) Controller (web) ...
- Java系列--第一篇 Maven+Spring+Spring MVC+mybatis 示例
基于Maven的Spring+SpringMVC+Mybatis的一个小项目的搭建,由于使用Maven3.1.0管理,所以Spring等都将使用的是时下(2013/9/8)最新的版本.即从http:/ ...
随机推荐
- 全国银行列表json格式
var list=[ { value:'CDB', text:'国家开发银行' }, { value:'ICBC', text:'中国工商银行' }, { value:'ABC', text:'中国农 ...
- 各大型邮箱smtp服务器及端口收集
>新浪邮箱smtp服务器 外发服务器:smtp.vip.sina.com 收件服务器:pop3.vip.sina.com 新浪免费邮件 外发服务器:smtp.sina.com.cn 收件服务器: ...
- arclistsg文档独立模型标签
[标签名称] arclistsg [标签简介] 单表独立模型的文档列表调用标记 [功能说明] 用于调用单表模型的内容,在V5.3系统以上版本中加入了单表模型的概念,脱离了以前的主从表的数据表关联结构, ...
- 查看php的配置文件Php.ini的位置
标签:php服务器 浏览器 配置文件 Linux local 近来,有不博友问php.ini存在哪个目录下?或者修改php.ini以后为何没有生效?基于以上两个问题,我觉得有必要教一下刚接触PHP的博 ...
- 在Intellij idea 2017中运行tomcat 8.5
前提:jdk,tomcat都已安装完,环境变量该配置的都配置了,tomcat localhost:xx 能登上去 首先新建web小项目 new project next 为项目命个名 finis ...
- mysql字符集问题 错误代码: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_croatian_ci,IMPLICIT) for operation '='
一般是多表或跨库表查询导致出现的问题,其原因是两张表的字符集不一样导致的,那为什么两张表的字符集会不一样?这是由于架构师或者开发人员在建表的时候不小心选错字符集的原因导致的. 那好我们把两张表(或两个 ...
- Velocity动态拼接字符串
1.在全局定义一个变量: #set($varName = "") 2.拼接字符串病截取字符串: #foreach( $role in $adminUser.roles) #set( ...
- python_如何对实例属性进行类型检查?
案例: 在某项目中,我们实现了一些类,并希望能像静态语言那样对他们的实例属性进行类型检查 p = Person() p.name = 'xi_xi' # 必须是str p.age = ...
- java.lang.ClassNotFoundException: com.radiadesign.catalina.session.RedisSessionHandlerValve
org.apache.tomcat.util.digester.Digester.startElement Begin event threw exception java.lang.ClassNot ...
- common-logging--源码之SimpleLog
common-logging源码Log接口 在common-logging的源码中,将log核心类抽象成了一个Log接口. 这里贴出Log接口的源码: /* * Licensed to the Apa ...