博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ssm+mavn+idea2017.1+jdk1.7+
阅读量:6847 次
发布时间:2019-06-26

本文共 17559 字,大约阅读时间需要 58 分钟。

项目下载地址:链接: 密码:0pry

项目最终的结构图:

090434_azRf_3027745.png

数据库:

/*Navicat MySQL Data TransferSource Server         : WuGongVmLinuxSource Server Version : 50711Source Host           : 192.168.1.148:3306Source Database       : vipTarget Server Type    : MYSQLTarget Server Version : 50711File Encoding         : 65001Date: 2018-02-26 09:38:45*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for t_phone-- ----------------------------DROP TABLE IF EXISTS `t_phone`;CREATE TABLE `t_phone` (  `id` bigint(20) NOT NULL AUTO_INCREMENT,  `user_id` bigint(20) DEFAULT NULL,  `add_user_id` bigint(20) DEFAULT NULL,  `add_time` datetime DEFAULT NULL,  `delete_flag` int(1) DEFAULT '0',  `phone` varchar(20) DEFAULT NULL COMMENT '手机号',  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;-- ------------------------------ Records of t_phone-- ----------------------------INSERT INTO `t_phone` VALUES ('1', '1', '1', '2018-02-23 14:49:26', '0', '18353131182');INSERT INTO `t_phone` VALUES ('2', '1', '1', '2018-02-23 15:27:14', '0', '18765413758');-- ------------------------------ Table structure for t_user-- ----------------------------DROP TABLE IF EXISTS `t_user`;CREATE TABLE `t_user` (  `id` bigint(20) NOT NULL AUTO_INCREMENT,  `name` varchar(100) DEFAULT NULL COMMENT '用户名',  `nick_name` varchar(100) DEFAULT NULL COMMENT '昵称',  `add_time` datetime DEFAULT NULL COMMENT '添加时间',  `add_user_id` bigint(20) DEFAULT NULL COMMENT '添加人',  `delete_flag` int(1) DEFAULT '0' COMMENT '删除标识',  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;-- ------------------------------ Records of t_user-- ----------------------------INSERT INTO `t_user` VALUES ('1', '吴工', 'wugong', '2018-02-23 14:14:29', '1', '0');INSERT INTO `t_user` VALUES ('2', '管理员', 'admin', '2018-02-23 14:43:02', '1', '0');INSERT INTO `t_user` VALUES ('3', '平台账号-000', 'plat', '2018-02-23 16:09:07', null, '1');INSERT INTO `t_user` VALUES ('4', '平台账号-001', 'plat', '2018-02-23 16:10:57', null, '0');INSERT INTO `t_user` VALUES ('5', '平台账号', 'plat', '2018-02-23 16:11:33', null, '0');INSERT INTO `t_user` VALUES ('6', '平台账号', 'plat', '2018-02-23 16:11:50', null, '0');INSERT INTO `t_user` VALUES ('7', '事务1', 'plat', '2018-02-23 16:49:58', null, '0');INSERT INTO `t_user` VALUES ('8', '事务2', 'plat', '2018-02-23 16:56:54', null, '0');INSERT INTO `t_user` VALUES ('11', '事务3', 'plat', '2018-02-23 17:05:59', null, '0');-- ------------------------------ Table structure for users-- ----------------------------DROP TABLE IF EXISTS `users`;CREATE TABLE `users` (  `id` bigint(20) NOT NULL AUTO_INCREMENT,  `userName` varchar(200) DEFAULT NULL,  `password` varchar(100) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='shiro权限验证演示users表,因为shiro读取的指定表名称、字段名称';-- ------------------------------ Records of users-- ----------------------------INSERT INTO `users` VALUES ('1', 'wugong', '123456');

1.1、创建project

133302_sSlO_3027745.png

133326_WZFC_3027745.png

 接着下一步,这里需要注在Properties中添加一个参数 archetypeCatalog=internal,不加这个参数,在maven生成骨架的时候将会非常慢,有时候直接卡住。来自网上的解释:

archetypeCatalog表示插件使用的archetype元数据,不加这个参数时默认为remote,local,即中央仓库archetype元数据,由于中央仓库的archetype太多了所以导致很慢,指定internal来表示仅使用内部元数据。

133506_zP9u_3027745.png

133606_xjER_3027745.png

整个mavn项目就算创建完毕

 

144934_xJ6J_3027745.png

2、创建两个directoy--->java  test

145000_7Rzf_3027745.png

2.1、标记新创建的目录为Sources  Tests

145028_ROJP_3027745.png

设置idea编译jdk环境为1.8或者1.7+

145051_S5W0_3027745.png145107_CGWS_3027745.png

在po.xml中添加ssm依赖

145132_7qcw_3027745.png

2、通过mybatis genernator逆向生成dao pojo

首先通过mybatis的逆向配置文件

创建generatorConfig.xml

修改里面的数据库链接信息、表信息

145207_lsmI_3027745.png

 

4.0.2.RELEASE
3.2.6
1.7.7
1.2.17
junit
junit
4.12
test
org.springframework
spring-core
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-oxm
${spring.version}
org.springframework
spring-tx
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-aop
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-test
${spring.version}
org.aspectj
aspectjweaver
1.8.4
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
1.2.2
javax
javaee-api
7.0
mysql
mysql-connector-java
5.1.30
commons-dbcp
commons-dbcp
1.2.2
jstl
jstl
1.2
log4j
log4j
${log4j.version}
com.alibaba
druid
1.0.12
com.fasterxml.jackson.core
jackson-core
2.8.5
com.fasterxml.jackson.jaxrs
jackson-jaxrs-xml-provider
2.4.1
org.codehaus.jackson
jackson-mapper-asl
1.9.4
com.fasterxml.jackson.core
jackson-databind
2.8.5
com.fasterxml.jackson.core
jackson-annotations
2.8.5
com.alibaba
fastjson
1.2.3
org.slf4j
slf4j-log4j12
${slf4j.version}
commons-fileupload
commons-fileupload
1.3.1
commons-io
commons-io
2.4
commons-codec
commons-codec
1.9
com.github.pagehelper
pagehelper
4.0.0
com.github.pagehelper
pagehelper
4.0.0
org.apache.shiro
shiro-core
1.2.3
com.mchange
c3p0
0.9.5.2
commons-logging
commons-logging
1.2
ssm
org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2
true
true

配置idea创建mavn执行逆向

145313_i4JL_3027745.png

145331_h9Tj_3027745.png

mybatis-generator:generate -e

保证pom.xml中已经配置

org.mybatis.generator
mybatis-generator-maven-plugin
1.3.2
true
true

然后执行逆向

145427_ubgO_3027745.png

结果:

145457_MwJ6_3027745.png

然后创建web项目的基本文件目录

145519_9PG3_3027745.png

web.xml

Archetype Created Web Application
contextConfigLocation
classpath:spring-mybatis.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

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://192.168.1.148:3306/vip?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNulljdbc.username=rootjdbc.password=root#定义初始连接数initialSize=0#定义最大连接数maxActive=20#定义最大空闲maxIdle=20#定义最小空闲minIdle=1#定义最长等待时间maxWait=60000

log4j.properties

log4j.rootLogger=INFO,Console,File#定义日志输出目的地为控制台log4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.Target=System.out#可以灵活地指定日志输出格式,下面一行是指定具体的格式log4j.appender.Console.layout = org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=[%c] - %m%n#文件大小到达指定尺寸的时候产生一个新的文件log4j.appender.File = org.apache.log4j.RollingFileAppender#指定输出目录log4j.appender.File.File = logs/ssm.log#定义文件最大大小log4j.appender.File.MaxFileSize = 10MB# 输出所以日志,如果换成DEBUG表示输出DEBUG以上级别日志log4j.appender.File.Threshold = ALLlog4j.appender.File.layout = org.apache.log4j.PatternLayoutlog4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n

spring-mvc.xml

text/plain;charset=UTF-8

spring-mybatis.xml

4、创建controller、service与jsp页面

UserController
package com.jie.controller;import com.jie.service.spi.IUserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;/** * \* Created with IntelliJ IDEA. * \* User: wugong.jie * \* Date: 2018/2/26 14:09 * \* To change this template use File | Settings | File Templates. * \* Description: * \ */@Controller@RequestMapping("manage/user")public class UserController {    @Autowired    private IUserService userService;    @RequestMapping("{id}")    public String user(@PathVariable("id")Long id,Model model){        try {            model.addAttribute("user",userService.getUser(id));        } catch (Exception e) {            e.printStackTrace();        }        return "user";    }}
package com.jie.service.spi;import com.jie.bean.User;/** * @author wugong.jie * @date 2018/2/26 */public interface IUserService {    Integer saveUser(User user);    Integer updateUser(User user);    User getUser(Long id);    Integer transferSaveUpdate(Long id);}
package com.jie.service;import com.jie.bean.User;import com.jie.dao.UserMapper;import com.jie.service.spi.IUserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import java.util.Random;/** * \* Created with IntelliJ IDEA. * \* User: wugong.jie * \* Date: 2018/2/26 14:10 * \* To change this template use File | Settings | File Templates. * \* Description: * \ */@Servicepublic class UserServiceImpl implements IUserService {    @Autowired    private UserMapper userMapper;    @Override    @Transactional    public Integer saveUser(User user){        userMapper.insert(user);        return 1;    }    @Override    public Integer updateUser(User user){        return userMapper.updateByPrimaryKeySelective(user);    }    @Override    public User getUser(Long id){        return userMapper.selectByPrimaryKey(id);    }    @Override    public Integer transferSaveUpdate(Long id){        User oldUser = this.getUser(id);        User user = new User();        user.setName("游客"+new Random().nextInt(100));        user.setAddUserId(id);//        int i=1/0;        this.saveUser(user);        oldUser.setName(oldUser.getName()+"-"+user.getName());        this.updateUser(oldUser);        return 1;    }}

user.jsp

<%@page contentType="text/html;charset=UTF-8" isELIgnored="false" %><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %><%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>    Title欢迎你:${user.name}

145823_uJtU_3027745.png

5、项目发布到tomcat上,

注意如果没有找到当前的tomcat local 可能是你没有绑定tomcat,自己百度一下tomcat idea绑定

150003_iuuU_3027745.png

150135_w8mW_3027745.png

150158_IQyC_3027745.png

150225_zLfp_3027745.png

编译项目并且启动

150314_LoaQ_3027745.png

150344_FteB_3027745.png

 

150438_FZhb_3027745.png

事务的测试:

创建测试类:UserTransferTest

com/jie/UserTransferTest.java:27

 

项目下载地址:链接: 密码:0pry

 

 

转载于:https://my.oschina.net/wugong/blog/1624146

你可能感兴趣的文章
Hyper-V Server 2008 R2安装、配置
查看>>
MYSQL-字符校对规则探究
查看>>
HTTPClient模拟登陆21CN
查看>>
Golang 用指定网卡的IP发送HTTP请求
查看>>
网站安全狗IIS版 V4.0.15586 发布
查看>>
Docker存储驱动之AUFS简介
查看>>
Java中如何封装自己的类,建立并使用自己的类库?
查看>>
Java Http请求工具类
查看>>
iscsi集群搭建
查看>>
Flutter Web - 目标全平台开发的Flutter再下一城!
查看>>
Nginx代理Tomcat
查看>>
Apache与Tomcat的区别
查看>>
mysql—Access denied for user 'root'@'localhost' (using password:NO)
查看>>
hibernate 懒加载异常
查看>>
python3的zip函数
查看>>
Paxos算法详细图解
查看>>
如何用Exchange Server 2003 构建多域名邮件系统
查看>>
httpd服务如何开机启动
查看>>
JAVA帮助文档全系列 JDK1.5 JDK1.6 JDK1.7 官方中英完整版下载
查看>>
android 1.6中LinearLayout getBaseline函数的一个bug
查看>>