架构:第三章:单一(伪分布式)架构之SSM整合,索引为什么能提供查询性能

commons-fileupload

commons-fileupload

1.3.1

jstl

jstl

1.2

junit

junit

4.12

test

javax.servlet

servlet-api

2.5

provided

javax.servlet.jsp

jsp-api

2.1.3-b06

provided

建库建表SQL

CREATE DATABASE IF NOT EXISTS atcrowdfunding CHARACTER SET utf8 COLLATE utf8_bin;

USE atcrowdfunding;

create table IF NOT EXISTS t_user

(

id int not null auto_increment,

loginacct varchar(255) not null,

userpswd char(32) not null,

username varchar(255) not null,

email varchar(255) not null,

createtime char(19),

primary key (id)

);

Mybatis相关

MyBatis配置文件

文件名:mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?>

在这里插入图片描述

创建MyBatis逆向工程

在其他工程之外创建另外一个工程

在这里插入图片描述

pom.xml设定

4.0.0

com

reverse

0.0.1-SNAPSHOT

org.mybatis

mybatis

3.2.8

org.mybatis.generator

mybatis-generator-maven-plugin

1.3.0

org.mybatis.generator

mybatis-generator-core

1.3.2

com.mchange

c3p0

0.9.2

mysql

mysql-connector-java

5.1.8

逆向工程配置文件:generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?>

<jdbcConnection driverClass=“com.mysql.jdbc.Driver”

connectionURL=“jdbc:mysql://localhost:3306/atcrowdfunding” userId=“root”

password=“root”>

<javaModelGenerator targetProject=".\src\main\java"

targetPackage=“com.entity”>

<sqlMapGenerator targetProject=".\src\main\java"

targetPackage=“com.component.mapper”>

<javaClientGenerator type=“XMLMAPPER”

targetProject=".\src\main\java" targetPackage=“com.component.mapper”>

生成资源的Maven命令:mybatis-generator:generate

在这里插入图片描述在这里插入图片描述在这里插入图片描述

资源归位F5刷新项目

在这里插入图片描述

复制文件到其他项目

在这里插入图片描述

![在这里

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享

插入图片描述](https://img-blog.csdnimg.cn/20181210183331211.png)

在这里插入图片描述

Spring和MyBatis整合

在common工程加入Spring和MyBatis整合需要的依赖

pom.xml

org.springframework

spring-orm

cglib

cglib

org.aspectj

aspectjweaver

org.codehaus.jackson

jackson-mapper-asl

mysql

mysql-connector-java

com.alibaba

druid

org.mybatis

mybatis

org.mybatis

mybatis-spring

log4j

log4j

org.slf4j

slf4j-api

org.slf4j

slf4j-log4j12

在ui-manger项目中加入

jdbc.properties

jdbc.user=root

jdbc.password=root

jdbc.url=jdbc:mysql://localhost:3306/atcrowdfunding?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8

jdbc.driver=com.mysql.jdbc.Driver

jdbc.initialSize=20

jdbc.minIdle=10

jdbc.maxActive=50

jdbc.maxWait=10000

jdbc.timeBetweenEvictionRunsMillis=60000

jdbc.minEvictableIdleTimeMillis=300000

jdbc.testWhileIdle=true

log4j.properties

For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!

For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.

DEBUG < INFO < WARN < ERROR < FATAL

log4j.rootLogger=DEBUG, a, logfile

log4j.appender.a=org.apache.log4j.ConsoleAppender

log4j.appender.a.layout=org.apache.log4j.PatternLayout

log4j.appender.a.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,S} %-5p [%c] %l - %m%n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender

log4j.appender.logfile.File=D:/atcrowdfunding.log

log4j.appender.logfile.MaxFileSize=512KB

Keep three backup files.

log4j.appender.logfile.MaxBackupIndex=3

Pattern to output: date priority [category] - message

log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

spring-tx.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”

xmlns:tx=“http://www.springframework.org/schema/tx”

xmlns:aop=“http://www.springframework.org/schema/aop”

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-4.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

<context:property-placeholder location=“classpath:jdbc.properties”/>

<context:component-scan base-package=“com.component.service.impl”/>

<bean id=“dataSource”

class=“com.alibaba.druid.pool.DruidDataSource”>

<property name=“timeBetweenEvictionRunsMillis”

value="${jdbc.timeBetweenEvictionRunsMillis}" />

<property name=“minEvictableIdleTimeMillis”

value="${jdbc.minEvictableIdleTimeMillis}" />

aop:config

<aop:pointcut expression=“execution(* *…Service.(…))” id=“txPointCut”/>

<aop:advisor advice-ref=“txAdvice” pointcut-ref=“txPointCut”/>

</aop:config>

<tx:advice id=“txAdvice” transaction-manager=“transactionManager”>

tx:attributes

<tx:method name=“get*” read-only=“true”/>

<tx:method name=“list*” read-only=“true”/>

<tx:method name=“count*” read-only=“true”/>

<tx:method name=“remove*” rollback-for=“java.lang.Exception” propagation=“REQUIRES_NEW”/>

<tx:method name=“save*” rollback-for=“java.lang.Exception” propagation=“REQUIRES_NEW”/>

<tx:method name=“update*” rollback-for=“java.lang.Exception” propagation=“REQUIRES_NEW”/>

</tx:attributes>

</tx:advice>

测试类

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations=“classpath:spring-tx.xml”)

public class AtCrowdfundingTest {

@Autowired

private DataSource dataSource;

@Test

public void testDataSource() throws SQLException {

Connection connection = dataSource.getConnection();

System.out.println(connection);

}

}

将spring-tx.xml,jdbc.properties文件放到测试src/test/resources下

如果出现下列错误

在这里插入图片描述

发现报错add添加junit.jar和spring-test

在这里插入图片描述

或者在ui-manger项目的pom.xml文件中

4.0.0

com

parent

0.0.1-SNAPSHOT

ui-manager

war

junit

junit

com

component

0.0.1-SNAPSHOT

org.springframework

spring-test

如果还有报错

在这里插入图片描述

在common项目的pom.xml中添加

org.springframework

spring-webmvc

在这里插入图片描述

在这里插入图片描述

Spring和SpringMVC整合

创建SpringMVC的配置文件

spring-mvc.xml

在common工程中加入Web开发相关依赖,之前如果添加过就不用再添加了

org.springframework

spring-webmvc

jstl

jstl

在这里插入图片描述

在ui-manger工程加入Web开发相关依赖

javax.servlet

servlet-api

provided

javax.servlet.jsp

jsp-api

provided

在spring-mvc.xml中加入名称空间

在这里插入图片描述

在这里插入图片描述

配置spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>

<context:component-scan base-package=“com.component.handler”/>

mvc:annotation-driven/

mvc:default-servlet-handler/

在web.xml中配置

在这里插入图片描述web.xml

<?xml version="1.0" encoding="UTF-8"?>

ui-manager

contextConfigLocation

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值