idea创建spring boot+mybatis(oracle)+themeleaf项目
1.新建项目
选择idea已经有的spring initializr
next,然后填写项目命名,包名
然后next,选择所需要的依赖
然后一路next,finish,项目新建成功,然后可以删除下面的三个文件和包,没卵用,删掉看的舒服
然后就是建项目结构,上面java包下的可以直接new--package,但是resources的直接new--directory会变成如下的长的的包名,所以需要设置一下,点击上面的那个小齿轮,然后将下图的设置的 √ 去掉,然后就可以直接new--directory就是树状结构了
完整的项目结构是这样的
2.添加依赖和其他配置
pom.xml:注释的是freemarker的模板依赖以及mysql的依赖,有需要的可以换成这个或其他的,然后还配了一些热部署,以及扫描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>prvi.chen</groupId>
<artifactId>springdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>spring-demo</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-freemarker</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.1.0</version>
</dependency>
<!--<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin> <plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins> <resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<!-- 是否替换资源中的属性-->
<filtering>false</filtering>
</resource>
</resources>
</build> </project>
SpringbootDemoApplication:程序入口,顺便配置扫描包,项目运行的时候直接run或者debug这个就行了
package com.jsiec; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; @SpringBootApplication
@MapperScan("com.jsiec.mapper")
@ComponentScan({"com.jsiec.controller","com.jsiec.service"})
public class SpringbootDemoApplication { public static void main(String[] args) {
SpringApplication.run(SpringbootDemoApplication.class, args);
}
}
application.properties:这个是配置文件,可以配置数据库相关设置,包括数据库连接池设置(我没配连接池),然后还有一些模板加载页的配置之类的
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL
spring.datasource.username=DEMO
spring.datasource.password=123456789 ########################################################
###THYMELEAF (ThymeleafAutoConfiguration)
########################################################
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
#spring.thymeleaf.encoding=UTF-8
# ;charset=<encoding> is added
#spring.thymeleaf.content-type=text/html
# set to false for hot refresh
#页面热加载
spring.thymeleaf.cache=false #修改tomcat的默认的端口号,将8080改为8888
server.port=
controller:几种传参方法,自己挑一种用用,里面的一些mapper,entity是mybatis自动生成的,就不放了
package priv.chen.controller; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import priv.chen.entity.Test;
import priv.chen.entity.User;
import priv.chen.mapper.TestMapper;
import priv.chen.mapper.UserMapper; import java.util.List;
import java.util.Map; /**
* Created by Administrator on 2017/12/19.
*/
@Controller
@RequestMapping("/test")
public class TestController {
@Autowired
private UserMapper userMapper;
@Autowired
private TestMapper testMapper;
@RequestMapping("/index")
public Object index(){
return "index";
} @ResponseBody
@RequestMapping("/hello")
public Object hello(){
return "say hello";
} @RequestMapping("/world")
public Object world(Model model) {
model.addAttribute("name", "张一");
return "/test/world";
} @RequestMapping("/getUser")
public Object getUser(Model model,User user){
List<User> list = userMapper.getAll(user);
Test test = testMapper.selectByPrimaryKey("1");
model.addAttribute("list",list);
model.addAttribute("test",test);
return "/test/test";
} @RequestMapping("/test1")
public String test1(Test test){
test = testMapper.selectByPrimaryKey("1");
return "/test/test";
}
@RequestMapping("/test2")
public String test2(Map<String,Object> map){
map.put("name", "张二");
return "/test/test";
}
@RequestMapping("/test3")
public String test3(ModelMap modelMap){
modelMap.addAttribute("name","张三");
return "/test/test";
}
@RequestMapping("/test4")
public String test4(Model model){
model.addAttribute("name","张四");
return "/test/test";
}
@RequestMapping("/test5")
public String test5(ModelMap modelMap){
modelMap.put("name","张五");
return "/test/test";
}
@RequestMapping("/test6")
public String test6(User user,Map< String, Object> map){
List<User> list = userMapper.getAll(user);
map.put("list",list);
return "/test/test";
} }
然后就html页面,用的是themeleaf,注释的是用的其他传参方法
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
</head>
<body>
<!--<div>
姓名:<span th:text="${test.name}"></span><br/>
</div>-->
<!--<div>
姓名:<span th:text="${name}"></span><br/>
</div>-->
<div th:each="user:${list}">
姓名:<span th:text="${user.name}"></span><br/>
</div>
</body> </html>
下面是运行效果:
最后放一张图
idea创建spring boot+mybatis(oracle)+themeleaf项目的更多相关文章
- 在Idea创建Spring Boot + MyBatis的web项目
创建步骤如下 选择Spring initializr 2. 修改group 与 atifact id,点击next 3. dependencies里面选择Web->Web , SQL -> ...
- Spring框架学习笔记(8)——spring boot+mybatis plus+mysql项目环境搭建
之前写的那篇Spring框架学习笔记(5)--Spring Boot创建与使用,发现有多小细节没有提及,,正好现在又学习了mybatis plus这款框架,打算重新整理一遍,并将细节说清楚 1.通过I ...
- Spring Boot + MyBatis 多模块项目搭建教程
一.前言 1.开发工具及系统环境 IDE:IntelliJ IDEA 2020.2.2 系统环境:Windows 2.项目目录结构 biz层:业务逻辑层 dao层:数据持久层 web层:请求处理层 二 ...
- Spring boot + mybatis + oracle代码生成器
在pom文件中加入依赖: <build> <plugins> <!--逆向工程--> <plugin> <groupId>org.mybat ...
- IDEA 创建spring boot 的Hello World 项目
1.Open IDEA,choose "New-->Project" 2.Choose "Spring Initializr" 3. Choose jav ...
- IntelliJ IDEA 创建spring boot 的Hello World 项目
1.Open IDEA,choose "New-->Project" 2.Choose "Spring Initializr" 3. Choose jav ...
- [七月挑选]使用idea创建spring boot 项目
title: 使用idea创建spring boot 项目 参考lindaZ的IntelliJ IDEA 创建spring boot 的Hello World 项目 1.Open IDEA,choos ...
- (4)Maven快速入门_4在Spring+SpringMVC+MyBatis+Oracle+Maven框架整合运行在Tomcat8中
利用Maven 创建Spring+SpringMVC+MyBatis+Oracle 项目 分了三个项目 Dao (jar) Service (jar) Controller (web) ...
- Spring boot Mybatis整合构建Rest服务(超细版)
Springboot+ Mybatis+MySql整合构建Rest服务(涵盖增.删.改.查) 1.概要 1.1 为什么要使用Spring boot? 1.1.1 简单方便.配置少.整合了大多数框架 ...
随机推荐
- SystemC_Basic
1.http://baike.baidu.com/view/1018980.htm 百度百科介绍的很好,举例很清晰. 2.SystemC的三个基本进程:SC_METHOD,SC_THREAD,SC_C ...
- python网络爬虫《爬取get请求的页面数据》
一.urllib库 urllib是python自带的一个用于爬虫的库,其主要作用就是可以通过代码模拟浏览器发送请求.其常被用到的子模块在python3中的为urllib.request和urllib. ...
- 模板】AC自动机(简单版)
模板]AC自动机(简单版) https://www.luogu.org/problemnew/show/P3808 这是一道简单的AC自动机模板题. 用于检测正确性以及算法常数. 为了防止卡OJ,在保 ...
- 【校招面试 之 C/C++】第33题 C++ 11新特性(四)之STL容器
C++ 11新增array.forward_list(单链表).unordered_set.unordered_map集中容器.
- task 定时设置
每天凌晨2点 0 0 2 * * ?和每天隔一小时 0 * */1 * * ? 例1:每隔5秒执行一次:*/5 * * * * ? 例2:每隔5分执行一次:0 */5 * * * ? 在26分.29 ...
- 可变数据类型&不可变数据类型
不同的变量在内存中有不同的存储空间,每个存储空间都有一个ID >>> a = 32 >>> id(a) # 查看ID 1571185856 >>> ...
- QQ分享登陆报错
linker command failed with exit code 1 (use -v to see invocation)报错原因 builtSetting下搜索 bitco 改为NO
- 软件开发中 SQL SERVER 任务的用法
在软件开发中,经常性会用到定时任务.这个时候你可能会想到线程.但是事实中,线程方法比较麻烦.容易出错,资源竞争等问题,设计起来让你很头痛. 现在给大家提供一个新的思路,用SQL SERVER 的任务管 ...
- Liunx cp
功能: 复制文件或目录 使用权限:所有使用者说明: cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中.若同 ...
- 反射中,Class.forName 和 classloader 的区别
https://blog.csdn.net/qq_27093465/article/details/52262340 java中class.forName()和classLoader都可用来对类进行加 ...