大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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}
name
条件为真就显示了
id | Name | age |
---|---|---|
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"));
}
}