在resources下创建一个名为banner.txt的文件
在文件里面定义,比如
__ .__
_/ |_ ____ __ _____ __|__|____ ____
\ __\/ _ \| | \ \/ / \__ \ / \
| | ( <_> ) | /> <| |/ __ \| | \
|__| \____/|____//__/\_ \__(____ /___| /
\/ \/ \/
即可
将一个ico图片拷贝到resources下重命名为favicon即可
在pom中导入如下依赖
<dependency>
<groupId>com.alibabagroupId>
<artifactId>druid-spring-boot-starterartifactId>
<version>1.1.10version>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<scope>runtimescope>
<version>5.1.21version>
dependency>
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/apidemo?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
@SpringBootApplication
@MapperScan(basePackages ="touxian_ssm.ssm.Service.**")
public class SsmApplication {
public static void main(String[] args) {
SpringApplication.run(SsmApplication.class, args);
}
}
public class Book_type {
private Integer id;
private String typename;
private Integer sort;
private String remark;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTypename() {
return typename;
}
public void setTypename(String typename) {
this.typename = typename;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
package touxian_ssm.ssm.Service.Book;
import touxian_ssm.ssm.vo.Book_type;
import java.util.List;
/**
* @author 偷闲
* @date 2019/4/28 15:25
*/
public interface Book_typeMapper {
List<Book_type> getalltype();
}
在application.properties里面添加mybaties扫描添加如下
mybatis.mapper-locations=classpath*:/mybaties/*/*.xml
在resources下创建mybaties文件,并创建xml文件
因为springboot没有jsp依赖,所以需要自己导入,pom文件导入如下5个依赖
<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
dependency>
<dependency>
<groupId>javax.servlet.jspgroupId>
<artifactId>javax.servlet.jsp-apiartifactId>
<version>2.3.1version>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-tomcatartifactId>
dependency>
<dependency>
<groupId>org.apache.tomcat.embedgroupId>
<artifactId>tomcat-embed-jasperartifactId>
dependency>
<dependency>
<groupId>jstlgroupId>
<artifactId>jstlartifactId>
<version>1.2version>
dependency>
在main下新建webapp/jsp文件夹
给项目指定jsp所在位置
新建WebMvcConfig
使用ctrl+o重写父类中的方法
代码如下
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/jsp/",".jsp");
}
}
@Controller
public class TypeController {
@Autowired
Book_typeMapper book_typeservice;
@RequestMapping("type")
public String hello(Model mod){
List<Book_type> alltype= book_typeservice.getalltype();
mod.addAttribute("alltype",alltype);
return "type_list";
}
}
jsp里面的代码是
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
<title>Title</title>
</head>
<body>
<table style="margin-top:5px;">
<thead>
<tr>
<th class="center">序号</th>
<th class="center">名称</th>
<th class="center">备注</th>
</tr>
</thead>
<tbody>
<!-- 开始循环 -->
<c:forEach items="${alltype}" var="var" varStatus="vs">
<tr>
<td class='center' style="width: 30px;">${var.sort}</td>
<td class='center'>${var.type_name}</td>
<td class='center'>${var.remark}</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
前台访问
http://localhost:8080/type