我的idea是13.1.3
首先点击 File - New Project - 选择maven ,并且在右面选择maven-archtype-webapp选项,如图所示
点击next后,出现填写GroupId和Artifactid,一般GroupId写com.***.项目,Artifactid写你的项目名称
然后点击next
点击next
Project name 项目名称,location项目地址,随后点击finish,如果未创建例如我的E盘csdn文件夹,会提示是否创建,点OK
随后idea进行下载目录结构,如果网络慢的话,可能会等比较长时间。 创建好目录之后提示信息,忽略那条waring...如下图
先看一下项目 目录的结构
现在是一个大的project,我们可以右键csdn项目new 一个Module命名为csdn-front前端模块,在右键new一个Module命名为csdn-service作为数据模块,步骤过程和上面一样,过程略去,(这里面,new的Module也都是maven项目,记得和上述过程一样哦)直接展示new好的目录结构
我这里的csdn-front中的main目录下java目录是自己手动创建的,会发现他是蓝色的,如果刚接触idea不久可能不知道如何创建java目录,还是new 一个文件夹命名为java,然后操作如下图所示
酱紫就是蓝色的java目录了
现在配置pom.文件,打开csdn-front里的pom.xml
4.0.0
com.wangjianxin.csdn
csdn-front
war
csdn-fron
1.0-SNAPSHOT
http://maven.apache.org
UTF-8
4.0.5.RELEASE
3.1
1.6
1.2.2
junit
junit
3.8.1
test
com.typesafe.akka
akka-actor_2.10
2.3.6
com.wangjianxin.csdn
csdn-service
1.0-SNAPSHOT
org.apache.commons
commons-lang3
3.1
org.apache.shiro
shiro-core
${version.shiro}
org.apache.shiro
shiro-web
${version.shiro}
org.apache.shiro
shiro-spring
${version.shiro}
org.apache.shiro
shiro-aspectj
${version.shiro}
org.apache.shiro
shiro-ehcache
${version.shiro}
ehcache-core
net.sf.ehcache
org.apache.httpcomponents
httpclient
4.3.3
org.apache.httpcomponents
httpcore
4.3.1
org.apache.httpcomponents
httpmime
4.3.2
org.aspectj
aspectjweaver
1.6.12
cglib
cglib-nodep
2.2
org.springframework
spring-core
${spring.version}
commons-logging
commons-logging
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-webmvc
${spring.version}
commons-logging
commons-logging
1.1.1
javax.servlet
servlet-api
2.5
provided
javax.servlet
jstl
1.2
org.apache.velocity
velocity
1.7
opensymphony
sitemesh
2.4.2
com.google.code.kaptcha
kaptcha
2.3.2
org.slf4j
slf4j-log4j12
1.7.5
org.codehaus.jackson
jackson-core-asl
1.9.12
org.codehaus.jackson
jackson-mapper-asl
1.9.12
org.codehaus.jackson
jackson-core-asl
1.9.12
org.codehaus.jackson
jackson-mapper-asl
1.9.12
com.jolbox
bonecp
0.8.0-rc1
com.cloudhopper.proxool
proxool
0.9.1
org.mybatis
mybatis
3.1.0
org.mybatis
mybatis-spring
1.2.2
HTTPClient
HTTPClient
0.3-3
net.sourceforge.javacsv
javacsv
2.0
commons-fileupload
commons-fileupload
1.3.1
mysql
mysql-connector-java
5.1.18
junit
junit
4.11
test
org.springframework
spring-test
${spring.version}
test
com.google.code.gson
gson
2.3
com.danga
memcached
2.6.6
com.github.miemiedev
mybatis-paginator
1.2.15
csdn-front
${project.basedir}/src/main/resources
true
${project.basedir}/src/main/resources
true
${project.basedir}/src/test/resources
true
org.apache.maven.plugins
maven-surefire-plugin
2.9
true
org.mortbay.jetty
maven-jetty-plugin
6.1.12.rc5
5
8080
600000
/
org.apache.tomcat.maven
tomcat6-maven-plugin
2.2
http://localhost:8080/manager/html
tomcat
tomcat
8090
org.apache.maven.plugins
maven-compiler-plugin
2.5.1
1.6
UTF-8
org.apache.maven.plugins
maven-resources-plugin
2.4.1
UTF-8
org.apache.maven.plugins
maven-war-plugin
2.1.1
true
${project.build.directory}/classes
WEB-INF/classes
false
*.xml
*.properties
在配置csdn-service里的pom文件,如下
4.0.0
com.wangjianxin.csdn
csdn-service
war
csdn-service
http://maven.apache.org
1.0-SNAPSHOT
UTF-8
4.0.5.RELEASE
3.1
1.6
1.2.2
junit
junit
3.8.1
test
org.apache.commons
commons-lang3
3.1
org.apache.httpcomponents
httpclient
4.2.1
org.apache.httpcomponents
httpcore
4.2.1
cglib
cglib-nodep
2.2
org.springframework
spring-core
${spring.version}
commons-logging
commons-logging
org.springframework
spring-orm
${spring.version}
jar
joda-time
joda-time
2.3
commons-httpclient
HttpClient
3.0.1
org.mybatis
mybatis
3.2.3
provided
org.mybatis
mybatis-spring
1.2.2
com.github.miemiedev
mybatis-paginator
1.2.15
org.springframework
spring-webmvc
${spring.version}
commons-logging
commons-logging
1.1.1
com.danga
memcached
2.6.6
javax.servlet
servlet-api
2.5
provided
javax.servlet
jstl
1.2
org.slf4j
slf4j-log4j12
1.7.5
com.fasterxml.jackson.core
jackson-databind
2.0.0-RC1
com.jolbox
bonecp
0.8.0-rc1
com.google.code.gson
gson
2.3
HTTPClient
HTTPClient
0.3-3
net.sourceforge.javacsv
javacsv
2.0
mysql
mysql-connector-java
5.1.18
commons-dbcp
commons-dbcp
1.2.2
commons-lang
commons-lang
2.5
junit
junit
4.11
test
org.springframework
spring-test
${spring.version}
test
org.apache.commons
commons-pool2
2.2
javax.mail
mail
1.4.7
dom4j
dom4j
1.6.1
net.sf.json-lib
json-lib
2.4
jdk15
xom
xom
1.2.5
org.jdom
jdom
1.1
csdn-service
将包都下载到本地maven库之后,开始写配置文件
在csdn-front中的resources里new spring config
命名爲spring-servlet,内容如下
text/json;charset=UTF-8
classpath:jdbc.properties
继续新建xml文件 命名为mybatis-config 如下(这个xml里的settings借鉴了网上的一篇文章,,,)
借着配置配置jdbc.properties 如下
type=mysql
jdbcUrl=jdbc\:mysql\://localhost\:3306/ssm?autoReconnect\=true&useUnicode\=true&characterEncoding\=UTF-8
username=root
password=root
bonecp.idleConnectionTestPeriod=60
bonecp.idleConnectionTestPeriodInMinutes=5
bonecp.idleMaxAgeInMinutes=10
bonecp.idleMaxAge=60
bonecp.partitionCount=3
bonecp.minConnectionsPerPartition=2
bonecp.maxConnectionsPerPartition=50
bonecp.acquireIncrement=3
bonecp.statementsCacheSize=50
bonecp.releaseHelperThreads=3
bonecp.defaultAutoCommit=true
ssm是我的数据库名字,下面root是账号和密码
最后配置web xml文件
Archetype Created Web Application
contextConfigLocation
classpath:spring-mybatis.xml
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.IntrospectorCleanupListener
com.github.miemiedev.mybatis.paginator.CleanupMybatisPaginatorListener
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
CharacterEncodingFilter
/*
spring
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-servlet.xml
1
spring
/
随后开始创建controller 和service
创建controller包,new class文件
package com.wangjianxin.front.controller;
import com.wangjianxin.service.manager.StudentManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* Created by wangjianxin on 2016/10/31.
*/
@Controller
@RequestMapping("/ssm")
public class CsdnController {
@Autowired
private StudentManager studentManager;
@RequestMapping(value = "/csdn.json",method = RequestMethod.GET)
@ResponseBody
public String csdn(){
List lsit = studentManager.selectall();
return lsit.toString();
}
@RequestMapping(value = "/csdn.html")
public String html(){
return "csdn";
}
}
利用@Autowired引入manager 调用manager接口的方法
随后在csdn-service中建立文件夹和类如图
想必这些类目大家都懂得,dao层中的接口方法名和mapping中的xml映射相对应,
StudentManager:
package com.wangjianxin.service.manager;
import com.wangjianxin.service.model.Student;
import java.util.List;
/**
* Created by wangjianxin on 2016/10/26.
*/
public interface StudentManager {
List selectall();
}
package com.wangjianxin.service.manager.impl;
import com.wangjianxin.service.dao.StudentMapper;
import com.wangjianxin.service.manager.StudentManager;
import com.wangjianxin.service.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by wangjianxin on 2016/10/26.
*/
@Service
public class StudentManagerImpl implements StudentManager{
@Autowired
private StudentManager studentManager;
@Override
public List selectall() {
List lsit = studentManager.selectall();
return lsit;
}
}
package com.wangjianxin.service.manager;
import com.wangjianxin.service.model.Student;
import java.util.List;
/**
* Created by wangjianxin on 2016/10/26.
*/
public interface StudentManager {
List selectall();
}
id, name, age, hobby
在csdn的WEB-INF的jsp文件夹下面建立csdn.jsp文件
<%--
Created by IntelliJ IDEA.
User: wangjianxin
Date: 2016/10/31
Time: 13:58
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
hello csdn 哈哈~
写了个ajax和controller交互。
首先编译项目,cmd 命令切换到csdn项目的目录,mvn install
随后编译成功后可以在idea中的maven Project选项栏里找到csdn-front里的Plugins-jetty-jetty:run运行。
输入地址localhost:8080/ssm/csdn.html