spring mvc + mybatis 框架搭建

idea + gradle
刚刚入门,只是个人见解,如有错误或者问题欢迎指出指正。
邮箱: [ wgh0807@qq.com ]

文章引用:
[apache - log4j]
[mybatis 配置]

一、 build.gradle 加载相关包

在dependencies下配置
相关包的搜索请见[maven.org]
个人常用的包:
''// java EE api
'' compile 'javax:javaee-api:7.0'
''
'' //mysql connector
'' compile 'mysql:mysql-connector-java:5.1.47'
''
'' // spring 框架
'' compile 'org.springframework:spring-webmvc:5.1.3.RELEASE'
'' compile 'org.springframework:spring-jdbc:5.1.3.RELEASE'
'' compile 'org.springframework:spring-context-support:5.1.3.RELEASE'
''
'' // mybatis
'' compile 'org.mybatis:mybatis:3.4.6'
'' compile 'org.mybatis:mybatis-spring:1.3.2'
''
'' //其他
'' // json 转换
'' compile 'com.fasterxml.jackson.core:jackson-databind:2.9.8'// json数据转换
'' compile 'jstl:jstl:1.2'//jsp标准标签库
'' compile 'org.jasypt:jasypt:1.9.2'//Strong Password encorypt
'' compile 'org.projectlombok:lombok:1.18.4'//精简class
'' compile 'org.slf4j:slf4j-log4j12:1.7.25' //日志记录
'' compile 'commons-codec:commons-codec:1.11'//编解码
'' compile 'commons-fileupload:commons-fileupload:1.3.2'//文件上
修改完后使用右下角弹窗中的import 或者auto import 都可以,会在网络环境下自动下载。

二、创建包结构

