Web Service 项目流程
- New Project - New Spring Initializer - Dependencies - Spring Boot Web | Spring Boot DevTools | JDBC API | MySQL Driver
-
数据库配置 - application.yml || application.properties
server: port: 8081 spring: datasource: url: jdbc:oracle:thin:@47.99.59.172:1521:ORCL username: ODSADM password: HWods666 driver-class-name: oracle.jdbc.driver.OracleDriver dbcp2: min-idle: 5 initial-size: 5 max-total: 5 max-wait-millis: 150 mybatis: mapper-locations: classpath:mapper/*.xml-
建立实体类 跟数据库字段保持一致
-
防止报错 创建类时添加无参构造方法
public ChartRule(){ } -
建立Mapper 接口 定义操作数据库的动作 --- 创建Java Interface 定义function 以及返回的数据类型
-
建立Mapper的XML 文件,写具体的SQL -- xml文件的基本配置
-
如果mybatis引入报错,则在pom.xml 文件中的 dependecies添加依赖
-
如果mybatis 报错URI is not registered (Settings | Lauguage & Framework | Schemas and DTDS):
File - Settings - Lauguage & Framework - Schemas and DTDs - Ignored schemas and DTDS 中添加报错的链接 - apply - ok -
select | insert | deletet | update 都可以 但注意 id 与 上一步Mapper中的function 进行匹配
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://www.mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.example.amanda.mapper.ChartRuleMapper"> <select id="findA" resultType="com.example.amanda.entity.ChartRule"> SELECT CHARTID, CHARTNAME,RULENAME FROM ODSADM.ODS_CHARTRULE </select> </mapper>
-
-
建立Service 类,处理业务逻辑在Controller 类中展示处理结果
建立Controller 类中展示处理结果
\