idea新建springmvc+spring+mybaties项目2
1,项目创建完成后,src-main下建立java目录后,是无法在该目录下创建新的包和java类等文件的。在idea中需要对目录进行标注


Sources 一般用于标注类似 src 这种可编译目录。有时候我们不单单项目的 src 目录要可编译,还有其他一些特别的目录也许我们也要作为可编译的目录,就需要对该目录进行此标注。只有 Sources 这种可编译目录才可以新建 Java 类和包,这一点需要牢记。
Tests 一般用于标注可编译的单元测试目录。在规范的 maven 项目结构中,顶级目录是 src,maven 的 src 我们是不会设置为 Sources 的,而是在其子目录 main 目录下的 java 目录,我们会设置为 Sources。而单元测试的目录是 src - test - java,这里的 java 目录我们就会设置为 Tests,表示该目录是作为可编译的单元测试目录。一般这个和后面几个我们都是在 maven 项目下进行配置的,但是我这里还是会先说说。从这一点我们也可以看出 IntelliJ IDEA 对 maven 项目的支持是比较彻底的。
Resources 一般用于标注资源文件目录。在 maven 项目下,资源目录是单独划分出来的,其目录为:src - main -resources,这里的 resources 目录我们就会设置为 Resources,表示该目录是作为资源目录。资源目录下的文件是会被编译到输出目录下的。
Test Resources 一般用于标注单元测试的资源文件目录。在 maven 项目下,单元测试的资源目录是单独划分出来的,其目录为:src - test -resources,这里的 resources 目录我们就会设置为 Test Resources,表示该目录是作为单元测试的资源目录。资源目录下的文件是会被编译到输出目录下的。
Excluded 一般用于标注排除目录。被排除的目录不会被 IntelliJ IDEA 创建索引,相当于被 IntelliJ IDEA 废弃,该目录下的代码文件是不具备代码检查和智能提示等常规代码功能。
通过上面的介绍,我们知道对于非 maven 项目我们只要会设置 src 即可。
2,配置文件
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--1.如果你想使用@Autowired注解,那么就必须事先在 spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。 2.如果想使用@Resource 、@PostConstruct、@PreDestroy等注解就必须声明CommonAnnotationBeanPostProcessor 3.如果想使用@PersistenceContext注解,就必须声明PersistenceAnnotationBeanPostProcessor的Bean。 4.如果想使用 @Required的注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean。 使用<context:annotation- config/>隐式地向 Spring容器注册这4个BeanPostProcessor-->
<context:annotation-config />
<!--开启spring注解,注入bean
1.RequestMappingHandlerMapping 2.BeanNameUrlHandlerMapping 3.RequestMappingHandlerAdapter 4.HttpRequestHandlerAdapter 5.SimpleControllerHandlerAdapter 6.ExceptionHandlerExceptionResolver 7.ResponseStatusExceptionResolver 8.DefaultHandlerExceptionResolver-->
<mvc:annotation-driven/> <context:component-scan base-package="com.controller" /> <mvc:resources mapping="/css/**" location="/WEB-INF/statics/css" />
<mvc:resources mapping="/js/**" location="/WEB-INF/statics/js/" />
<mvc:resources mapping="/image/**" location="/WEB-INF/statics/image/" /> <!--视图解析-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="contentType" value="text/html;charset = UTF-8" />
<property name="suffix" value=".vm"/>
</bean> <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>WEB-INF/velocity/</value>
</property>
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encodint">UTF-8</prop>
<prop key="contentType">text/html;charset=UTF-8</prop>
<prop key="velocimaco.library">macro/macros.vm</prop>
</props>
</property>
</bean> </beans>
log4j.properties
#配置根Logger 后面是若干个Appender
log4j.rootLogger=DEBUG,A1,R
#log4j.rootLogger=INFO,A1,R # ConsoleAppender 输出
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n # File 输出 一天一个文件,输出路径可以定制,一般在根路径下
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=log.txt
log4j.appender.R.MaxFileSize=500KB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
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>com.project</groupId>
<artifactId>maven-first</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>maven-first Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!--日志-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.10</version>
</dependency>
<!--j2ee servlet jsp,jstl-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>-->
<!--<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>--> <!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
</dependency> <!--spring 版本需要统一,否则会有冲突-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.8.RELEASE</version>
</dependency>
<!--页面语言使用velocity-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>2.0</version>
<!--servlet-api有冲突,需要排除-->
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency> </dependencies>
<build>
<finalName>maven-first</finalName>
<!--tomcat插件-->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<uriEncoding>utf-8</uriEncoding>
<path>/mavenfirst</path>
<port>8181</port>
</configuration>
</plugin> </plugins> <resources>
<resource>
<directory>${basedir}/src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
</build>
</project>
3,创建controller
package com.controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class UserController { @RequestMapping("index")
public String login(){
return "index";
}
}
4,运行项目