个人喜欢提前创建好包结构,而且喜欢在一个总的包下创建包

  • src

    • project

      • controller(控制器)
      • service(服务层)
      • dao(数据层)
      • obj(对象包,也可以使用pojo、model等)
      • util(其他工具类)

        三、配置文件

        目录结构

  • resources
    • mapper

      • xxxx-mapper.xml
    • jdbc.properties
    • log4j.properties
    • mybatis-config.xml (可以集成到application.xml中,非必须)
    • application.xml
  • webapp
    • WEB-INF

      • web.xml
      • web-servlet.xml

        详细配置

  1. jdbc.properties

    jdbc.Url 中传入了三个参数,由于使用本地数据库访问,故没有使用ssl加密;其他两个为编码方式使用utf-8,否则可能会出现中文乱码(需要参照数据库编码方式,建库的时候也最好配置下。mac下mysql使用UTF8)
    配置如下
    ''jdbc_Driver = com.mysql.jdbc.Driver
    '' jdbc_Url = jdbc:mysql:///?useSSL=false&useUnicode=true&characterEncoding=UTF-8
    '' jdbc_user = java
    '' jdbc_password = java

  2. mapper/*-mapper.xml

    为了第5项配置方便,才创建mapper文件夹,并命名为*-mapper.xml
    基本配置为
    ''<?xml version="1.0" encoding="UTF-8"?>
    '' <!DOCTYPE mapper
    '' PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    '' "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    ''
    ''
    ''
    内容物包含5种常用标签:insert, delete, update, select 和 resultMap
    前4种分别对应增删改查,第五种则是为了对象中一对多或多对多属性。
    result map中又包含四个常用标签:id、result、association、collection
    association用于一对一属性,collection用于一对多属性

  3. log4j.properties

    日志记录的配置文件
    官方有四种配置方式:xml、json、yaml 和 Properties
    我采用的是第四种配置,详细配置和其他方式配置请参考[apache官网]
    基本配置:
    ''# 1. rootLogger: all trace debug info warn error fatal off
    '' log4j.rootLogger = WARN, console
    '' log4j.logger.demo = WARN
    ''
    '' # 2. appender
    '' log4j.appender.console = org.apache.log4j.ConsoleAppender
    ''
    '' # 3. layout
    '' log4j.appender.console.layout = org.apache.log4j.PatternLayout
    '' log4j.appender.console.layout.ConversionPattern = %d\t%p\t%c{1}\t%m%n

  4. mybatis-config.xml

    此文件其实不需要,因为可以集成到application.xml中(个人理解)
    简单配置
    ''<?xml version="1.0" encoding="UTF-8"?>
    '' <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
    ''
    ''
    ''
    ''
    ''

  5. application.xml

    我个人认为这里替代了mybatis-config.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"
    '' xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
    '' <context:property-placeholder location="classpath:jdbc.properties"/
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''
    ''

  6. web.xml

    webapp / WEB-INF / web.xml
    ''<?xml version="1.0" encoding="UTF-8"?>
    '' <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    '' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    '' xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    '' version="4.0">
    ''
    ''
    '' encoding
    '' org.springframework.web.filter.CharacterEncodingFilter
    ''
    ''
    '' encoding
    '' /
    ''
    ''
    ''
    ''
    '' cors
    '' project.util.Cross_domain_access
    ''
    ''
    '' cors
    '' /
    ''
    ''
    ''
    ''
    '' web
    '' org.springframework.web.servlet.DispatcherServlet
    ''
    ''
    '' web
    '' /
    ''
    ''
    ''
    ''
    '' default
    '' .html
    '' .css
    '' .js
    '' .ico
    '' /static/*
    ''
    ''
    ''
    ''
    '' org.springframework.web.context.ContextLoaderListener
    ''
    ''
    '' org.springframework.web.context.request.RequestContextListener
    ''
    ''
    '' contextConfigLocation
    '' classpath:applicationContext.xml
    ''
    ''
    ''

  7. web-servlet.xml

    webapp / WEB-INF / web-servlet.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:mvc="http://www.springframework.org/schema/mvc"
    '' xmlns:context="http://www.springframework.org/schema/context"
    '' xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    ''
    ''
    ''
    ''
    ''
    ''
    以上就是基础环境的配置过程,谢谢观看。END

转载于:https://www.cnblogs.com/wgh0807/p/10308433.html

spring mvc + mybatis 框架搭建 ( idea + gradle)相关推荐

  1. SSM框架(Spring + Spring MVC + Mybatis)搭建

    Spring是一个轻量级的框架,用到了注解和自动装配,就是IOC和AOP: SpringMVC是Spring实现的一个Web层,相当于Struts的框架: Mybatis是 一个持久层的框架,在使用上 ...

  2. Spring MVC + Mybatis项目搭建

    1.参考<Java Spring MVC项目搭建(一)--Spring MVC框架集成>配置spring mvc需要的jar包及eclipse配置(主要是针对servlet-api.jar ...

  3. Spring+SpringMVC+MyBatis框架搭建-----详细教程

    1.基本概念 1.1Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J ...

  4. 使用Spring MVC,Mybatis框架等创建Java Web项目时各种前期准备的配置文件内容

    1.pom.xml 首先,pom.xml文件,里面包含各种maven的依赖,代码如下: <project xmlns="http://maven.apache.org/POM/4.0. ...

  5. Spring+SpringMVC+Mybatis框架搭建

    一.项目结构及所需jar包 1.1.项目结构 1.2依赖jar包(含json-lib. log4j.Junit) 二.配置文件 2.1.web.xml配置 <?xml version=" ...

  6. 基于ssm框架的论坛系统(Spring,Spring MVC,MyBatis)

                                                                 基于ssm框架的论坛系统 1.介绍 本论坛系统基于spring,spring ...

  7. SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一)

    SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一) 1. 前言 最近在写毕设过程中,重新梳理了一遍SSM框架,特此记录一下. 附上源码:https://gitee ...

  8. SSM框架超级详细整合记录:Spring+Spring MVC+MyBatis+Maven+MySQL

    1.前言 本文主要对SSM框架整合的过程进行记录,作为之后参考的依据. 1.1.参考文章 Spring代码实例系列-绪论 Spring MVC代码实例系列-绪论 MyBatis代码实例系列-绪论 1. ...

  9. 超详细整合SSM框架--(Spring + Spring MVC + MyBatis)

    超详细整合SSM框架--(Spring + Spring MVC + MyBatis) SpringMVC框架--文章跳转 Spring框架--文章跳转 Mybatis框架--文章跳转 整合思路 设计 ...

最新文章

  1. 在线翻译系统属于计算机应用领域中,【单选题】网状物编织物和机件上的滚花部分,可以在轮廓线附件用( )线示意画出...
  2. Tungsten Fabric SDN — Netronome Agilio SmartNIC vRouter
  3. LAMP架构之个人博客搭建
  4. java元婴期(24)----java进阶(mybatis(3)---动态sql(重点))
  5. python flask 大文件 下载_flask - python上传大文件到服务器报错
  6. where嵌套select_Select子查询:Select Zoo
  7. *【2019牛客暑期多校训练营(第三场)- G】Removing Stones(分治)
  8. python最简单的账号密码验证_Python之简单的用户名密码验证
  9. Django--ORM基本操作
  10. MSSMS18闪退解决方法
  11. eclipse没有server选项
  12. TextWatcher实现输入关键字筛选数据
  13. python电脑怎么运行_如何运行python文件
  14. 计算机应用于设计,计算机工程与设计期刊_计算机工程与设计_计算机工程与应用...
  15. 拷贝相关器 matlab,基于MELP的水下实时语音通信机的研究与实现
  16. 基于曲线插值的规划方法(Interpolating Curve Planners)
  17. 使用Markdown输出LaTex数学公式
  18. hdoj-1593-find a way to escape【数学题】
  19. golang flow工作流引擎-自己挖坑自己填
  20. 如何用单片机控制语音芯片?语音芯片该如何选择?唯创知音来推荐

热门文章

  1. JS传中文到后台需要的处理
  2. c++中的对象引用(object reference)与对象指针的区别
  3. Ubuntu手机系统会成为第四大手机系统吗
  4. 如何终止正在在发送的ajax请求
  5. 如果你的云服务商倒闭该怎么办?
  6. smarty_modifier_truncate,无或者有md_substr的情况下都能正确截取字符串的php函数,可用于smarty。...
  7. linux内核 semaphore,2.4内核里semaphore源码的一个疑问
  8. 安卓手机格式化怎么弄_安卓手机无法启动如何进行格式化
  9. forkjoin rxjs_如何通过吃披萨来理解RxJS运算符:zip,forkJoin和Combine
  10. HTML的标签分为哪几类?各标签语法格式是怎样的?