成都创新互联网站制作重庆分公司

SpringBootMybatisThymeleaf项目构建

  1. POM文件

    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">
    4.0.0

    org.springframework.boot
    spring-boot-starter-parent
    2.1.6.RELEASE


    com.skcc
    service
    0.0.1-SNAPSHOT
    oaadmin
    Demo project for Spring Boot

    1.8




    org.springframework.boot
    spring-boot-starter-web


    org.springframework.boot
    spring-boot-starter-test
    test



    org.springframework.boot
    spring-boot-starter-thymeleaf


    org.mybatis.spring.boot
    mybatis-spring-boot-starter
    2.1.0



    org.springframework.boot
    spring-boot-starter-jdbc



    com.microsoft.sqlserver
    mssql-jdbc
    runtime



    org.springframework.boot
    spring-boot-devtools
    true






    org.springframework.boot
    spring-boot-maven-plugin




    application.properties文件配置
    spring.profiles.active=dev

spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html; charset=utf-8

创新互联主营渠县网站建设的网络公司,主营网站建设方案,重庆APP软件开发,渠县h5小程序设计搭建,渠县网站营销推广欢迎渠县等地区企业咨询

spring.datasource.url=jdbc:sqlserver://172.206.205.116:1433;DatabaseName=EGSS_TEST
spring.datasource.username=EGSS_DEV
spring.datasource.password=
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
# com.microsoft.sqlserver.jdbc.SQLServerDriver com.MySQL.jdbc.Driver
mybatis.config-location=classpath:mybatis/mapper/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/
Mapper.xml
mybatis.type-aliases-package=com.skcc.entity

在src/main/resources创建目录mybatis/mapper文件夹,再创建BookMapper.xml/mybatis-config.xml
BookMapper.xml文件

PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >




INSERT INTO AA_Book(BookName,Author,WordCount,BookSummary,[Desc],CreateDate)
VALUES
(

         #{BookName}
        , #{Author}
        , #{WordCount}
        , #{BookSummary}
        , #{Desc}
        ,GETDATE()

    )

mybatis-config.xml文件

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

    
    
    
    
    
    


OaadminApplication启动类入口文件@SpringBootApplication
br/>@SpringBootApplication
public class OaadminApplication {

public static void main(String[] args) {
    SpringApplication.run(OaadminApplication.class, args);
}

}
com.skcc.mapper包BookMapper.java文件
public interface BookMapper {

// com.ibatis.sqlmap.client.SqlMapClient;
public List selectAllBook();

public Map selectBookById(Map map);

public int insertBook(Map map);

}com.skcc.controller包下UserController.java文件
@Controller
br/>com.skcc.controller包下UserController.java文件
@Controller
public class UserController {

@Autowired
BookMapper bookDao;

@RequestMapping("/hello")
public String hello(Model m) {
    m.addAttribute("name", "thymeleaf start.");
    List empList = new ArrayList<>();
    empList.add(new EmpInfo("1001", "ZhouJun", 30));
    empList.add(new EmpInfo("1002", "LiMei", 32));
    empList.add(new EmpInfo("1003","ChenHua",22));
    m.addAttribute("emps", empList);
    m.addAttribute("nowdate",new Date());
    List bookList= bookDao.selectAllBook();

    m.addAttribute("BooKList", bookList.toString());

    return "hello";
}

}**src/main/resources/templates文件**,其中src/main/resources/static中可以放js,css文件@{/css/hello.css}
br/>**src/main/resources/templates文件**,其中src/main/resources/static中可以放js,css文件@{/css/hello.css}


Spring Boot thymeleaf





name


条件为真就显示了



onclick="testPopUp();" />






遍历

















idNameage



时间格式化





BooKList


BooKList


**单元测试示例**
@RunWith(SpringRunner.class)
br/>**单元测试示例**
@RunWith(SpringRunner.class)
public class HelloTest {

@Autowired
BookMapper bookDao;

@Test
public void sayHello() {
    new HelloService().sayHello();
}

@Test
public void selectAllBookTest() {

    List bookList= bookDao.selectAllBook();
    System.out.println(bookList);
}

@Test
public void selectBookById() {
    Map paramMap = new HashMap<>();
    paramMap.put("BookId", 1);
    Map bookMap = bookDao.selectBookById(paramMap);
    System.out.println("----------selectBookById--bookMap-------------------");
    System.out.println(bookMap);
}

@Test
public void insertBook() {
    Map paramMap = new HashMap<>();
    paramMap.put("BookName", "PHP高级编程");
    paramMap.put("Author", "zhangjun");
    paramMap.put("WordCount", 66999);
    paramMap.put("BookSummary", "网络原理");
    paramMap.put("Desc", "2008年出版");
    int result = bookDao.insertBook(paramMap);
    System.out.println("insertBook : " + result+" Key : " + paramMap.get("BookId"));

}

}


本文标题:SpringBootMybatisThymeleaf项目构建
标题路径:http://cxhlcq.com/article/pioodi.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部