springboot --- 之SSM框架整合

2021-07-06 02:05

阅读:488

标签:rac   jar   boot   上下   user   thymeleaf   生效   jdb   templates   

1.pom依赖:
即:spring-boot的基本jar ---- 内置springmvc和spring
Thymeleaf jar
热部署 jar ---方便二次加载 ctrl+f9再次编译
Mybatis jar
Mysql jar

org.springframework.boot
     spring-boot-starter-web
org.springframework.boot
     spring-boot-starter-thymeleaf
org.springframework.boot
     spring-boot-starter-tomcat
org.springframework.boot
    spring-boot-devtools
    trueorg.mybatis.spring.boot
    mybatis-spring-boot-starter
    1.1.1mysql
    mysql-connector-java
    5.1.21


2.application的配置:
#thymeleaf 配置
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#缓存设置为false, 这样修改之后马上生效,便于调试
spring.thymeleaf.cache=false
#上下文
server.context-path=/thymeleaf
#视图层控制
#spring.mvc.view.prefix=classpath:/templates/
#spring.mvc.view.suffix=.html
#spring.mvc.static-path-pattern=/static/**
#数据库
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/how2java?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver



3.mapper层 以及非常简单的entity层:
@Mapper
@Repository
// 加上Repository注解,即可自动bean
public interface CategoryMapper {

    @Select("select * from category_ ")
    public List findAll();

}

4.service层 --- 以及serviceImpl实现层
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    CategoryMapper;

    @Override
    public List selectAll() {
        return categoryMapper.findAll();
    }
}
5.controller层:
这个里面加了pagehelper,可以忽略
@Controller
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    
    @RequestMapping("/listCategory")
    public String showList(Model model,
                           @RequestParam(value = "start", defaultValue = "0") int start,
                           @RequestParam(value = "size", defaultValue = "5") int size)
                            throws Exception{
        PageHelper.startPage(start,size);
        List list = categoryService.selectAll();
        PageInfo page = new PageInfo(list);
        model.addAttribute("page",page);
        return "listCategory";
    }
}

6.Thymeleaf --- 渲染模板:  有点类似于EL表达式的写法
id name
[首 页] [上一页] [下一页] [末 页]

  

springboot --- 之SSM框架整合

标签:rac   jar   boot   上下   user   thymeleaf   生效   jdb   templates   

原文地址:https://www.cnblogs.com/kkzhilu/p/9595492.html


评论


亲,登录后才可以留言!