Skip to content

doingself/mavenDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ssmProject

Idea + maven (多个 module)

  • Spring + Spring MVC + MyBatis

  • WebSocket

  • Mybatis Generator

  • redis

  • shiro

  • 二维码

  • HttpURLConnection

  • spring 定时器 Scheduled

  • ExtJS 集成失败

项目搭建

创建 Maven 项目

image image image image

添加 module

使用方式一 添加 ssmArtifact-core

image image image image

使用方式二 添加 ssmArtifact-web

只有 web 勾选 Create from Archetype, 并选择 maven-archetype-webapp

image image image image

关联 module

image image

其他设置

  • 删除 ssmProjectsrc
  • web 添加 Java

image image

集成 ExtJS (集成失败😂😂😂)

  1. 样式比较适合做后端前台,风格统一,组件完备,功能强大
  2. 几乎不用写样式,直接调用组件就可以了

ExtJS的版本繁多,本文收集了ExtJS各个版本的下载链接,包括官网和非官网的,以及各种汉化版api,欢迎大家下载分享。

一般历史项目很多用的是2.2.x的版本,而且没有版权问题。(2.2.3相对稳定,但其实bug也不少)
3.x比起2.x改进很多,包括稳定性上的问题,但需要注意版权
4.x版本是一个飞跃式的版本,整个架构都更完善了,MVC,按需加载,plugin机制,components架构等都很不错。
4.0的时候侧重于底层架构,性能不行,后面的4.1和4.2的changelog都说大幅改进性能

准备工作

创建 ExtJS 项目

  • 解压 ext-6.2.0-gpl.zip
  • 解压 SenchaCmd-6.2.2-osx-no_jre.app.zip 并安装
  • 创建 ssmProject 工程 sencha -sdk /Users/syc/Documents/ext-6.2.0 generate app ssmProject /Users/syc/Documents/workspace/ssmProject

export PATH=${PATH}:/Users/syc/bin/Sencha/Cmd/6.2.2.36

bogon:IdeaWorkspace syc$ sencha -sdk ext-6.2.0 generate app ssmProject ssmProject
Sencha Cmd v6.2.2.36
[WRN] the following remote package repository directories did not initialize properly :
[WRN] 	 - /Users/syc/bin/Sencha/Cmd/repo/.sencha
[WRN] 	 - /Users/syc/bin/Sencha/Cmd/repo/pkgs
[ERR] javax/xml/bind/DatatypeConverter
[ERR]
The application was last modified by an older version of Sencha Cmd (6.2.0.103).
Running "sencha package upgrade" may resolve the error described above.

TODO

在网上找前端框架的资料, 发现现在已经基本不用 ExtJS 了 我个人还是挺习惯 ExtJS 的, 但是此次未能成功集成😂😂😂

ssm 搭建

  • 完善目录结构(controller / service / dao / model)
  • 使用 maven 引入 ssm/数据库等各种 jar 包

ssm 配置

  • log4j.properties
  • jdbc.properties
  • mapping/*.xml
  • spring-mvc.xml
  • spring-mybatis.xml
  • web.xml

部署 Tomcat

  • war 将WEB工程以包的形式上传到服务器 发布模式,这是先打成war包,再发布
  • war exploded 将WEB工程以当前文件夹的位置关系上传到服务器 直接把文件夹、jsp页面 、classes等等移到Tomcat 部署文件夹里面,进行加载部署。因此这种方式支持热部署,一般在开发的时候也是用这种方式。

image image image

ssmProject 集成 WebSocket

spring4.0以后加入了对websocket技术的支持 参考 package com.syc.websocket

  • 添加 jar 包
  • 实现 HandshakeInterceptor
  • 实现 WebSocketHandler
  • 继承 WebMvcConfigurerAdapter 实现 WebSocketConfigurer
  • 添加 spring 配置

ssmProject 集成 MyBatis Generator

MyBatis Generator (MBG) 是一个Mybatis的代码生成器,它可以帮助我们根据数据库中表的设计生成对应的 实体类xml Mapper文件,接口以及帮助类(也就是我们可以借助该类来进行简单的CRUD操作),这样就避免了我们每使用到一张表的数据就需要手动去创建对应的类和xml文件,这就帮我们节约了大量的时间去开发和业务逻辑有关的功能,但是如果对联合查询和存储过程您仍然需要手写SQL和对象。

  1. maven 配置
    <dependencies>
		<dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>

        ...
    </dependencies>
    <build>
        <finalName>ssmArtifact-web</finalName>

        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>

                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <verbose>true</verbose>
                        <overwrite>true</overwrite>
                    </configuration>
                </plugin>

                ...
            </plugins>
        </pluginManagement>
    </build>
  1. 配置 generatorConfig.xml

    参考 ssmProject/ssmArtifact-web/generatorConfig.xml 配置

  2. 运行

        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;

        //指定 逆向工程配置文件
        File configFile = new File(MybatisGenerator.class.getResource("/generatorConfig.xml").getFile());
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = null;
        try {
            config = cp.parseConfiguration(configFile);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XMLParserException e) {
            e.printStackTrace();
        }
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = null;
        try {
            myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        } catch (InvalidConfigurationException e) {
            e.printStackTrace();
        }
        try {
            myBatisGenerator.generate(null);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

ssmProject 集成 Redis

  1. 添加 maven 依赖
    • spring-data-redis spring-redis实现
    • jedis redis客户端
    • mybatis-ehcache Ehcache实现,用于参考
  2. 添加 redis.properties 文件, 配置 Redis 参数
  3. 添加 spring-redis.xml 配置文件
  4. web.xmlcontextConfigLocation 进行配置

ssmProject 集成 shiro

  1. 配置 maven 依赖
  2. 配置 spring-shiro.xml
  3. 实现类
  4. web.xml 配置 DelegatingFilterProxy

ssmProject 集成 二维码

  1. 配置 maven 依赖 (com.google.zxing)
  2. 参考 QRCodeController

ssmProject Http 请求

参考使用 HttpURLConnectioncom.syc.http.HttpUtil 工具类

请求方式

  • 使用原生 HttpURLConnection
  • 使用 HTTPClient

ssmProject 集成 定时器

  1. spring 配置文件 beans 中添加属性 xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation
  2. spring 配置文件 <beans> 标记内添加
<context:component-scan base-package="com.syc.task" />

<task:executor id="executor" pool-size="5" />
<task:scheduler id="scheduler" pool-size="10" />
<task:annotation-driven executor="executor" scheduler="scheduler" mode="proxy"/>
  1. 实现了添加注解 @Component @Scheduled
    参考 com.syc.task.MyTask

    • fixedDelay
    • cron

sycProject

Idea + Maven 多 module 工程, module 间相互依赖的简单 Java Web Demo

image

image

image

image

image

image

image

image

image

image

image

image

image

鸣谢

About

Idea + Maven 多 module 工程, module 间相互依赖的简单 Java Web Demo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published