代码拉取完成,页面将自动刷新
<dependency>
<groupId>com.sagframe</groupId>
<artifactId>sagacity-sqltoy-spring-starter</artifactId>
<!-- jdk1.8 用5.6.4.jre8 -->
<version>5.6.4</version>
</dependency>
<!--
注意注意: 配置连接池依赖
1、druid连接池
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.21</version>
</dependency>
2、springboot自带的hikari连接池需要额外增加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>3.2.3</version>
</dependency>
-->
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yml</include>
<include>**/*.sql</include>
<include>**/*.jpg</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<includes>
<include>**/*.xml</include>
</includes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yml</include>
<include>**/*.sql</include>
</includes>
</testResource>
</testResources>
#完整路径:spring.sqltoy
spring:
sqltoy:
# 配置sql文件路径,多个用逗号分割
sqlResourcesDir: classpath:com/sqltoy/helloworld
# 默认为false,debug模式将打印执行sql,并自动检测sql文件更新并重新加载
debug: true
package com.sqltoy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
*
* @project sqltoy-helloworld
* @description helloworld 主程序入口
* @author zhongxuchen
* @version v1.0, Date:2020年7月17日
* @modify 2020年7月17日,修改说明
*/
@SpringBootApplication
@ComponentScan(basePackages = { "com.sqltoy.helloworld"})
@EnableTransactionManagement
public class SqlToyApplication {
/**
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(SqlToyApplication.class, args);
}
}
create table SQLTOY_FRUIT_ORDER
(
FRUIT_NAME varchar(100) not null comment '水果名称',
ORDER_MONTH integer not null comment '订单月份',
SALE_COUNT numeric(10,2) not null comment '销售数量',
SALE_PRICE numeric(10,2) not null comment '销售单价',
TOTAL_AMT numeric(10,2) not null comment '总金额',
primary key (FRUIT_NAME, ORDER_MONTH)
);
alter table SQLTOY_FRUIT_ORDER comment '查询汇总演示-水果订单表';
############# db config ####################
jdbc.driver_class=com.mysql.cj.jdbc.Driver
# url characterEncoding=utf-8 param is need
jdbc.url=jdbc:mysql://192.168.56.101:3306/quickstart?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false
# mysql schema=dbname,oracle schema=username
jdbc.schema=quickstart
jdbc.username=quickstart
jdbc.password=quickstart
java -cp ./libs/* org.sagacity.quickvo.QuickVOStart quickvo.xml
java -cp ./libs/\* org.sagacity.quickvo.QuickVOStart ./quickvo.xml
<?xml version="1.0" encoding="utf-8"?>
<sqltoy xmlns="http://www.sagframe.com/schema/sqltoy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sagframe.com/schema/sqltoy http://www.sagframe.com/schema/sqltoy/sqltoy.xsd">
<!-- 这里是演示,正常单表查询无需写sql -->
<sql id="helloworld_search_fruitOrder">
<value>
<![CDATA[
select * from sqltoy_fruit_order t
where #[t.FRUIT_NAME like :fruitName]
]]>
</value>
</sql>
</sqltoy>
package com.sqltoy.helloworld.service.impl;
import org.sagacity.sqltoy.dao.LightDao;
import org.sagacity.sqltoy.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sqltoy.helloworld.service.FruitOrderService;
import com.sqltoy.helloworld.vo.FruitOrderVO;
/**
* 水果订单服务逻辑实现
*
* @author zhongxuchen
* @date 2021/4/19
*/
@Service("fruitOrderService")
public class FruitOrderServiceImpl implements FruitOrderService {
// sqltoy只要注入框架自带的LightDao 就可以通过lightDao.xxx 完成全部数据库操作,具体有哪些功能可以参见LightDao
// 功能定义
@Autowired
LightDao lightDao;
@Override
public void createFruitOrder(FruitOrderVO fruitOrderVO) {
lightDao.save(fruitOrderVO);
}
@Override
public Page<FruitOrderVO> searchFruitOrder(Page pageModel, FruitOrderVO fruitOrderVO) {
return lightDao.findPage(pageModel, "helloworld_search_fruitOrder", fruitOrderVO, FruitOrder.class);
}
}
package com.sqltoy.helloworld.service;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.sagacity.sqltoy.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import com.alibaba.fastjson.JSON;
import com.sqltoy.SqlToyApplication;
import com.sqltoy.helloworld.vo.FruitOrderVO;
/**
*
* @author zhongxuchen
*
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = SqlToyApplication.class)
public class FruitOrderServiceTest {
@Autowired
FruitOrderService fruitOrderService;
@Test
public void testCreateFruitOrder() {
FruitOrderVO fruitOrder = new FruitOrderVO();
fruitOrder.setFruitName("苹果");
fruitOrder.setOrderMonth(202101);
fruitOrder.setSaleCount(BigDecimal.valueOf(100));
fruitOrder.setSalePrice(BigDecimal.valueOf(100));
fruitOrder.setTotalAmt(BigDecimal.valueOf(10000));
fruitOrderService.createFruitOrder(fruitOrder);
}
@Test
public void testSearchFruitOrder() {
FruitOrderVO fruitOrder = new FruitOrderVO();
fruitOrder.setFruitName("果");
Page pageModel = fruitOrderService.searchFruitOrder(new Page(10, 1), fruitOrder);
System.err.println(JSON.toJSONString(pageModel));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。