上一篇搭建起了大体架构,这一篇写个增删改查demo,
第三篇是完善第二篇的bug:第三篇
7、测试显示table 信息 √
(建table,在sql 里面添加几条数据,显示到页面)
8、增加热部署功能 √(自动刷新后台java,xml代码变动情况,无需手动重启,
不过idea对它支持不大友好,建议idea写完框架后用 sts(eclipse对spring包的集成)继续修改
spring.thymeleaf.cache 设为false
或者使用springboot的devtools
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
)
9、增加 redis设置 √
(这个著名的高性能sql不用多说了吧?自行安装配置)
10、加入前端框架:layUI ,bootstrap,jquery √
(前端页面为bootstrap-table)
11、写增删查改! crud √
(前台,写个隐藏域,获取id,如果id为空,执行添加;如果id有值,执行修改;实现两个功能用一个方法)
12、设置报错页面 √
13、美化页面,规范代码 √
————————————————————
效果:
目录结构:
工欲善其事必先利其器,配置几个不错的功能再写demo吧:
主页:Application.java ,这里有个跳转首页的注解方法,index主页大家自己写比较好
@Controller
@SpringBootApplication
@ServletComponentScan
@EnableScheduling
@EnableCaching
@MapperScan(basePackages = {"com.example.demo.other.MyMapper"})
//启注解事务管理
@EnableTransactionManagement
public class Application {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/"
};
@RequestMapping(value="/index",method = RequestMethod.GET)
public String showIndex(){
return "index";
}
}
一、配置pom.xml,我的仅供参考
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- 页面模板 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
&l