目录
1.下载好maven并配置好
2.maven工程搭建
2.1打开IDEA建一个新的工程
2.2选择合适的jdk及要创建的web项目模板
2.3输入GroupId和ArtifactId
2.4选择之前下载的maven和setting文件
2.5给项目命名并选择存放路径,点击finish完成项目构建
2.6构建完成后,删除掉pom中的配置信息,保持下图所示
3.SSM搭建
3.1修改pom.xml
3.2 修改web.xml
3.3 新建resources文件夹并修改文件夹属性
3.4 jdbc.properties文件配置
3.5 spring.xml文件配置
3.6 spring-mvc.xml文件配置
3.7新建java文件并修改文件夹属性
3.8新建包名com.xxxx.mybatis.domain;
3.9新建包名com.xxxx.mybatis.IDao
3.10新建包名com.xxxx.mybatis.mapping
3.11新建包名com.xxxx.repo;
3.12新建包名com.xxxx.repo.Impl;
3.13新建包名com.xxxx.controller;
3.14最后完整图如下:
4.mysql数据库建好表
5.打包和启动
5.1打包
5.2启动
码云源码地址:https://gitee.com/qqcj520/Common-Enterprise-Architecture/tree/springmvcmybatis
新建一个ssm+maven的web
项目
Maven中的settings.xml地址设置
在mirrors标签中引入阿里私服
xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
Archetype Created Web Application
contextConfigLocation
classpath:spring.xml
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
true
encoding
UTF-8
encodingFilter
/*
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.IntrospectorCleanupListener
SpringMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
1
true
SpringMVC
/
/index.jsp
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://192.168.87.8:3306/bigdata
username=root
password=root
#\u5b9a\u4e49\u521d\u59cb\u8fde\u63a5\u6570
initialSize=0
#\u5b9a\u4e49\u6700\u5927\u8fde\u63a5\u6570
maxActive=20
#\u5b9a\u4e49\u6700\u5927\u7a7a\u95f2
maxIdle=20
#\u5b9a\u4e49\u6700\u5c0f\u7a7a\u95f2
minIdle=1
#\u5b9a\u4e49\u6700\u957f\u7b49\u5f85\u65f6\u95f4
maxWait=60000
text/html;charset=UTF-8
创建实体类:
package com.xxxx.mybatis.domain;
import java.io.Serializable;
public class Enterprise implements Serializable{
private Integer id;
private String name;
private String address;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address == null ? null : address.trim();
}
}
新建mapper
package com.xxxx.mybatis.IDao;
import com.xxxx.mybatis.domain.Enterprise;
public interface EnterpriseMapper {
int deleteByPrimaryKey(Integer id);
int insert(Enterprise record);
int insertSelective(Enterprise record);
Enterprise selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(Enterprise record);
int updateByPrimaryKey(Enterprise record);
}
id, name, address
delete from enterprise
where id = #{id,jdbcType=INTEGER}
insert into enterprise (id, name, address
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}
)
insert into enterprise
id,
name,
address,
#{id,jdbcType=INTEGER},
#{name,jdbcType=VARCHAR},
#{address,jdbcType=VARCHAR},
update enterprise
name = #{name,jdbcType=VARCHAR},
address = #{address,jdbcType=VARCHAR},
where id = #{id,jdbcType=INTEGER}
update enterprise
set name = #{name,jdbcType=VARCHAR},
address = #{address,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
package com.xxxx.repo;
import com.xxxx.mybatis.domain.Enterprise;
public interface IEnterpriseService {
public Enterprise getEnterpriseById(int enterpriseId);
}
package com.xxxx.repo.Impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.xxxx.mybatis.IDao.EnterpriseMapper;
import com.xxxx.mybatis.domain.Enterprise;
import com.xxxx.repo.IEnterpriseService;
@Service("enterpriseService")
public class EnterpriseServiceImpl implements IEnterpriseService{
@Resource
private EnterpriseMapper enterpriseMapper;
@Override
public Enterprise getEnterpriseById(int enterpriseId) {
return enterpriseMapper.selectByPrimaryKey(enterpriseId);
}
}
package com.xxxx.controller;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.xxxx.mybatis.domain.Enterprise;
import com.xxxx.repo.IEnterpriseService;
@RestController
@RequestMapping("/enterprise")
public class EnterpriseController {
@Resource
IEnterpriseService enterpriseService;
@RequestMapping("/getname")
@ResponseBody
public Enterprise getName(){
return enterpriseService.getEnterpriseById(1);
}
}
点击启动,出现0表示打包成功
启动成功
查询接口,接口返回成功,SSM项目搭建完成