maven+spring boot+mybatis+thymeleaf实战

由于项目需要,基于spring boot可以快速搭建简化spring的相关配置和开发过程。

Thymeleaf是一个XML/XHTML/HTML5模板引擎,由于浏览器解释html时,忽略未定义的标签属性,因此thymeleaf的模板可以静态运行,在浏览器中可以查看静态效果,语法比较清晰简单。美工制作一套静态的页面效果,程序员很容易在上面修改为动态的。

1.maven pom如下


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


   
        UTF-8
        UTF-8
        1.7
   


   
       
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.1.1
       

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

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


       
            mysql
            mysql-connector-java
            runtime
       

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

       
            com.alibaba
            druid
            1.0.26
       

       
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
       


   

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

       

   

   

2.spring boot例子代码:

UserController.java

@EnableAutoConfiguration
public class UserController {
 @Autowired
 private UserService userService;
 @Autowired
 private ConsumeInfoService consumeInfoService;
 @Autowired
 private PayCheckInfoService payCheckInfoService;

 @ResponseBody
 @RequestMapping({ "/home" })
 public User home() {
  User user = userService.selectById(1);
  System.out.println("用户信息" + user);
  return user;
 }

UserService.java:

@Service
public class UserService {
 @Autowired
 @Qualifier("userMapper")
 private UserMapper userMapper;

 public void save(User user) {
  userMapper.save(user);
 }

 public User selectById(int id) {
  return userMapper.selectById(id);
 }
 
 public List queryAll(){
  return userMapper.queryAll();
 }
 
 public void deleteUser(Integer id){
  userMapper.deleteById(id);
 }
 
 public void updateById(User user){
  userMapper.updateById(user);
 }
}
UserMapper.java

@Mapper
public interface UserMapper {
 int save(User user);
 

 User selectById(Integer member_id);

 int updateById(User user);

 int deleteById(Integer member_id);

 List queryAll();
}

3.thymeleaf使用:


 xmlns:th="http://www.thymeleaf.org">

 
           
           
             
             
             
           
           
           

页面效果:

 


 maven+spring boot+mybatis+thymeleaf实战_第1张图片

 

你可能感兴趣的:(spring,boot)