1.springmvc整合到当前的测试案例
1.1依赖
spring-web
spring-webmvc
jackson需要的依赖(将返回的对象以json输出)通过@responseBody实现
public User queryOne(){
return new User();}
{" “:” “,” ":[{},{}]}
由对象转化为json字符串,需要引入第三方jar包–jackson.jar
1.2spring.xml配置springmvc需要的内容
没有页面
开启注解驱动
soring.xml
@requestMapping
@responseBody
@ReqestBody
@RequestParam
@PathVariable
基本流程:
静态页面
需要关闭dispatcherServlet 对静态资源的拦截
mapping *.xml
星.do
/星
如果有页面的跳转需要配置视图解析器
prefix suffix(web应用中没有后端工程的页面跳转功能)
1.3controller
根据请求路径编写测试代码
基于user的测试案例
localhost:8080/query?id=1
@requestmapping(value=“query”,method=RequestMethod.GET/POST/PUT/DELETE)
注意:@RestController//controller和responsebody的结合
1.4web容器启动
右键项目run as(mvn install)打成war包,进行测试(只是输出json,不需要配置视图解析器)但是要把test单元测试全部注释掉,否则无法打成war包,会报错
如果环境没有修改jdk1.8 保持jre1.8会报错,提示you run jre not jdk
需要修改eclipse的java环境为jdk
修改已经创建的工程的3个配置内容
右键工程–preferences
1.5web.xml的配置
ssm框架在web容器启动时,启动调用的逻辑
dispatcherservlet的配置
加载spring.xml文件
复制war包到tomcat的webapps下
开启tomcat运行,输入网址即可运行,输出json字符串
也可以使用eclipse自带的tomcat,需要进行配置
通过tomcat插件启动当前ssm需要调用mvn 命令 mvn tomcat7:run
方法一:找到ssm项目文件,调用指令
方法二:在eclipse中调用指令运行
1.6eclipse执行maven命令的配置
自定义maven build中实现的各种命令对项目的配置可在下图中找到管理窗口
配置:
<build>
<finalName>ssm</finalName>
<!-- maven tomcat7 -->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--port -->
<port>8090</port>
<!-- contextpath -->
<path>/</path>
<!--receive utf-8 -->
<uriEncoding>utf-8</uriEncoding>
<useBodyEncodingForURI>utf-8</useBodyEncodingForURI>
</configuration>
</plugin>
</plugins>
</build>
代码实现:
上一天的基础上加入springmvc
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>ssm</display-name>
<!--dispatcherservlet -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--init param spring.xml -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring.xml
加入的springmvc的扫描
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:P="http://www.springframework.org/schema/P"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/P
http://www.springframework.org/schema/P/spring-P-3.2.xsd
" >
<!--扫描的基础路径cn.tedu 扫描所有以cn.tedu开始的包路径 -->
<!--扫描的基础路径cn.tedu.web.service -->
<context:component-scan base-package="cn.tedu"/>
<!--准备一个数据源对象 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!-- url -->
<property name="url" value="jdbc:mysql:///easymall"></property>
<!-- 注册驱动类 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<!-- 登录数据库的用户名和密码 -->
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!-- sqlsession -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--导入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!--mybatis的配置文件 准备出来 否则无法加载 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!--mapper映射文件的扫描 扫描使用*通配 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
<!--别名包 resultType domain entity dto vo pojo -->
<property name="typeAliasesPackage" value="cn.tedu.domain"></property>
</bean>
<!--扫描动态代理调用sqlsession -->
<!--实现接口类的方法 提供接口类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--扫描的包路径 cn.tedu.mapper -->
<property name="basePackage" value="cn.tedu.mapper"></property>
</bean>
<!--开启springmvc的注解驱动 -->
<mvc:annotation-driven/>
</beans>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.tedu</groupId>
<artifactId>ssm</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ssm Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies><dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!--spring jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!--mysql 数据库 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
<!--德鲁伊连接数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.14</version>
</dependency>
<!--mybatis 相关的两个配置 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!--springmvc的依赖包两个 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>ssm</finalName>
<!-- maven tomcat7 -->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--port -->
<port>8090</port>
<!-- contextpath -->
<path>/</path>
<!--receive utf-8 -->
<uriEncoding>utf-8</uriEncoding>
<useBodyEncodingForURI>utf-8</useBodyEncodingForURI>
</configuration>
</plugin>
</plugins>
</build>
</project>
页面的效果和思路
1.1用户积分的查询
页面发起请求
ssm框架接收请求地址
处理业务逻辑:根据userid的值到数据库查询一个用户对应的积分数据
返回给Ajax使用
1.2订单的支付及积分的更新
页面发起请求
ssm接受请求,根据参数查询订单的信息,(拿到金额执行支付)
业务逻辑:根据支付的金额对当前订单所述的用户进行积的更新
返回Ajax失败或者成功(事务柔性事务)
2.demo工程
功能及怎么实现,内容大概
用户的积分查询
js代码阅读
接口文件(技术对接规范,沟通的内容)
功能:订单支付和积分的查询
2.1准备一个与ssm相同的配置的工程
2.2需要将静态页面的资源拷贝到当前的工程(此处没有资源,自行构造环境,达到所需的需求)
2.3创建数据库的表格
t_order表格
order_id 主键 varchar类型
order_money 订单金额 int
user_id 外键关联字段 int
t_user表格
user_id 主键 int
lev 用户的等级 int 0 普通用户 1 银牌用户
ponts 积分数值 int\
向表格中添加数据
2.4添加框架支持的配置
springmvc的dispatcherservlet放开对静态文件的拦截(css,js,html),在项目spring.xml中添加一个resources的配置,两个属性 location 静态文件存放在根目录 / ,mapping 访问路径满足mapping的要求时只要是静态文件后缀.js .css .html 都不归dispatcherservlet负责
<!--当前系统访问静态资源的配置 *一级 /js **多级/a/js /a/b/js -->
<mvc:resources location="/" mapping="/**"/>
mybatis支持的驼峰命名的规则配置
sql语句解决字段和属性间的对应关系
User userId lev ponits
Order orderId orderMoney userId
user_id lev points
order_id orderMoney
第一种方法(普通的处理)
select user_id userId from t_user where id=1;
第二种方法:
resultMap="USERRM"
<properties name="userId" column="user_id">
第三种方法:
select * from t_user;
需要在mybatis的配置文件中实现驼峰命名的对应规则,它会将字段名称user_id,user-id,order_id,order-id自动和驼峰规则的属性名称匹配userId orderId
<configuration>
<!--在setting中实现驼峰规则,和关闭缓存 -->
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="cacheEnabled" value="false"/>
</settings>
</configuration>
2.5编写功能:
编写架子(controller service mapper)
OrderUserMapper.xml(命名空间对应接口的全路径名称,和标签的id对应正确,否则报invalid bound statement)
代码实现:
package cn.tedu.domain;
public class Order {
private String orderId;
private Integer orderMoney;
private Integer userId;
public Order(String orderId, Integer orderMoney, Integer userId) {
super();
this.orderId = orderId;
this.orderMoney = orderMoney;
this.userId = userId;
}
public Order() {
super();
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public Integer getOrderMoney() {
return orderMoney;
}
public void setOrderMoney(Integer orderMoney) {
this.orderMoney = orderMoney;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
@Override
public String toString() {
return "Order [orderId=" + orderId + ", orderMoney=" + orderMoney + ", userId=" + userId + "]";
}
}
package cn.tedu.domain;
public class User {
private Integer userId;
private Integer points;
private Integer lev;
public User(Integer userId, Integer points, Integer lev) {
super();
this.userId = userId;
this.points = points;
this.lev = lev;
}
public User() {
super();
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getPoints() {
return points;
}
public void setPoints(Integer points) {
this.points = points;
}
public Integer getLev() {
return lev;
}
public void setLev(Integer lev) {
this.lev = lev;
}
@Override
public String toString() {
return "User [userId=" + userId + ", points=" + points + ", lev=" + lev + "]";
}
}
package cn.tedu.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/**
* 处理当前案例中的所有请求(两个)
* 返回数据全部交给Ajax使用所以没有页面跳转的功能,需要使用responseBody
* 将数据完整的返回给ajax
*
*
*/
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.tedu.domain.User;
import cn.tedu.service.OrderUserService;
@RestController
public class OrderUserController {
@Autowired
private OrderUserService ouService;
//用户积分查询
@RequestMapping(value="user/query/point")
public User queryUserPoints(Integer userId){
//select * from t_user where id=#{userId}
User user=ouService.queryUserPoints(userId);
return user;
}
//order订单的支付和积分更新访问接收
@RequestMapping("order/pay")
public Integer orderPay(String orderId){
//只关心成功和失败
try {
ouService.orderPay(orderId);
return 1;
} catch (Exception e) {
e.printStackTrace();
//进入到catch说明调用的业务层逻辑出现问题
return 0;//表明失败
}
}
}
package cn.tedu.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.tedu.domain.Order;
import cn.tedu.domain.User;
import cn.tedu.mapper.OrderUserMapper;
@Service
public class OrderUserService {
@Autowired
private OrderUserMapper ouMapper;
public User queryUserPoints(Integer userId) {
return ouMapper.selectUserById(userId);
}
public void orderPay(String orderId) {
/**
* 代码思路
* 1.做支付逻辑;打印支付的金额
* 将订单金额查询,打印(order)
* select * from t_order where order_id=#{orderId}
* 2.根据金额做用户的积分更新(order 查询出的用户id)
* update set t_user points=points+#{points}
* where user_id=#{userId}
*
*/
//查询订单
Order order=ouMapper.selectOrderById(orderId);
//用户1支付了5000/6000/9000
System.out.println("用户"+order.getOrderId()+"支付了"+order.getOrderMoney()+"元");
//更新积分,将所有sql的参数封装到user对象
User paramUser=new User();
paramUser.setUserId(order.getUserId());
paramUser.setPoints(order.getOrderMoney());
//执行更新
ouMapper.updateUserPointsById(paramUser);
}
}
package cn.tedu.mapper;
import org.springframework.stereotype.Repository;
import cn.tedu.domain.Order;
import cn.tedu.domain.User;
@Repository
public interface OrderUserMapper {
User selectUserById(Integer userId);
void updateUserPointsById(User paramUser);
Order selectOrderById(String orderId);
}
配置文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.tedu</groupId>
<artifactId>SSM-DEMO02</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SSM-DEMO02 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies><dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!--spring jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!--mysql 数据库 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
<!--德鲁伊连接数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.14</version>
</dependency>
<!--mybatis 相关的两个配置 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!--springmvc的依赖包两个 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>SSM-DEMO02</finalName>
<!-- maven tomcat7 -->
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--port -->
<port>8090</port>
<!-- contextpath -->
<path>/</path>
<!--receive utf-8 -->
<uriEncoding>utf-8</uriEncoding>
<useBodyEncodingForURI>utf-8</useBodyEncodingForURI>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>SSM-DEMO02</display-name>
<!--dispatcherservlet -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--init param spring.xml -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:P="http://www.springframework.org/schema/P"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/P
http://www.springframework.org/schema/P/spring-P-3.2.xsd
" >
<!--扫描的基础路径cn.tedu 扫描所有以cn.tedu开始的包路径 -->
<!--扫描的基础路径cn.tedu.web.service -->
<context:component-scan base-package="cn.tedu"/>
<!--准备一个数据源对象 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!-- url -->
<property name="url" value="jdbc:mysql:///easymall"></property>
<!-- 注册驱动类 -->
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<!-- 登录数据库的用户名和密码 -->
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!-- sqlsession -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--导入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!--mybatis的配置文件 准备出来 否则无法加载 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!--mapper映射文件的扫描 扫描使用*通配 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
<!--别名包 resultType domain entity dto vo pojo -->
<property name="typeAliasesPackage" value="cn.tedu.domain"></property>
</bean>
<!--扫描动态代理调用sqlsession -->
<!--实现接口类的方法 提供接口类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--扫描的包路径 cn.tedu.mapper -->
<property name="basePackage" value="cn.tedu.mapper"></property>
</bean>
<!--开启springmvc的注解驱动 -->
<mvc:annotation-driven/>
<!-- 开发当前系统访问静态资源的配置 -->
<!--当前系统访问静态资源的配置 *一级 /js **多级/a/js /a/b/js -->
<!-- <mvc:resources location="/" mapping="/**"/> -->
</beans>
<?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">
<configuration>
<!--在setting中实现驼峰规则,和关闭缓存 -->
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="cacheEnabled" value="false"/>
</settings>
</configuration>
<?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">
<mapper namespace="cn.tedu.mapper.OrderUserMapper">
<!-- selectUserById -->
<select id="selectUserById" parameterType="int" resultType="User">
select * from t_user where user_id=#{userId};
</select>
<!--selectOrderById -->
<select id="selectOrderById" parameterType="String" resultType="Order">
select * from t_order where order_id=#{orderId};
</select>
<update id="updateUserPointsById" parameterType="User" >
update t_user set points=points+#{points} where user_id=#{userId};
</update>
</mapper>
常见的问题:
1.eclipse加载工程不完整
问题描述:编写的工程代码在eclipse关闭后重启总总是出现红叉
原因:eclipse加载工程的各种配置文件 .setting
eclipse中的视图标签problems
window–show view —problem
明确提示红叉的详细信息
2.提示invalid bound statement
描述问题:
当执行测试方法,验证从数据库进行增删查改的操作时,提示错误, invalid bound statement
原因(只有两个)
映射文件namespace 没有指定正确的接口类的全路径名称
标签的id值和方法名称不同
总结:
接口文件
规范文档(需求文档、开发规范)
沟通内容的定义
代码结构
单体项目的问题:
1.什么是单体项目
当一个系统的所有功能都集中在一个应用中时,这个系统就是单体的系统。
order-user有两个功能
2.单体项目的缺点
2.1并发不高(nginx解决)
并发:同时访问一个系统的请求的个数
单位时间并发(一分钟多少)
tomcat容器 200-500/秒
2.2功能强耦合并发集中
功能强耦合
一个系统的所有功能集中到一起,引起了功能间的强耦合,导致需求人员对需求业务的处理复杂度提高
并发集中
例如:双十一,订单系统的奔溃,访问商品,可以注册用户,可以添加购物车
3.解决上述问题
3.1并发扩展(nginx)
nginx:比maven的地位高,比redis,es,rabbitmq mycat地位低
应用它的功能(负载均衡,动态分离)
3.2项目的拆分
最终实现的是微服务的框架,解决功能强耦合,并发集中的问题
springboot
springcloud
单机的nginx在cpu性能足够的情况下,5万-7万的并发
引入前端网络搭建的nginx集群,配合IP入口服务器,dns服务器的配置,实现网络入口的扩大
负载均衡的逻辑:
物理均衡:平均分配所有的访问请求
逻辑均衡:根据服务器的性能均衡有占比的访问
互联网框架中的作用
负载均衡
负载:高并发的访问压力负重,载重
均衡:平均分配,后端服务器(后端服务器集群)
动静分离
静态资源img、css js html 等可以放到nginx中被客户端访问,后端服务器专心处理动态数据,nginx专心处理静态文件数据—动静分离
断点:
扩展:maven工程里的debug模式