多平台统一管理软件接口,如何实现多平台统一管理软件接口
210
2022-11-23
使用IDEA搭建ssm框架的详细图文教程
ssm(spring springMVC mybatis)
1.创建项目
file->new->project
2.新建的maven项目目录结构
添加ssm需要的文件夹等
如果去掉java文件夹的蓝色标志,会发现这里new时不能创建java类或包
如果main/java前不是蓝色文件夹或test/java前不是绿色文件夹,可以这样添加
3.加入maven依赖
pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <dependency>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<dependency>
4.加入spring配置文件(applicationContext.xml)
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context" xmlns:aop="http://springframework.org/schema/aop" xmlns:tx="http://springframework.org/schema/tx" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop.xsd http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx.xsd">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:context="http://springframework.org/schema/context"
xmlns:aop="http://springframework.org/schema/aop" xmlns:tx="http://springframework.org/schema/tx"
xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/aop http://springframework.org/schema/aop/spring-aop.xsd http://springframework.org/schema/tx http://springframework.org/schema/tx/spring-tx.xsd">
5.配置数据库连接相关信息(dbconfig.properties)
#数据库连接
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm-crud?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
#加载驱动
jdbc.driverClass=com.mysql.cj.jdbc.Driver
#数据库登录用户名
jdbc.user=root
#密码
jdbc.password=root
6.mybatis配置文件(mybatis-config.xml)
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
注意:这里要建个mapper空文件,因为spring的配置文件applicationContext.xml
中有一项配置要扫描这个文件夹下的所有映射文件
7.配置web.xml文件
web.xml
项目启动,先加载web.xml文件的配置
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
8.配置spring mvc配置文件(dispatcherServlet-servlet.xml)
spring mvc就是充当控制器,替代servlet
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:context="http://springframework.org/schema/context" xmlns:mvc="http://springframework.org/schema/mvc" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc.xsd">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:context="http://springframework.org/schema/context"
xmlns:mvc="http://springframework.org/schema/mvc"
xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/context http://springframework.org/schema/context/spring-context.xsd http://springframework.org/schema/mvc http://springframework.org/schema/mvc/spring-mvc.xsd">
9.使用逆向工程前配置
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
connectionURL="jdbc:mysql://localhost:3306/ssm-crud?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8" userId="root" password="root">
connectionURL="jdbc:mysql://localhost:3306/ssm-crud?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8"
userId="root"
password="root">
targetProject=".\src\main\resources">
targetProject=".\src\main\resources">
targetaTXElXfEPackage="com.ssm.dao" targetProject=".\src\main\java">
targetaTXElXfEPackage="com.ssm.dao"
targetProject=".\src\main\java">
10.使用逆向工程生成接口、实体类、映射文件
MBGTest.java
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class MBGTest {
public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
List
boolean overwrite = true;
File configFile = new File("mbg.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
}
逆向工程生成
总结
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~