POM文件

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">;
4.0.0

com.sk.confluence
spring-boot-demo
0.0.1-SNAPSHOT
jar

spring-boot-demo
Demo project for Spring Boot


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



    UTF-8
    UTF-8
    1.8



    
        org.springframework.boot
        spring-boot-starter-web
    
    
        org.springframework.boot
        spring-boot-starter-thymeleaf
    
    
        org.springframework.boot
        spring-boot-starter-data-jpa
    

    
        org.mybatis.spring.boot
        mybatis-spring-boot-starter
        1.3.1
    
    
        mysql
        mysql-connector-java
        8.0.9-rc
    
    
        com.microsoft.sqlserver
        sqljdbc4
        4.0.0
    
    
        com.alibaba
        druid
        1.1.9
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    

    
    
        org.springframework.boot
        spring-boot-devtools
        true
        true
    



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

        
    

application.yml文件
spring:
profiles:
active: dev
datasource:
url: jdbc:sqlserver://172.26.205.117:1433;DatabaseName=EGSS_TEST
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
username: EGSS_DEV
password: EgssTest2016!
thymeleaf:
mode: HTML
mybatis:
type-aliases-package: com.sk.confluence.entity
config-location: classpath:mapping/mybatis-config.xml
mapper-locations: classpath:mapping/mssql/*.xml
logging:
level:
root: info
file: logs/my.log

application-dev.yml文件
server:
port: 8081
servlet:
context-path: /skcc

logback-spring.xml









    
        
            ${PATTERN}
        
    
    
    
        
    
 


    
        ${PRO_FILE_PATH}
        
            ${PRO_FILE_PATH}/warn.%d{yyyy-MM-dd}.log
            100
        
        
            ${PATTERN}
        
    
    
        
    

br/>Controller文件
@Controller
public class BookShopController {

@Autowired
private UserXmlMapper userMapper;

@Autowired
private CarEntity carInfo;

@RequestMapping(value="/greeting")
public String bookshop(String shopName,Model m) {
    CarEntity carInfo = new CarEntity();
    m.addAttribute("ShopName", "阳光书林");
    m.addAttribute("CarInfo", carInfo.toString());
    return "bookshop";
}

@RequestMapping(value ="/",method=RequestMethod.GET)
public String home() {
    return "index";
}

@GetMapping(value="books/{userid}")
public String detail(@PathVariable Integer userid,Model m) {
    m.addAttribute("bookid", userid);
    UserEntity user = new UserEntity();
    user.setId(userid);
    user.setUsername("TOM JACK(王忠义)");
    List users = userMapper.getAllUser();
    m.addAttribute("user", user);
    m.addAttribute("CarInfo", carInfo.toString());
    return "bookshop";
}

@GetMapping(value="users")
public String detail(Model m) {
    List userEntities = new ArrayList<>();
    userEntities = userMapper.getAllUser();
    m.addAttribute("users", userEntities);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    return "users";
}

@GetMapping(value="userdetail/{id}")
public String userdetail(@PathVariable(required=false) Integer id,Model m) {
    Map map = new HashMap<>();
    map.put("id", id);
    UserEntity user =   userMapper.getUserByid(map);
    m.addAttribute("user", user);                                                                                                                                 
    return "userdetail";
}

@PostMapping(value="insertUser")
public String insertUser(UserEntity userEntity) {
    Map map = new HashMap<>();
    map.put("username", userEntity.getUsername());
     userMapper.insertUser(map);
    return "redirect:/users";
}

@PostMapping(value="deleteUser")
public String deleteUser(UserEntity userEntity) {
    Map map = new HashMap<>();
    map.put("id", userEntity.getId());
     userMapper.deleteUser(map);
    return "redirect:/users";
}

@PostMapping(value="updateUser")
public String updateUser(UserEntity userEntity) {
    Map map = new HashMap<>();
    map.put("id", userEntity.getId());
    map.put("username", userEntity.getUsername());
     userMapper.updateUser(map);
    return "redirect:/users";
}

}

;






Spring Book Shop

th:href="@{/bootstrap-3.3.7-dist/css/bootstrap.min.css}">




详细信息



能取到值吗


1001



用户id:1001



用户姓名:张三



th:value="${user.id}" /> value="TOM KOL" th:value="${user.username}" />

        

123654

状态: 想读 已读 不读

不错,你已经开始行动啦
,你还没有开始行动啦

CarInfo:

返回


程序启动入口br/>@SpringBootApplication
@MapperScan("com.sk.confluence.dao")
public class SpringBootDemoApplication {

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

@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
    return args -> {

        System.out.println("Let's inspect the beans provided by Spring Boot:");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
            System.out.println(beanName);
        }

    };
}

}