Skip to content

Commit

Permalink
thymeleaf模板工程提交
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwujing committed Apr 19, 2018
1 parent a4a200a commit b8c6098
Show file tree
Hide file tree
Showing 20 changed files with 7,294 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8

server.port=8080
server.port=8082

web:
pancm:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8

server.port=8083
server.port=8084

## 默认的数据源
master.datasource.url=jdbc:mysql://localhost:3306/springBoot?useUnicode=true&characterEncoding=utf8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Thu Apr 19 14:33:37 CST 2018
#Thu Apr 19 14:41:22 CST 2018
version=0.0.1-SNAPSHOT
groupId=1.0.0
m2e.projectName=springboot-mutilDatasource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8

server.port=8083
server.port=8084

## 默认的数据源
master.datasource.url=jdbc:mysql://localhost:3306/springBoot?useUnicode=true&characterEncoding=utf8
Expand Down
2 changes: 0 additions & 2 deletions springboot-restful/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<mybatis-spring-boot>1.2.0</mybatis-spring-boot>
<mysql-connector>5.1.44</mysql-connector>
</properties>

<parent>
Expand Down Expand Up @@ -59,7 +58,6 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector}</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions springboot-restful/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


mybatis.typeAliasesPackage=com.pancm.pojo
mybatis.mapperLocations=classpath\:mapper/*.xml
#mybatis.typeAliasesPackage=com.pancm.pojo
#mybatis.mapperLocations=classpath\:mapper/*.xml



11 changes: 9 additions & 2 deletions springboot-thymeleaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<version>1.5.9.RELEASE</version>
</parent>

<properties>
<java.version>1.8</java.version>
<java.version>1.7</java.version>
<mybatis-spring-boot>1.2.0</mybatis-spring-boot>
</properties>

<dependencies>
Expand All @@ -32,6 +33,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Spring Boot Mybatis 依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-spring-boot}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
Expand Down
13 changes: 8 additions & 5 deletions springboot-thymeleaf/src/main/java/com/pancm/App.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.pancm;

/**
* Hello world!
*
*/
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
// 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件
SpringApplication.run(App.class, args);
System.out.println("程序正在运行...");
}
}
44 changes: 44 additions & 0 deletions springboot-thymeleaf/src/main/java/com/pancm/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.pancm.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.pancm.pojo.User;

/**
*
* Title: UserDao
* Description:
* 用户数据接口
* Version:1.0.0
* @author pancm
* @date 2018年1月9日
*/
@Mapper
public interface UserDao {


@Insert("insert into t_user(id,name,password,age) values (#{id},#{name},#{password},#{age})")
void addUser(User user);


@Update("update t_user set name=#{name},password=#{password} age=#{age} where id=#{id}")
void updateUser(User user);


@Delete("delete from t_user where id=#{id}")
void deleteUser(int id);

@Select("SELECT * FROM t_user where id=#{id}")
User findById(int id);


@Select("SELECT * FROM t_user")
List<User> findAll();

}
102 changes: 102 additions & 0 deletions springboot-thymeleaf/src/main/java/com/pancm/pojo/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.pancm.pojo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
*
* Title: User
* Description:用户pojo类
* Version:1.0.0
* @author pancm
* @date 2017年9月26日
*/
@Entity
public class User {

/** 编号 */
@Id
@GeneratedValue
private int id;
/** 姓名 */
@Column(nullable = false, unique = true)
private String name;
/** 密码*/
@Column(nullable = false)
private String password;
/** 年龄 */
@Column(nullable = false)
private int age;

public User(){
}

/**
* 获取编号
* @return id
*/
public int getId() {
return id;
}

/**
* 设置编号
* @param id
*/
public void setId(int id) {
this.id = id;
}

/**
* 获取姓名
* @return name
*/
public String getName() {
return name;
}

/**
* 设置姓名
* @param name
*/
public void setName(String name) {
this.name = name;
}


/**
* 获取密码
* @return password
*/
public String getPassword() {
return password;
}

/**
* 设置密码
* @param String password
*/
public void setPassword(String password) {
this.password = password;
}

/**
* 获取年龄
* @return age
*/
public int getAge() {
return age;
}
/**
* 设置年龄
* @param int age
*/
public void setAge(int age) {
this.age = age;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.pancm.service;

import java.util.List;

import com.pancm.pojo.User;


/**
*
* Title: UserService
* Description:
* 用户接口
* Version:1.0.0
* @author pancm
* @date 2018年3月19日
*/
public interface UserService {

/**
* 新增用户
* @param user
* @return
*/
boolean addUser(User user);

/**
* 修改用户
* @param user
* @return
*/
boolean updateUser(User user);


/**
* 删除用户
* @param id
* @return
*/
boolean deleteUser(int id);

/**
* 根据用户名字查询用户信息
* @param userName
*/
User findUserById(int id);
/**
* 查询所有
* @return
*/
List<User> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.pancm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pancm.dao.UserDao;
import com.pancm.pojo.User;
import com.pancm.service.UserService;

/**
*
* Title: UserServiceImpl
* Description:
* 用户操作实现类
* Version:1.0.0
* @author pancm
* @date 2018年3月19日
*/
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;


@Override
public boolean addUser(User user) {
boolean flag=false;
try{
userDao.addUser(user);
flag=true;
}catch(Exception e){
System.out.println("新增失败!");
e.printStackTrace();
}
return flag;
}

@Override
public boolean updateUser(User user) {
boolean flag=false;
try{
userDao.updateUser(user);
flag=true;
}catch(Exception e){
System.out.println("修改失败!");
e.printStackTrace();
}
return flag;
}

@Override
public boolean deleteUser(int id) {
boolean flag=false;
try{
userDao.deleteUser(id);
flag=true;
}catch(Exception e){
System.out.println("删除失败!");
e.printStackTrace();
}
return flag;
}

@Override
public User findUserById(int id) {
return userDao.findById(id);
}

@Override
public List<User> findAll() {
return userDao.findAll();
}
}
Loading

0 comments on commit b8c6098

Please sign in to comment.