5,选中项目,点击启动

PS:tomcat插件方式启动



idea新建springmvc+spring+mybaties项目2的更多相关文章
- idea新建springmvc+spring+mybaties项目1
1,点击file,选择module,新建项目 2,选择maven -- >maven-archetype-webapp 3,输入GroupId,ArtifactId,点击next 4,选择本地m ...
- Java-----SSM(SpringMVC+Spring+mybaties)框架整合
在进行整合之前,首先了解这个框架的作用 Mybaties: 丰富的标签库,可写动态sql,并统一的在.XML文件中编写,方便统一管理,解耦 SpringMVC: 标准的MVC思想(mode,view, ...
- 使用IntelliJ IDEA新建一个spring boot项目
好家伙, 使用IntelliJ IDEA新建一个spring boot项目 目的很简单,就是网页上出现一个"hello world" 别的暂时不管 首先关于工具IntelliJ I ...
- JAVA入门教程 - idea 新建maven spring MVC项目
用的是Idea2017版本.其他大同小异 1.新建项目 2.勾选Create from archetype 选中maven-archetype-webapp 3.输入项目名字. 4.下一步 5.点Fi ...
- SpringMVC+Spring+mybatis项目从零开始--分布式项目结构搭建
转载出处: SpringMVC+Spring+mybatis+Redis项目从零开始--分布式项目结构搭建 /** 本文为博主原创文章,如转载请附链接. **/ SSM框架web项目从零开始--分布式 ...
- ssm项目框架搭建(增删改查案例实现)——(SpringMVC+Spring+mybatis项目整合)
Spring 常用注解 内容 一.基本概念 1. Spring 2. SpringMVC 3. MyBatis 二.开发环境搭建 1. 创建 maven 项目 2. SSM整合 2.1 项目结构图 2 ...
- IDEA新建一个Spring Boot项目
Maven构建项目模板 maven构建的是maven风格的纯净模板,要转变成spring boot项目需要自己添加依赖等配置. mvn archetype:generate: Maven插件原型是一个 ...
- SpringMVC+Spring+mybatis项目从零开始--Spring mybatis mysql配置实现
上一章我们把SSM项目结构已搭建(SSM框架web项目从零开始--分布式项目结构搭建)完毕,本章将实现Spring,mybatis,mysql等相关配置. 1. 外部架包依赖引入 外部依赖包引入 ...
- Maven新建一个Spring MVC项目
新建一个Maven项目,选择archetypes为maven-archetype-webapp,相关的名称按个人习惯取,我这里取Group Id:moonlit-groupArtifact Id:mo ...
随机推荐
- 查看linux ubuntu版本
ubuntu版本: lsb_release -a linux版本: uname -a proc目录下记录的当前系统运行的各种数据,version记录的版本信息直接可以通过cat查看到. 使用命令:c ...
- 大数据学习——HDFS的shell
-help 功能:输出这个命令参数手册 -ls 功能:显示目录信息 示例: hadoop fs -ls hdfs://hadoop-server01:9000/ 备注:这些参数中,所有的hdfs路径都 ...
- mysql异常Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95' for column 'region_name'
Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95' for column 'region_name' insert语句加的该字段有汉字,乱码造成的 解 ...
- XTU 二分图和网络流 练习题 C. 方格取数(1)
C. 方格取数(1) Time Limit: 5000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d Java class ...
- 使用using current logfile实现DG备库实时更新
DG1是主库,DG2是备库:运行在最大可用模式. 实验一:未使用using current logfile参数时,备库在最大可用模式下,不能实时同步备库的更新 -此时需要等待主库进行归档---侧面证明 ...
- Gym - 100548C The Problem Needs 3D Arrays (最大密度子图)
TK在大多数 Unix平台.Windows平台和Macintosh系统都是预装好的,TKinter 模块是 Tk GUI 套件的标准Python接口.可实现Python的GUI编程. Tkinter模 ...
- ubuntu使用git提交github时,执行pull或者push命令要重新输入用户名和密码
ubuntu使用git提交github时,执行pull或者push命令要重新输入用户名和密码: 1:问题现象: hlp@hlp:~/code/github_code/catch_imooc1$ git ...
- .NET 调用java webservice保存datetime类型数据为空的解决办法
问题描述: 用C#.NET调用Java开发的WebService时,先在客户端封装的带有int属性的对象,当将该对象传到服务器端时,服务器端可以得到 string类型的属性值,却不能得到i ...
- phpstorm的破解
按照PHPstorm进入如下页面: 然后继续单击License server 输入:http://www.0-php.com:1017 PHPstorm完美运行!!!!!
- LightOJ1094 - Farthest Nodes in a Tree(树的直径)
http://lightoj.com/volume_showproblem.php?problem=1094 Given a tree (a connected graph with no cycle ...