├── README.md
├── src
├── main
│ ├── resources
│ │ ├── static
│ │ │ ├── subpage
│ │ │ │ └── newpage.html
│ │ │ └── index.html
│ │ └── application.properties
│ └── java_scala
│ │ └── org
│ │ └── tashaxing
│ │ └── SpringbootScalaDemo
│ │ ├── SpringbootScalaDemoApplication.scala
│ │ ├── repository
│ │ ├── ScalaModelQuery.scala
│ │ ├── ScalaModelRepository.scala
│ │ └── BaseQuery.scala
│ │ ├── controller
│ │ ├── PageController.scala
│ │ ├── JavaTestController.java
│ │ └── ScalaTestController.scala
│ │ ├── config
│ │ └── OriginConfig.scala
│ │ └── model
│ │ ├── ScalaModel.scala
│ │ └── SlickModel.scala
└── test
│ └── java
│ └── org
│ └── tashaxing
│ └── SpringbootScalaDemo
│ └── SpringbootScalaDemoApplicationTests.java
├── frontend
├── src
│ ├── apitest.html
│ └── apitest.js
├── .gitattributes
├── README.md
├── package.json
└── webpack.config.js
├── .gitattributes
├── .gitignore
├── pom.xml
├── mvnw.cmd
└── mvnw
/README.md:
--------------------------------------------------------------------------------
1 | # SpringbootScalaDemo
2 | springboot demo combined with scala and java
3 |
4 | # blog address
5 | http://blog.csdn.net/u012234115/article/details/78650622
6 |
--------------------------------------------------------------------------------
/src/main/resources/static/subpage/newpage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | newpage
6 |
7 |
8 | the subpage
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | scala test index page
6 |
7 |
8 | demo rootpage for scala springboot
9 |
10 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 | #datasource
3 | spring.jpa.hibernate.ddl-auto=update
4 | spring.datasource.url=jdbc:mysql://localhost:3306/db_example?useUnicode=true&characterEncoding=UTF-8&useSSL=false
5 | spring.datasource.username=springuser
6 | spring.datasource.password=ThePassword
7 |
8 | # Server port
9 | server.port=7700
--------------------------------------------------------------------------------
/frontend/src/apitest.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | apitest
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/frontend/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/src/test/java/org/tashaxing/SpringbootScalaDemo/SpringbootScalaDemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootScalaDemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java_scala/org/tashaxing/SpringbootScalaDemo/SpringbootScalaDemoApplication.scala:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo
2 |
3 | import org.springframework.boot.SpringApplication
4 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
5 | import org.springframework.boot.autoconfigure.{EnableAutoConfiguration, SpringBootApplication}
6 |
7 | @SpringBootApplication
8 | class BootConfig
9 |
10 | object SpringbootScalaDemoApplication extends App {
11 |
12 | SpringApplication.run(classOf[BootConfig])
13 | }
--------------------------------------------------------------------------------
/frontend/README.md:
--------------------------------------------------------------------------------
1 | # react_multipage_demo
2 | A react multipage demo with webpack
3 |
4 | # code structure
5 | 
6 |
7 | # blog address
8 | http://blog.csdn.net/u012234115/article/details/78640077
9 |
10 | # screenshots
11 | 
12 | 
13 | 
14 |
--------------------------------------------------------------------------------
/src/main/java_scala/org/tashaxing/SpringbootScalaDemo/repository/ScalaModelQuery.scala:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo.repository
2 |
3 | import org.springframework.beans.factory.annotation.Autowired
4 | import org.springframework.stereotype.Service
5 | import org.tashaxing.SpringbootScalaDemo.model.ScalaModel
6 | import java.util.List
7 |
8 | @Service
9 | class ScalaModelQuery extends BaseQuery[ScalaModel]
10 | {
11 | @Autowired val scalaModelRepository: ScalaModelRepository = null
12 |
13 | def findByName(name: String): List[ScalaModel] = scalaModelRepository.findByName(name)
14 |
15 | // def findNameOfAge(): List[Object] = scalaModelRepository.findNameOfAge()
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java_scala/org/tashaxing/SpringbootScalaDemo/repository/ScalaModelRepository.scala:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo.repository
2 |
3 | import org.springframework.data.jpa.repository.{JpaRepository, Query}
4 | import org.tashaxing.SpringbootScalaDemo.model.ScalaModel
5 |
6 | // remember to use java List and Long here
7 | import java.util.List
8 | import java.lang.Long
9 |
10 | trait ScalaModelRepository extends JpaRepository[ScalaModel, Long]
11 | {
12 | // normal find function from db
13 | def findByName(name: String): List[ScalaModel]
14 |
15 | // self defined function from db by sql query
16 | // @Query(value = "select name from scala_model where age < 22")
17 | // def findNameOfAge(): List[Object]
18 | }
--------------------------------------------------------------------------------
/src/main/java_scala/org/tashaxing/SpringbootScalaDemo/controller/PageController.scala:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo.controller
2 |
3 | import org.springframework.stereotype.Controller
4 | import org.springframework.web.bind.annotation.RequestMapping
5 |
6 | @Controller
7 | class PageController
8 | {
9 | // root page
10 | @RequestMapping(Array("/"))
11 | def index(): String = "redirect:/index.html"
12 |
13 | // an other page
14 | // use forward instead of redirect will not show xxx.html in browser address bar
15 | @RequestMapping(Array("/subpage"))
16 | def sub(): String = "forward:/subpage/newpage.html"
17 |
18 | // no need to redirect apitest
19 | // @RequestMapping(Array("/apitest"))
20 | // def apitest(): String = "redirect:/apitest.html"
21 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 | /.idea
45 | target
46 | node_modules
47 |
--------------------------------------------------------------------------------
/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react_multipage_demo",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "antd": "^2.12.8",
7 | "axios": "^0.17.1",
8 | "react": "^15.6.1",
9 | "react-dom": "^15.6.1"
10 | },
11 | "scripts": {
12 | "start": "webpack-dev-server",
13 | "build": "webpack"
14 | },
15 | "devDependencies": {
16 | "babel-core": "^6.26.0",
17 | "babel-loader": "^7.1.2",
18 | "babel-preset-env": "^1.6.1",
19 | "babel-preset-es2015": "^6.24.1",
20 | "babel-preset-react": "^6.24.1",
21 | "copy-webpack-plugin": "^4.2.3",
22 | "css-loader": "^0.28.7",
23 | "less": "^2.7.3",
24 | "less-loader": "^4.0.5",
25 | "style-loader": "^0.19.0",
26 | "webpack": "^3.8.1",
27 | "webpack-dev-server": "^2.9.4"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java_scala/org/tashaxing/SpringbootScalaDemo/config/OriginConfig.scala:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo.config
2 |
3 | import org.springframework.context.annotation.Configuration
4 | import org.springframework.web.servlet.config.annotation.{CorsRegistry, WebMvcConfigurerAdapter}
5 |
6 | @Configuration
7 | class OriginConfig extends WebMvcConfigurerAdapter
8 | {
9 | override def addCorsMappings(registry: CorsRegistry): Unit =
10 | {
11 | // cors setting to allow origin access
12 | registry.addMapping("/**") // allow any path
13 | .allowedOrigins("http://192.168.1.97") // allow exact ip /** to map any ip
14 | .allowedMethods("GET", "POST") // allow methods
15 | .allowedHeaders("*") // allow any header
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/src/main/java_scala/org/tashaxing/SpringbootScalaDemo/model/ScalaModel.scala:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo.model
2 |
3 | import java.lang.Long
4 | import javax.persistence.{Entity, GeneratedValue, Id, Table}
5 | import javax.validation.constraints.NotNull
6 |
7 | import scala.beans.BeanProperty
8 | import org.hibernate.validator.constraints.{NotBlank, NotEmpty}
9 |
10 | import scala.annotation.meta.field
11 |
12 | //@Table(name = "scala_model") // define mysql table name
13 | //@Entity
14 | //case class ScalaModel(
15 | // @(Id @field) @(GeneratedValue @field) @BeanProperty var id: Long,
16 | // @BeanProperty @(NotEmpty @field) var name: String, // @field is a must
17 | // @BeanProperty @(NotEmpty @field) var age: Int
18 | //)
19 |
20 | @Table(name = "scala_model") // define mysql table name
21 | @Entity
22 | class ScalaModel
23 | {
24 | @Id
25 | @GeneratedValue
26 | @BeanProperty
27 | var id: Long = _
28 |
29 | @BeanProperty
30 | @NotBlank // we can make sure it not empty
31 | var name: String = _
32 |
33 | @BeanProperty
34 | @NotNull
35 | var age: Int = 18 // we can define default value here
36 | }
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/main/java_scala/org/tashaxing/SpringbootScalaDemo/controller/JavaTestController.java:
--------------------------------------------------------------------------------
1 | package org.tashaxing.SpringbootScalaDemo.controller;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RequestParam;
11 | import org.springframework.web.bind.annotation.RestController;
12 | import org.tashaxing.SpringbootScalaDemo.model.ScalaModel;
13 |
14 | @RestController
15 | @RequestMapping("/javatest")
16 | public class JavaTestController {
17 |
18 | @RequestMapping
19 | public String root() {
20 | return "java test results";
21 | }
22 |
23 | @GetMapping("/info")
24 | public Map getInfo(@RequestParam String name) {
25 | // java map can be returned without extra code
26 | Map map = new HashMap<>();
27 | map.put("name", name);
28 | return map;
29 | }
30 |
31 | @RequestMapping("/list")
32 | public List