91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Spring Boot Mybatis Thymeleaf項目構建

發布時間:2020-08-03 10:30:02 來源:網絡 閱讀:591 作者:zjy1002261870 欄目:編程語言
  1. POM文件
    <?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>
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.skcc</groupId>
    <artifactId>service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>oaadmin</name>
    <description>Demo project for Spring Boot</description>
    <properties>
    <java.version>1.8</java.version>
    </properties>
    <dependencies>
    <!-- 開發Spring及web項目依賴 -->
    <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>
    <!-- thymeleaf視圖模板依賴 -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.0</version>
    </dependency>
    <!-- jdbc依賴 -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <!-- mssql driver -->
    <dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <scope>runtime</scope>
    </dependency>
    <!-- 熱部署依賴 -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional> <!-- 這個需要為 true 熱部署才有效 -->
    </dependency>
    </dependencies>
    <build>
    <plugins>
    <!-- 熱部署插件 -->
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>
    </build>
    </project>
    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

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文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.skcc.mapper.BookMapper">
<select id="selectAllBook" resultType="com.skcc.entity.BookEntity">
select from AA_Book
</select>
<select id="selectBookById" parameterType="java.util.Map" resultType="java.util.Map" >
select
from AA_Book where BookId=#{BookId}
</select>
<insert id="insertBook" keyProperty="BookId" useGeneratedKeys="true" parameterType="java.util.Map">
INSERT INTO AA_Book(BookName,Author,WordCount,BookSummary,[Desc],CreateDate)
VALUES
(

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

    )
</insert>
</mapper>

mybatis-config.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>

    <typeAlias alias="Integer" type="java.lang.Integer" />
    <typeAlias alias="Long" type="java.lang.Long" />
    <typeAlias alias="HashMap" type="java.util.HashMap" />
    <typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" />
    <typeAlias alias="ArrayList" type="java.util.ArrayList" />
    <typeAlias alias="LinkedList" type="java.util.LinkedList" />
</typeAliases>

<!--  
<mappers>
    <mapper resource="classpath:sample/mybatis/mapper/CityMapper.xml"/>

</mappers>

-->

</configuration>

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<BookEntity> selectAllBook();

public Map<String, Object> selectBookById(Map<String, Object> map);

public int insertBook(Map<String, Object> 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<EmpInfo> 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<BookEntity> 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}
<head>
<title>Spring Boot thymeleaf</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" style="text/css" href="/css/hello.css" th:href="@{/css/hello.css}" />
<script type="text/javascript" src="/js/hello.js" th:src="@{/js/hello.js}"></script>
</head>
<body>
<p th:text="${name}">name</p>
<p th:if="n">條件為真就顯示了</p>
<div>
<input type="button" value="Test Buton" class="ibutton"
onclick="testPopUp();" />
</div>
<div class="showing">
<div th:replace="include::footer1"></div>
<div th:replace="include::footer2(1999,2019)"></div>
</div>
<div>
<h3>遍歷</h3>
<table>
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>age</th>
</tr>
</thead>
<tbody>
<tr th:each="p: ${emps}">
<td th:text="${p.empID}"></td>
<td th:text="${p.empName}"></td>
<td th:text="${p.age}"></td>
</tr>
</tbody>
</table>
</div>
<div>
<h3>時間格式化</h3>
<p th:text="${#dates.format(nowdate,'yyyy-MM-dd HH:mm:ss SSS')}"></p>
</div>
<div>
<h3>BooKList</h3>
<p th:text="${BooKList}">BooKList</p>
</div>

</body>**單元測試示例**
@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<BookEntity> bookList= bookDao.selectAllBook();
    System.out.println(bookList);
}

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

@Test
public void insertBook() {
    Map<String, Object> 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"));

}

}

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

福安市| 古蔺县| 沂源县| 沿河| 班戈县| 平遥县| 华池县| 青铜峡市| 普定县| 建阳市| 曲阳县| 东山县| 民丰县| 江都市| 凤山县| 瓮安县| 双辽市| 许昌县| 蒙山县| 定西市| 马公市| 涿州市| 洞头县| 原阳县| 兴山县| 汤阴县| 上杭县| 漳州市| 灯塔市| 南和县| 周至县| 襄樊市| 社会| 罗定市| 万年县| 东丰县| 曲靖市| 上虞市| 勐海县| 赣榆县| 惠州市|